8000 minor #54768 Remove calls to `onConsecutiveCalls()` (alexandre-daubois) · VincentLanglet/symfony@146efab · GitHub
[go: up one dir, main page]

Skip to content

Commit 146efab

Browse files
minor symfony#54768 Remove calls to onConsecutiveCalls() (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- Remove calls to `onConsecutiveCalls()` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT cc `@OskarStark` as we did a lot of stuff on tests migration last year Commits ------- 4118849 Remove calls to `onConsecutiveCalls()`
2 parents ad0caee + 4118849 commit 146efab

File tree

26 files changed

+257
-195
lines changed

26 files changed

+257
-195
lines changed

src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineOpenTransactionLoggerMiddlewareTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testMiddlewareWrapsInTransactionAndFlushes()
5252
{
5353
$this->connection->expects($this->exactly(1))
5454
->method('isTransactionActive')
55-
->will($this->onConsecutiveCalls(true, true, false))
55+
->willReturn(true, true, false)
5656
;
5757

5858
$this->middleware->handle(new Envelope(new \stdClass()), $this->getStackMock());

src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ public function testVerbosityChanged()
117117
$output
118118
->expects($this->exactly(2))
119119
->method('getVerbosity')
120-
->willReturnOnConsecutiveCalls(
121-
OutputInterface::VERBOSITY_QUIET,
122-
OutputInterface::VERBOSITY_DEBUG
123-
)
120+
->willReturn(OutputInterface::VERBOSITY_QUIET, OutputInterface::VERBOSITY_DEBUG)
124121
;
125122
$handler = new ConsoleHandler($output);
12612 10000 3
$this->assertFalse($handler->isHandling(['level' => Logger::NOTICE]),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ protected function getLoader()
271271
$loader
272272
->expects($this->exactly(7))
273273
->method('load')
274-
->willReturnOnConsecutiveCalls(
274+
->willReturn(
275275
$this->getCatalogue('fr', [
276276
'foo' => 'foo (FR)',
277277
]),

src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ public function testImportWithFileLocatorDelegation()
2525
$locatorMock = $this->createMock(FileLocatorInterface::class);
2626

2727
$locatorMockForAdditionalLoader = $this->createMock(FileLocatorInterface::class);
28-
$locatorMockForAdditionalLoader->expects($this->any())->method('locate')->will($this->onConsecutiveCalls(
29-
['path/to/file1'], // Default
30-
['path/to/file1', 'path/to/file2'], // First is imported
31-
['path/to/file1', 'path/to/file2'], // Second is imported
32-
['path/to/file1'], // Exception
33-
['path/to/file1', 'path/to/file2'] // Exception
34-
));
28+
$locatorMockForAdditionalLoader->expects($this->any())
29+
->method('locate')
30+
->willReturn(
31+
['path/to/file1'],
32+
['path/to/file1', 'path/to/file2'],
33+
['path/to/file1', 'path/to/file2'],
34+
['path/to/file1'],
35+
['path/to/file1', 'path/to/file2']
36+
);
3537

3638
$fileLoader = new TestFileLoader($locatorMock);
3739
$fileLoader->setSupports(false);

src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public function testLoadFile()
7676
}
7777

7878
$mock = $this->createMock(Validator::class);
79-
$mock->expects($this->exactly(2))->method('validate')->will($this->onConsecutiveCalls(false, true));
79+
$mock->expects($this->exactly(2))->method('validate')
80+
->willReturn(false, true);
8081

8182
try {
8283
XmlUtils::loadFile($fixtures.'valid.xml', [$mock, 'validate']);

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class SessionListenerTest extends TestCase
4545
public function testSessionCookieOptions(array $phpSessionOptions, array $sessionOptions, array $expectedSessionOptions)
4646
{
4747
$session = $this->createMock(Session::class);
48-
$session->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
48+
$session->method('getUsageIndex')->willReturn(0, 1);
4949
$session->method('getId')->willReturn('123456');
5050
$session->method('getName')->willReturn('PHPSESSID');
5151
$session->method('save');
@@ -398,7 +398,7 @@ public function testSessionUsesFactory()
398398
public function testResponseIsPrivateIfSessionStarted()
399399
{
400400
$session = $this->createMock(Session::class);
401-
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
401+
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);
402402

403403
$container = new Container();
404404
$container->set('initialized_session', $session);
@@ -423,7 +423,7 @@ public function testResponseIsPrivateIfSessionStarted()
423423
public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent()
424424
{
425425
$session = $this->createMock(Session::class);
426-
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
426+
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);
427427

428428
$container = new Container();
429429
$container->set('initialized_session', $session);
@@ -450,7 +450,7 @@ public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent()
450450
public function testSessionSaveAndResponseHasSessionCookie()
451451
{
452452
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
453-
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
453+
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);
454454
$session->expects($this->exactly(1))->method('getId')->willReturn('123456');
455455
$session->expects($this->exactly(1))->method('getName')->willReturn('PHPSESSID');
456456
$session->expects($this->exactly(1))->method('save');
@@ -535,7 +535,7 @@ public function testUninitializedSessionWithoutInitializedSession()
535535
public function testResponseHeadersMaxAgeAndExpiresNotBeOverridenIfSessionStarted()
536536
{
537537
$session = $this->createMock(Session::class);
538-
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
538+
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);
539539

540540
$container = new Container();
541541
$container->set('initialized_session', $session);
@@ -565,7 +565,7 @@ public function testResponseHeadersMaxAgeAndExpiresNotBeOverridenIfSessionStarte
565565
public function testResponseHeadersMaxAgeAndExpiresDefaultValuesIfSessionStarted()
566566
{
567567
$session = $this->createMock(Session::class);
568-
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
568+
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);
569569

570570
$container = new Container();
571571
$container->set('initialized_session', $session);
@@ -618,7 +618,7 @@ public function testSurrogateMainRequestIsPublic()
618618
{
619619
$session = $this->createMock(Session::class);
620620
$session->expects($this->exactly(1))->method('getName')->willReturn('PHPSESSID');
621-
$session->expects($this->exactly(4))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1, 1, 1));
621+
$session->expects($this->exactly(4))->method('getUsageIndex')->willReturn(0, 1, 1, 1);
622622

623623
$container = new Container();
624624
$container->set('initialized_session', $session);
@@ -715,7 +715,7 @@ public function testGetSessionSetsSessionOnMainRequest()
715715
public function testSessionUsageExceptionIfStatelessAndSessionUsed()
716716
{
717717
$session = $this->createMock(Session::class);
718-
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
718+
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);
719719

720720
$container = new Container();
721721
$container->set('initialized_session', $session);
@@ -734,7 +734,7 @@ public function testSessionUsageExceptionIfStatelessAndSessionUsed()
734734
public function testSessionUsageLogIfStatelessAndSessionUsed()
735735
{
736736
$session = $this->createMock(Session::class);
737-
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
737+
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);
738738

739739
$logger = $this->createMock(LoggerInterface::class);
740740
$logger->expects($this->exactly(1))->method('warning');
@@ -759,7 +759,7 @@ public function testSessionIsSavedWhenUnexpectedSessionExceptionThrown()
759759
$session->expects($this->exactly(1))->method('getId')->willReturn('123456');
760760
$session->expects($this->exactly(1))->method('getName')->willReturn('PHPSESSID');
761761
$session->method('isStarted')->willReturn(true);
762-
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
762+
$session->expects($this->exactly(2))->method('getUsageIndex')->willReturn(0, 1);
763763
$session->expects($this->exactly(1))->method('save');
764764

765765
$container = new Container();

src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,17 @@ public function testRenderExceptionIgnoreErrors()
102102

103103
public function testRenderExceptionIgnoreErrorsWithAlt()
104104
{
105-
$strategy = new InlineFragmentRenderer($this->getKernel($this->onConsecutiveCalls(
106-
$this->throwException(new \RuntimeException('foo')),
107-
$this->returnValue(new Response('bar'))
108-
)));
105+
$strategy = new InlineFragmentRenderer($this->getKernel($this->returnCallback(function () {
106+
static $firstCall = true;
107+
108+
if ($firstCall) {
109+
$firstCall = false;
110+
111+
throw new \RuntimeException('foo');
112+
}
113+
114+
return new Response('bar');
115+
})));
109116

110117
$this->assertEquals('bar', $strategy->render('/', Request::create('/'), ['ignore_errors' => true, 'alt' => '/foo'])->getContent());
111118
}

src/Symfony/Component/HttpKernel/Tests/HttpCache/EsiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ protected function getCache($request, $response)
245245
if (\is_array($response)) {
246246
$cache->expects($this->any())
247247
->method('handle')
248-
->will($this->onConsecutiveCalls(...$response))
248+
->willReturn(...$response)
249249
;
250250
} else {
251251
$cache->expects($this->any())

src/Symfony/Component/HttpKernel/Tests/HttpCache/SsiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ protected function getCache($request, $response)
201201
if (\is_array($response)) {
202202
$cache->expects($this->any())
203203
->method('handle')
204-
->will($this->onConsecutiveCalls(...$response))
204+
->willReturn(...$response)
205205
;
206206
} else {
207207
$cache->expects($this->any())

src/Symfony/Component/Lock/Tests/LockTest.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testAcquireNoBlocking()
3939
->method('save');
4040
$store
4141
->method('exists')
42-
->willReturnOnConsecutiveCalls(true, false);
42+
->willReturn(true, false);
4343

4444
$this->assertTrue($lock->acquire(false));
4545
}
@@ -55,7 +55,7 @@ public function testAcquireNoBlockingWithPersistingStoreInterface()
5555
->method('save');
5656
$store
5757
->method('exists')
58-
->willReturnOnConsecutiveCalls(true, false);
58+
->willReturn(true, false);
5959

6060
$this->assertTrue($lock->acquire(false));
6161
}
@@ -71,7 +71,7 @@ public function testAcquireBlockingWithPersistingStoreInterface()
7171
->method('save');
7272
$store
7373
->method('exists')
74-
->willReturnOnConsecutiveCalls(true, false);
74+
->willReturn(true, false);
7575

7676
$this->assertTrue($lock->acquire(true));
7777
}
@@ -93,7 +93,7 @@ public function testAcquireBlockingRetryWithPersistingStoreInterface()
9393
});
9494
$store
9595
->method('exists')
96-
->willReturnOnConsecutiveCalls(true, false);
96+
->willReturn(true, false);
9797

9898
$this->assertTrue($lock->acquire(true));
9999
}
@@ -110,7 +110,7 @@ public function testAcquireReturnsFalse()
110110
->willThrowException(new LockConflictedException());
111111
$store
112112
->method('exists')
113-
->willReturnOnConsecutiveCalls(true, false);
113+
->willReturn(true, false);
114114

