Skip to content

Commit 20b2aad

Browse files
[Tests] Remove occurrences of withConsecutive()
1 parent 10c73d3 commit 20b2aad

File tree

22 files changed

+611
-267
lines changed

22 files changed

+611
-267
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,31 @@ private function getKernel(array $bundles, $useDispatcher = false)
258258
$container
259259
->expects($this->exactly(2))
260260
->method('hasParameter')
261-
->withConsecutive(['console.command.ids'], ['console.lazy_command.ids'])
262-
->willReturnOnConsecutiveCalls(true, true)
261+
->willReturnCallback(function (...$args) {
262+
static $series = [
263+
[['console.command.ids'], true],
264+
[['console.lazy_command.ids'], true],
265+
];
266+
267+
[$expectedArgs, $return] = array_shift($series);
268+
269+
return $expectedArgs === $args ? $return : $this->fail();
270+
})
263271
;
272+
264273
$container
265274
->expects($this->exactly(2))
266275
->method('getParameter')
267-
->withConsecutive(['console.lazy_command.ids'], ['console.command.ids'])
268-
->willReturnOnConsecutiveCalls([], [])
276+
->willReturnCallback(function (...$args) {
277+
static $series = [
278+
[['console.lazy_command.ids'], []],
279+
[['console.command.ids'], []],
280+
];
281+
282+
[$expectedArgs, $return] = array_shift($series);
283+
284+
return $expectedArgs === $args ? $return : $this->fail();
285+
})
269286
;
270287

271288
$kernel = $this->createMock(KernelInterface::class);

