From b1f7975b62e9a0b2f7bec5fa592b44a610f4609a Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Mon, 19 Jan 2026 09:29:09 +0100 Subject: [PATCH] improve tests --- tests/Knp/Menu/Tests/Iterator/IteratorTest.php | 4 ++-- tests/Knp/Menu/Tests/Matcher/MatcherTest.php | 8 ++++---- .../Knp/Menu/Tests/Matcher/Voter/RegexVoterTest.php | 2 +- .../Knp/Menu/Tests/Matcher/Voter/RouteVoterTest.php | 4 ++-- tests/Knp/Menu/Tests/Matcher/Voter/UriVoterTest.php | 2 +- tests/Knp/Menu/Tests/Provider/ChainProviderTest.php | 4 ++-- tests/Knp/Menu/Tests/Twig/HelperTest.php | 10 +++++----- tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php | 12 ++++++------ tests/Knp/Menu/Tests/Util/MenuManipulatorTest.php | 2 +- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/Knp/Menu/Tests/Iterator/IteratorTest.php b/tests/Knp/Menu/Tests/Iterator/IteratorTest.php index d96674bb..60360fd4 100644 --- a/tests/Knp/Menu/Tests/Iterator/IteratorTest.php +++ b/tests/Knp/Menu/Tests/Iterator/IteratorTest.php @@ -22,10 +22,10 @@ public function testRecursiveIterator(): void { // Adding an item which does not provide a RecursiveIterator to be sure it works properly. $child = $this->getMockBuilder(ItemInterface::class)->getMock(); - $child->expects($this->any()) + $child ->method('getName') ->willReturn('Foo'); - $child->expects($this->any()) + $child ->method('getIterator') ->willReturn(new \EmptyIterator()); $this->menu->addChild($child); diff --git a/tests/Knp/Menu/Tests/Matcher/MatcherTest.php b/tests/Knp/Menu/Tests/Matcher/MatcherTest.php index 6c49d31b..f502601b 100644 --- a/tests/Knp/Menu/Tests/Matcher/MatcherTest.php +++ b/tests/Knp/Menu/Tests/Matcher/MatcherTest.php @@ -15,7 +15,7 @@ final class MatcherTest extends TestCase public function testItemFlag(?bool $flag, bool $expected): void { $item = $this->getMockBuilder(ItemInterface::class)->getMock(); - $item->expects($this->any()) + $item ->method('isCurrent') ->willReturn($flag); @@ -55,7 +55,7 @@ public function testFlagOverwritesCache(): void public function testFlagWinsOverVoter(bool $value): void { $item = $this->getMockBuilder(ItemInterface::class)->getMock(); - $item->expects($this->any()) + $item ->method('isCurrent') ->willReturn($value); @@ -74,7 +74,7 @@ public function testFlagWinsOverVoter(bool $value): void public function testFirstVoterWins(bool $value): void { $item = $this->getMockBuilder(ItemInterface::class)->getMock(); - $item->expects($this->any()) + $item ->method('isCurrent') ->willReturn(null); @@ -99,7 +99,7 @@ public function testFirstVoterWins(bool $value): void public function testVoterIterator(bool $value): void { $item = $this->getMockBuilder(ItemInterface::class)->getMock(); - $item->expects($this->any()) + $item ->method('isCurrent') ->willReturn(null); diff --git a/tests/Knp/Menu/Tests/Matcher/Voter/RegexVoterTest.php b/tests/Knp/Menu/Tests/Matcher/Voter/RegexVoterTest.php index a2f2f4db..e05ddc97 100644 --- a/tests/Knp/Menu/Tests/Matcher/Voter/RegexVoterTest.php +++ b/tests/Knp/Menu/Tests/Matcher/Voter/RegexVoterTest.php @@ -14,7 +14,7 @@ final class RegexVoterTest extends TestCase public function testMatching(?string $exp, ?string $itemUri, ?bool $expected): void { $item = $this->getMockBuilder(ItemInterface::class)->getMock(); - $item->expects($this->any()) + $item ->method('getUri') ->willReturn($itemUri); diff --git a/tests/Knp/Menu/Tests/Matcher/Voter/RouteVoterTest.php b/tests/Knp/Menu/Tests/Matcher/Voter/RouteVoterTest.php index 970bd123..fa08315a 100644 --- a/tests/Knp/Menu/Tests/Matcher/Voter/RouteVoterTest.php +++ b/tests/Knp/Menu/Tests/Matcher/Voter/RouteVoterTest.php @@ -26,7 +26,7 @@ public function testInvalidRouteConfig(): void $this->expectException(\InvalidArgumentException::class); $item = $this->getMockBuilder(ItemInterface::class)->getMock(); - $item->expects($this->any()) + $item ->method('getExtra') ->with('routes') ->willReturn([['invalid' => 'array']]); @@ -53,7 +53,7 @@ public function testInvalidRouteConfig(): void public function testMatching(?string $route, array $parameters, array $queryParameters, $itemRoutes, ?bool $expected): void { $item = $this->getMockBuilder(ItemInterface::class)->getMock(); - $item->expects($this->any()) + $item ->method('getExtra') ->with('routes') ->willReturn($itemRoutes) diff --git a/tests/Knp/Menu/Tests/Matcher/Voter/UriVoterTest.php b/tests/Knp/Menu/Tests/Matcher/Voter/UriVoterTest.php index 21ea24ed..92365d91 100644 --- a/tests/Knp/Menu/Tests/Matcher/Voter/UriVoterTest.php +++ b/tests/Knp/Menu/Tests/Matcher/Voter/UriVoterTest.php @@ -14,7 +14,7 @@ final class UriVoterTest extends TestCase public function testMatching(?string $uri, ?string $itemUri, ?bool $expected): void { $item = $this->getMockBuilder(ItemInterface::class)->getMock(); - $item->expects($this->any()) + $item ->method('getUri') ->willReturn($itemUri); diff --git a/tests/Knp/Menu/Tests/Provider/ChainProviderTest.php b/tests/Knp/Menu/Tests/Provider/ChainProviderTest.php index 2d373c4d..f2835e47 100644 --- a/tests/Knp/Menu/Tests/Provider/ChainProviderTest.php +++ b/tests/Knp/Menu/Tests/Provider/ChainProviderTest.php @@ -35,7 +35,7 @@ public function testGetExistentMenu(): void { $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); $innerProvider = $this->getMockBuilder(MenuProviderInterface::class)->getMock(); - $innerProvider->expects($this->any()) + $innerProvider ->method('has') ->with('default') ->willReturn(true) @@ -54,7 +54,7 @@ public function testGetWithOptions(): void { $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); $innerProvider = $this->getMockBuilder(MenuProviderInterface::class)->getMock(); - $innerProvider->expects($this->any()) + $innerProvider ->method('has') ->with('default', ['foo' => 'bar']) ->willReturn(true) diff --git a/tests/Knp/Menu/Tests/Twig/HelperTest.php b/tests/Knp/Menu/Tests/Twig/HelperTest.php index e5ab5b43..c1bcb2df 100644 --- a/tests/Knp/Menu/Tests/Twig/HelperTest.php +++ b/tests/Knp/Menu/Tests/Twig/HelperTest.php @@ -157,7 +157,7 @@ public function testGetMenuByPath(): void $menuProvider = $this->getMockBuilder(MenuProviderInterface::class)->getMock(); $child = $this->getMockBuilder(ItemInterface::class)->getMock(); $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); - $menu->expects($this->any()) + $menu ->method('getChild') ->with('child') ->willReturn($child) @@ -180,12 +180,12 @@ public function testGetMenuByInvalidPath(): void $rendererProvider = $this->getMockBuilder(RendererProviderInterface::class)->getMock(); $menuProvider = $this->getMockBuilder(MenuProviderInterface::class)->getMock(); $child = $this->getMockBuilder(ItemInterface::class)->getMock(); - $child->expects($this->any()) + $child ->method('getChild') ->willReturn(null) ; $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); - $menu->expects($this->any()) + $menu ->method('getChild') ->with('child') ->willReturn($child) @@ -205,7 +205,7 @@ public function testRenderMenuByPath(): void { $child = $this->getMockBuilder(ItemInterface::class)->getMock(); $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); - $menu->expects($this->any()) + $menu ->method('getChild') ->with('child') ->willReturn($child) @@ -244,7 +244,7 @@ public function testBreadcrumbsArray(): void $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); $manipulator = $this->getMockBuilder(MenuManipulator::class)->getMock(); - $manipulator->expects($this->any()) + $manipulator ->method('getBreadcrumbsArray') ->with($menu) ->willReturn(['A', 'B']); diff --git a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php index 18c2ae5c..7238a75b 100644 --- a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php +++ b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php @@ -89,7 +89,7 @@ public function testRetrieveMenuByName(): void public function testGetBreadcrumbsArray(): void { $helper = $this->getHelperMock(['getBreadcrumbsArray']); - $helper->expects($this->any()) + $helper ->method('getBreadcrumbsArray') ->with('default') ->willReturn(['A', 'B']) @@ -103,11 +103,11 @@ public function testPathAsString(): void $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); $helper = $this->getHelperMock(['get']); $manipulator = $this->getManipulatorMock(['getPathAsString']); - $helper->expects($this->any()) + $helper ->method('get') ->with('default') ->willReturn($menu); - $manipulator->expects($this->any()) + $manipulator ->method('getPathAsString') ->with($menu) ->willReturn('A > B') @@ -121,7 +121,7 @@ public function testIsCurrent(): void $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); $helper = $this->getHelperMock([]); $matcher = $this->getMatcherMock(); - $matcher->expects($this->any()) + $matcher ->method('isCurrent') ->with($menu) ->willReturn(true) @@ -135,7 +135,7 @@ public function testIsAncestor(): void $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); $helper = $this->getHelperMock([]); $matcher = $this->getMatcherMock(); - $matcher->expects($this->any()) + $matcher ->method('isAncestor') ->with($menu) ->willReturn(false) @@ -154,7 +154,7 @@ public function testGetCurrentItem(): void ->willReturn($menu) ; $matcher = $this->getMatcherMock(); - $matcher->expects($this->any()) + $matcher ->method('isCurrent') ->with($menu) ->willReturn(true) diff --git a/tests/Knp/Menu/Tests/Util/MenuManipulatorTest.php b/tests/Knp/Menu/Tests/Util/MenuManipulatorTest.php index 6081cfd6..c6c9f18f 100644 --- a/tests/Knp/Menu/Tests/Util/MenuManipulatorTest.php +++ b/tests/Knp/Menu/Tests/Util/MenuManipulatorTest.php @@ -196,7 +196,7 @@ public function testCallRecursively(): void foreach (\range(1, 2) as $i) { $child = $this->getMockBuilder(ItemInterface::class)->getMock(); - $child->expects($this->any()) + $child ->method('getName') ->willReturn('Child '.$i) ;