Skip to content

Commit

Permalink
minor #49621 [Tests] Remove occurrences of withConsecutive() (alexa…
Browse files Browse the repository at this point in the history
…ndre-daubois)

This PR was merged into the 5.4 branch.

Discussion
----------

[Tests] Remove occurrences of `withConsecutive()`

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

`withConsecutive()` has been deprecated in PHPUnit 9.6 and removed in PHP 10 (sebastianbergmann/phpunit#4564). This PR aims at starting the work to remove these occurrences. There is unfortunately no given migration path, and this requires manual work.

I'll create a meta issue referencing remaining occurrences if this one's merged, to keep track. Some seems pretty hard to remove.

cc `@OskarStark` this might interest you, as we worked a lot on tests lately 😄

Commits
-------

2047763649 [Tests] Remove occurrences of `withConsecutive()`
  • Loading branch information
nicolas-grekas committed Mar 10, 2023
2 parents f24d83c + 2371736 commit 4b1d04e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
25 changes: 21 additions & 4 deletions Tests/Console/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,31 @@ private function getKernel(array $bundles, $useDispatcher = false)
$container
->expects($this->exactly(2))
->method('hasParameter')
->withConsecutive(['console.command.ids'], ['console.lazy_command.ids'])
->willReturnOnConsecutiveCalls(true, true)
->willReturnCallback(function (...$args) {
static $series = [
['console.command.ids'],
['console.lazy_command.ids'],
];

$this->assertSame(array_shift($series), $args);

return true;
})
;

$container
->expects($this->exactly(2))
->method('getParameter')
->withConsecutive(['console.lazy_command.ids'], ['console.command.ids'])
->willReturnOnConsecutiveCalls([], [])
->willReturnCallback(function (...$args) {
static $series = [
['console.lazy_command.ids'],
['console.command.ids'],
];

$this->assertSame(array_shift($series), $args);

return [];
})
;

$kernel = $this->createMock(KernelInterface::class);
Expand Down
23 changes: 13 additions & 10 deletions Tests/Translation/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,21 @@ public function testResourceFilesOptionLoadsBeforeOtherAddedResources($debug, $e

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

$series = [
/* The "messages.some_locale.loader" is passed via the resource_file option and shall be loaded first */
[['messages.some_locale.loader', 'some_locale', 'messages'], $someCatalogue],
/* This resource is added by an addResource() call and shall be loaded after the resource_files */
[['second_resource.some_locale.loader', 'some_locale', 'messages'], $someCatalogue],
];

$loader->expects($this->exactly(2))
->method('load')
->withConsecutive(
/* The "messages.some_locale.loader" is passed via the resource_file option and shall be loaded first */
['messages.some_locale.loader', 'some_locale', 'messages'],
/* This resource is added by an addResource() call and shall be loaded after the resource_files */
['second_resource.some_locale.loader', 'some_locale', 'messages']
)
->willReturnOnConsecutiveCalls(
$someCatalogue,
$someCatalogue
);
->willReturnCallback(function (...$args) use (&$series) {
[$expectedArgs, $return] = array_shift($series);
$this->assertSame($expectedArgs, $args);

return $return;
});

$options = [
'resource_files' => ['some_locale' => ['messages.some_locale.loader']],
Expand Down

0 comments on commit 4b1d04e

Please sign in to comment.