Skip to content

Commit b80140c

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

File tree

22 files changed

+573
-273
lines changed

22 files changed

+573
-273
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,25 @@ 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 (string $arg) {
262+
if (\in_array($arg, ['console.command.ids', 'console.lazy_command.ids'], true)) {
263+
return true;
264+
}
265+
266+
throw new \LogicException();
267+
})
263268
;
269+
264270
$container
265271
->expects($this->exactly(2))
266272
->method('getParameter')
267-
->withConsecutive(['console.lazy_command.ids'], ['console.command.ids'])
268-
->willReturnOnConsecutiveCalls([], [])
273+
->willReturnCallback(function (string $arg) {
274+
if (\in_array($arg, ['console.command.ids', 'console.lazy_command.ids'], true)) {
275+
return [];
276+
}
277+
278+
throw new \LogicException();
279+
})
269280
;
270281

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

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,19 @@ public function testResourceFilesOptionLoadsBeforeOtherAddedResources($debug, $e
150150

151151
$loader->expects($this->exactly(2))
152152
->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-
);
153+
->willReturnCallback(function (string $loader, string $locale, string $domain) use ($someCatalogue) {
154+
if ('some_locale' === $locale && 'messages' === $domain) {
155+
switch ($loader) {
156+
/* The "messages.some_locale.loader" is passed via the resource_file option and shall be loaded first */
157+
case 'messages.some_locale.loader':
158+
/* This resource is added by an addResource() call and shall be loaded after the resource_files */
159+
case 'second_resource.some_locale.loader':
160+
return $someCatalogue;
161+
}
162+
}
163+
164+
throw new \LogicException();
165+
});
163166

164167
$options = [
165168
'resource_files' => ['some_locale' => ['messages.some_locale.loader']],

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ public function testWarmUp()
2525
$expressionLang = $this->createMock(ExpressionLanguage::class);
2626
$expressionLang->expects($this->exactly(2))
2727
->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-
);
28+
->willReturnCallback(function ($expression, array $names) use ($expressions) {
29+
if (['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver'] !== $names || !\in_array($expression, $expressions)) {
30+
throw new \LogicException();
31+
}
32+
})
33+
;
3234

3335
(new ExpressionCacheWarmer($expressions, $expressionLang))->warmUp('');
3436
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ public function testLongKey()
2121
{
2222
$cache = $this->getMockBuilder(MaxIdLengthAdapter::class)
2323
->setConstructorArgs([str_repeat('-', 10)])
24-
->setMethods(['doHave', 'doFetch', 'doDelete', 'doSave', 'doClear'])
24+
->onlyMethods(['doHave', 'doFetch', 'doDelete', 'doSave', 'doClear'])
2525
->getMock();
2626

2727
$cache->expects($this->exactly(2))
2828
->method('doHave')
29-
->withConsecutive(
30-
[$this->equalTo('----------:nWfzGiCgLczv3SSUzXL3kg:')],
31-
[$this->equalTo('----------:---------------------------------------')]
32-
);
29+
->willReturnCallback(function (string $id) {
30+
if (!\in_array($id, ['----------:nWfzGiCgLczv3SSUzXL3kg:', '----------:---------------------------------------'], true)) {
31+
throw new \LogicException();
32+
}
33+
})
34+
;
3335

3436
$cache->hasItem(str_repeat('-', 40));
3537
$cache->hasItem(str_repeat('-', 39));

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,17 @@ 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 (string $locale) {
68+
if ('locales' === $locale) {
69+
return ['fr', 'en'];
70+
}
71+
72+
if ('default_locale' === $locale) {
73+
return 'fr';
74+
}
75+
76+
throw new \LogicException();
77+
})
7578
;
7679
}, true];
7780
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,18 @@ 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 (string $id) {
88+
if ('id1' === $id) {
89+
return 'data1';
90+
}
91+
92+
if ('id2' === $id) {
93+
return 'data2';
94+
}
95+
96+
throw new \LogicException();
97+
})
98+
;
8999
$proxy = new StrictSessionHandler($handler);
90100

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

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ 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+
if (!\in_array([$logger, $levels], $expectedCalls, true)) {
227+
throw new \LogicException();
228+
}
229+
})
230+
;
226231

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

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
4949
$this->localeAwareService
5050
->expects($this->exactly(2))
5151
->method('setLocale')
52-
->withConsecutive(
53-
[$this->anything()],
54-
['en']
55-
)
56-
->willReturnOnConsecutiveCalls(
57-
$this->throwException(new \InvalidArgumentException())
58-
);
52+
->willReturnCallback(function (string $locale) {
53+
if (!\in_array($locale, ['fr', 'en'], true)) {
54+
throw new \LogicException();
55+
}
56+
57+
if ('fr' === $locale) {
58+
throw new \InvalidArgumentException();
59+
}
60+
})
61+
;
5962

6063
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MAIN_REQUEST);
6164
$this->listener->onKernelRequest($event);
@@ -93,13 +96,16 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
9396
$this->localeAwareService
9497
->expects($this->exactly(2))
9598
->method('setLocale')
96-
->withConsecutive(
97-
[$this->anything()],
98-
['en']
99-
)
100-
->willReturnOnConsecutiveCalls(
101-
$this->throwException(new \InvalidArgumentException())
102-
);
99+
->willReturnCallback(function (string $locale) {
100+
if (!\in_array($locale, ['fr', 'en'], true)) {
101+
throw new \LogicException();
102+
}
103+
104+
if ('fr' === $locale) {
105+
throw new \InvalidArgumentException();
106+
}
107+
})
108+
;
103109

104110
$this->requestStack->push($this->createRequest('fr'));
105111
$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)