115115
$this->assertFalse($lock->acquire(false));
116116
}
@@ -127,7 +127,7 @@ public function testAcquireReturnsFalseStoreInterface()
127127
->willThrowException(new LockConflictedException());
128128
$store
129129
->method('exists')
130-
->willReturnOnConsecutiveCalls(true, false);
130+
->willReturn(true, false);
131131

132132
$this->assertFalse($lock->acquire(false));
133133
}
@@ -146,7 +146,7 @@ public function testAcquireBlockingWithBlockingStoreInterface()
146146
->method('waitAndSave');
147147
$store
148148
->method('exists')
149-
->willReturnOnConsecutiveCalls(true, false);
149+
->willReturn(true, false);
150150

151151
$this->assertTrue($lock->acquire(true));
152152
}
@@ -166,7 +166,7 @@ public function testAcquireSetsTtl()
166166
->with($key, 10);
167167
$store
168168
->method('exists')
169-
->willReturnOnConsecutiveCalls(true, false);
169+
->willReturn(true, false);
170170

171171
$lock->acquire();
172172
}
@@ -183,7 +183,7 @@ public function testRefresh()
183183
->with($key, 10);
184184
$store
185185
->method('exists')
186-
->willReturnOnConsecutiveCalls(true, false);
186+
->willReturn(true, false);
187187

