8000 [Tests] Remove occurrences of `withConsecutive()` · adpauly/symfony@2047763 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2047763

Browse files
alexandre-dauboisnicolas-grekas
authored andcommitted
[Tests] Remove occurrences of withConsecutive()
1 parent 10c73d3 commit 2047763

File tree

32 files changed

+796
-365
lines changed

32 files changed

+796
-365
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\Twig\Extension\StopwatchExtension;
1616
use Symfony\Component\Stopwatch\Stopwatch;
17+
use Symfony\Component\Stopwatch\StopwatchEvent;
1718
use Twig\Environment;
1819
use Twig\Error\RuntimeError;
1920
use Twig\Loader\ArrayLoader;
@@ -67,12 +68,29 @@ protected function getStopwatch($events = [])
6768
$expectedStopCalls[] = [$this->equalTo($eventName)];
6869
}
6970

70-
$startInvocationMocker = $stopwatch->expects($this->exactly($expectedCalls))
71-
->method('start');
72-
\call_user_func_array([$startInvocationMocker, 'withConsecutive'], $expectedStartCalls);
73-
$stopInvocationMocker = $stopwatch->expects($this->exactly($expectedCalls))
74-
->method('stop');
75-
\call_user_func_array([$stopInvocationMocker, 'withConsecutive'], $expectedStopCalls);
71+
$stopwatch
72+
->expects($this->exactly($expectedCalls))
73+
->method('start')
74+
->willReturnCallback(function (string $name, string $category) use (&$expectedStartCalls) {
75+
[$expectedName, $expectedCategory] = array_shift($expectedStartCalls);
76+
77+
$expectedName->evaluate($name);
78+
$this->assertSame($expectedCategory, $category);
79+
80+
return $this->createMock(StopwatchEvent::class);
81+
})
82+
;
83+
84+
$stopwatch
85+
->expects($this->exactly($expectedCalls))
86+
->method('stop')
87+
->willReturnCallback(function (string $name) use (&$expectedStopCalls) {
88+
[$expectedName] = array_shift($expectedStopCalls);
89+
$expectedName->evaluate($name);
90+
91+
return $this->createMock(StopwatchEvent::class);
92+
})
93+
;
7694

7795
return $stopwatch;
7896
}

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'],
264+
['console.lazy_command.ids'],
265+
];
266+
267+
$this->assertSame(array_shift($series), $args);
268+
269+
return true;
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+
$this->assertSame(array_shift($series), $args);
283+
284+
return [];
285+
})
269286
;
270287

271288
$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
@@ -148,18 +148,21 @@ 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+
$this->assertSame($expectedArgs, $args);
163+
164+
return $return;
165+
});
163166

164167
$options = [
165168
'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
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\SecurityBundle\CacheWarmer\ExpressionCacheWarmer;
1616
use Symfony\Component\ExpressionLanguage\Expression;
17+
use Symfony\Component\ExpressionLanguage\ParsedExpression;
1718
use Symfony\Component\Security\Core\Authorization\ExpressionLanguage;
1819

1920
class ExpressionCacheWarmerTest extends TestCase
@@ -22,13 +23,21 @@ public function testWarmUp()
2223
{
2324
$expressions = [new Expression('A'), new Expression('B')];
2425

26+
$series = [
27+
[$expressions[0], ['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver']],
28+
[$expressions[1], ['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver']],
29+
];
30+
2531
$expressionLang = $this->createMock(ExpressionLanguage::class);
2632
$expressionLang->expects($this->exactly(2))
2733
->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-
);
34+
->willReturnCallback(function (...$args) use (&$series) {
35+
$expectedArgs = array_shift($series);
36+
$this->assertSame($expectedArgs, $args);
37+
38+
return $this->createMock(ParsedExpression::class);
39+
})
40+
;
3241

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

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ 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+
$this->assertSame($expectedArgs, $args);
37+
})
38+
;
3339

3440
$cache->hasItem(str_repeat('-', 40));
3541
$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 (...$args) {
68+
static $series = [
69+
[['locales'], ['fr', 'en']],
70+
[['default_locale'], 'fr'],
71+
];
72+
73+
[$expectedArgs, $return] = array_shift($series);
74+
self::assertSame($expectedArgs, $args);
75+
76+
return $return;
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 (...$args) {
88+
static $series = [
89+
[['id1'], 'data1'],
90+
[['id2'], 'data2'],
91+
];
92+
93+
[$expectedArgs, $return] = array_shift($series);
94+
$this->assertSame($expectedArgs, $args);
95+
96+
return $return;
97+
})
98+
;
8999
$proxy = new StrictSessionHandler($handler);
90100

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

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,13 @@ 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+
$this->assertSame($expectedLogger, $logger);
229+
$this->assertSame($expectedLevels, $levels);
230+
})
231+
;
226232

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

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ 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+
$this->assertSame('en', $locale);
59+
})
60+
;
5961

6062
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MAIN_REQUEST);
6163
$this->listener->onKernelRequest($event);
@@ -90,16 +92,18 @@ public function testLocaleIsSetToDefaultOnKernelFinishRequestWhenParentRequestDo
9092

9193
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
9294
{
95+
$matcher = $this->exactly(2);
9396
$this->localeAwareService
94-
->expects($this->exactly(2))
97+
->expects($matcher)
9598
->method('setLocale')
96-
->withConsecutive(
97-
[$this->anything()],
98-
['en']
99-
)
100-
->willReturnOnConsecutiveCalls(
101-
$this->throwException(new \InvalidArgumentException())
102-
);
99+
->willReturnCallback(function (string $locale) use ($matcher) {
100+
if (1 === $matcher->getInvocationCount()) {
101+
throw new \InvalidArgumentException();
102+
}
103+
104+
$this->assertSame('en', $locale);
105+
})
106+
;
103107

104108
$this->requestStack->push($this->createRequest('fr'));
105109
$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 (null !== $container) {
187+
$this->assertInstanceOf(ContainerInterface::class, $container);
188+
}
189+
})
190+
;
189191

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

0 commit comments

Comments
 (0)
0