src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,20 @@ public function testResourceFilesOptionLoadsBeforeOtherAddedResources($debug, $e
148148

149149
$loader = $this->createMock(LoaderInterface::class);
150150

151+
$series = [
152+
/* The "messages.some_locale.loader" is passed via the resource_file option and shall be loaded first */
153+
[['messages.some_locale.loader', 'some_locale', 'messages'], $someCatalogue],
154+
/* This resource is added by an addResource() call and shall be loaded after the resource_files */
155+
[['second_resource.some_locale.loader', 'some_locale', 'messages'], $someCatalogue],
156+
];
157+
151158
$loader->expects($this->exactly(2))
152159
->method('load')
153-
->withConsecutive(
154-
/* The "messages.some_locale.loader" is passed via the resource_file option and shall be loaded first */
155-
['messages.some_locale.loader', 'some_locale', 'messages'],
156-
/* This resource is added by an addResource() call and shall be loaded after the resource_files */
157-
['second_resource.some_locale.loader', 'some_locale', 'messages']
158-
)
159-
->willReturnOnConsecutiveCalls(
160-
$someCatalogue,
161-
$someCatalogue
162-
);
160+
->willReturnCallback(function (...$args) use (&$series) {
161+
[$expectedArgs, $return] = array_shift($series);
162+
163+
return $expectedArgs === $args ? $return : $this->fail();
164+
});
163165

164166
$options = [
165167
'resource_files' => ['some_locale' => ['messages.some_locale.loader']],

src/Symfony/Bundle/SecurityBundle/Tests/CacheWarmer/ExpressionCacheWarmerTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,22 @@ public function testWarmUp()
2222
{
2323
$expressions = [new Expression('A'), new Expression('B')];
2424

25+
$series = [
26+
[$expressions[0], ['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver']],
27+
[$expressions[1], ['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver']],
28+
];
29+
2530
$expressionLang = $this->createMock(ExpressionLanguage::class);
2631
$expressionLang->expects($this->exactly(2))
2732
->method('parse')
28-
->withConsecutive(
29-
[$expressions[0], ['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver']],
30-
[$expressions[1], ['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver']]
31-
);
33+
->willReturnCallback(function (...$args) use (&$series) {
34+
$expectedArgs = array_shift($series);
35+
36+
if ($expectedArgs !== $args) {
37+
$this->fail();
38+
}
39+
})
40+
;
3241

3342
(new ExpressionCacheWarmer($expressions, $expressionLang))->warmUp('');
3443
}

src/Symfony/Component/Cache/Tests/Adapter/MaxIdLengthAdapterTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,19 @@ public function testLongKey()
2626

2727
$cache->expects($this->exactly(2))
2828
->method('doHave')
29-
->withConsecutive(
30-
[$this->equalTo('----------:nWfzGiCgLczv3SSUzXL3kg:')],
31-
[$this->equalTo('----------:---------------------------------------')]
32-
);
29+
->willReturnCallback(function (...$args) {
30+
static $series = [
31+
['----------:nWfzGiCgLczv3SSUzXL3kg:'],
32+
['----------:---------------------------------------'],
33+
];
34+
35+
$expectedArgs = array_shift($series);
36+
37+
if ($expectedArgs !== $args) {
38+
$this->fail();
39+
}
40+
})
41+
;
3342

3443
$cache->hasItem(str_repeat('-', 40));
3544
$cache->hasItem(str_repeat('-', 39));

src/Symfony/Component/DependencyInjection/Tests/Config/ContainerParametersResourceCheckerTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,16 @@ public static function isFreshProvider()
6464
yield 'fresh on every identical parameters' => [function (MockObject $container) {
6565
$container->expects(self::exactly(2))->method('hasParameter')->willReturn(true);
6666
$container->expects(self::exactly(2))->method('getParameter')
67-
->withConsecutive(
68-
[self::equalTo('locales')],
69-
[self::equalTo('default_locale')]
70-
)
71-
->willReturnMap([
72-
['locales', ['fr', 'en']],
73-
['default_locale', 'fr'],
74-
])
67+
->willReturnCallback(function (...$args) {
68+
static $series = [
69+
[['locales'], ['fr', 'en']],
70+
[['default_locale'], 'fr'],
71+
];
72+
73+
[$expectedArgs, $return] = array_shift($series);
74+
75+
return $expectedArgs === $args ? $return : $this->fail();
76+
})
7577
;
7678
}, true];
7779
}

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,17 @@ public function testReadWithValidateIdMismatch()
8484
{
8585
$handler = $this->createMock(\SessionHandlerInterface::class);
8686
$handler->expects($this->exactly(2))->method('read')
87-
->withConsecutive(['id1'], ['id2'])
88-
->will($this->onConsecutiveCalls('data1', 'data2'));
87+
->willReturnCallback(function (...$args) {
88+
static $series = [
89+
[['id1'], 'data1'],
90+
[['id2'], 'data2'],
91+
];
92+
93+
[$expectedArgs, $return] = array_shift($series);
94+
95+
return $expectedArgs === $args ? $return : $this->fail();
96+
})
97+
;
8998
$proxy = new StrictSessionHandler($handler);
9099

91100
$this->assertTrue($proxy->validateId('id1'));

src/Symfony/Component/HttpKernel/Tests/EventListener/DebugHandlersListenerTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,14 @@ public function testLevelsAssignedToLoggers(bool $hasLogger, bool $hasDeprecatio
222222
$handler
223223
->expects($this->exactly(\count($expectedCalls)))
224224
->method('setDefaultLogger')
225-
->withConsecutive(...$expectedCalls);
225+
->willReturnCallback(function (LoggerInterface $logger, $levels) use (&$expectedCalls) {
226+
[$expectedLogger, $expectedLevels] = array_shift($expectedCalls);
227+
228+
if ($expectedLogger !== $logger || $expectedLevels !== $levels) {
229+
$this->fail();
230+
}
231+
})
232+
;
226233

227234
$sut = new DebugHandlersListener(null, $logger, $levels, null, true, true, $deprecationLogger);
228235
$prevHander = set_exception_handler([$handler, 'handleError']);

src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,20 @@ public function testLocaleIsSetInOnKernelRequest()
4646

4747
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
4848
{
49+
$matcher = $this->exactly(2);
4950
$this->localeAwareService
50-
->expects($this->exactly(2))
51+
->expects($matcher)
5152
->method('setLocale')
52-
->withConsecutive(
53-
[$this->anything()],
54-
['en']
55-
)
56-
->willReturnOnConsecutiveCalls(
57-
$this->throwException(new \InvalidArgumentException())
58-
);
53+
->willReturnCallback(function (string $locale) use ($matcher) {
54+
if (1 === $matcher->getInvocationCount()) {
55+
throw new \InvalidArgumentException();
56+
}
57+
58+
if ('en' !== $locale) {
59+
$this->fail();
60+
}
61+
})
62+
;
5963

6064
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MAIN_REQUEST);
6165
$this->listener->onKernelRequest($event);
@@ -90,16 +94,20 @@ public function testLocaleIsSetToDefaultOnKernelFinishRequestWhenParentRequestDo
9094

9195
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
9296
{
97+
$matcher = $this->exactly(2);
9398
$this->localeAwareService
94-
->expects($this->exactly(2))
99+
->expects($matcher)
95100
->method('setLocale')
96-
->withConsecutive(
97-
[$this->anything()],
98-
['en']
99-
)
100-
->willReturnOnConsecutiveCalls(
101-
$this->throwException(new \InvalidArgumentException())
102-
);
101+
->willReturnCallback(function (string $locale) use ($matcher) {
102+
if (1 === $matcher->getInvocationCount()) {
103+
throw new \InvalidArgumentException();
104+
}
105+
106+
if ('en' !== $locale) {
107+
$this->fail();
108+
}
109+
})
110+
;
103111

104112
$this->requestStack->push($this->createRequest('fr'));
105113
$this->requestStack->push($subRequest = $this->createRequest('de'));

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,12 @@ public function testShutdownGivesNullContainerToAllBundles()
182182
$bundle = $this->createMock(Bundle::class);
183183
$bundle->expects($this->exactly(2))
184184
->method('setContainer')
185-
->withConsecutive(
186-
[$this->isInstanceOf(ContainerInterface::class)],
187-
[null]
188-
);
185+
->willReturnCallback(function ($container) {
186+
if (!$container instanceof ContainerInterface && null !== $container) {
187+
throw new \LogicException();
188+
}
189+
})
190+
;
189191

190192
$kernel = $this->getKernel(['getBundles']);
191193
$kernel->expects($this->any())

0 commit comments

Comments
 (0)