188188
$lock->refresh();
189189
}
@@ -200,7 +200,7 @@ public function testRefreshCustom()
200200
->with($key, 20);
201201
$store
202202
->method('exists')
203-
->willReturnOnConsecutiveCalls(true, false);
203+
->willReturn(true, false);
204204

205205
$lock->refresh(20);
206206
}
@@ -214,7 +214,7 @@ public function testIsAquired()
214214
$store
215215
->method('exists')
216216
->with($key)
217-
->willReturnOnConsecutiveCalls(true, false);
217+
->willReturn(true, false);
218218

219219
$this->assertTrue($lock->isAcquired());
220220
}
@@ -267,8 +267,8 @@ public function testReleaseOnDestruction()
267267

268268
$store
269269
->method('exists')
270-
->willReturnOnConsecutiveCalls(true, false)
271-
;
270+
->willReturn(true, false);
271+
272272
$store
273273
->expects($this->once())
274274
->method('delete')
@@ -286,8 +286,8 @@ public function testNoAutoReleaseWhenNotConfigured()
286286

287287
$store
288288
->method('exists')
289-
->willReturnOnConsecutiveCalls(true, false)
290-
;
289+
->willReturn(true, false);
290+
291291
$store
292292
->expects($this->never())
293293
->method('delete')
@@ -313,7 +313,8 @@ public function testReleaseThrowsExceptionWhenDeletionFail()
313313
$store
314314
->expects($this->never())
315315
->method('exists')
316-
->with($key);
316+
->with($key)
317+
->willReturn(true);
317318

318319
$lock->release();
319320
}
@@ -426,7 +427,7 @@ public function testAcquireReadNoBlockingWithSharedLockStoreInterface()
426427
->method('saveRead');
427428
$store
428429
->method('exists')
429-
->willReturnOnConsecutiveCalls(true, false);
430+
->willReturn(true, false);
430431

431432
$this->assertTrue($lock->acquireRead(false));
432433
}
@@ -534,7 +535,7 @@ public function testAcquireReadBlockingWithBlockingSharedLockStoreInterface()
534535
->method('waitAndSaveRead');
535536
$store
536537
->method('exists')
537-
->willReturnOnConsecutiveCalls(true, false);
538+
->willReturn(true, false);
538539

539540
$this->assertTrue($lock->acquireRead(true));
540541
}
@@ -556,7 +557,7 @@ public function testAcquireReadBlockingWithSharedLockStoreInterface()
556557
});
557558
$store
558559
->method('exists')
559-
->willReturnOnConsecutiveCalls(true, false);
560+
->willReturn(true, false);
560561

561562
$this->assertTrue($lock->acquireRead(true));
562563
}
@@ -572,7 +573,7 @@ public function testAcquireReadBlockingWithBlockingLockStoreInterface()
572573
->method('waitAndSave');
573574
$store
574575
->method('exists')
575-
->willReturnOnConsecutiveCalls(true, false);
576+
->willReturn(true, false);
576577

577578
$this->assertTrue($lock->acquireRead(true));
578579
}
@@ -594,7 +595,7 @@ public function testAcquireReadBlockingWithPersistingStoreInterface()
594595
});
595596
$store
596597
->method('exists')
597-
->willReturnOnConsecutiveCalls(true, false);
598+
->willReturn(true, false);
598599

599600
$this->assertTrue($lock->acquireRead(true));
600601
}

0 commit comments

Comments
 (0)
0