From 999a75f9149b853ec0057fbb34868bf7ccb41db0 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 17 Feb 2024 18:38:04 +0100 Subject: [PATCH] get rid of mocks --- tests/Unit/Doctrine/Orm/RouteProviderTest.php | 18 +---- .../Unit/Doctrine/Phpcr/RouteProviderTest.php | 65 +++---------------- 2 files changed, 13 insertions(+), 70 deletions(-) diff --git a/tests/Unit/Doctrine/Orm/RouteProviderTest.php b/tests/Unit/Doctrine/Orm/RouteProviderTest.php index a4a8f737..5748ee0b 100644 --- a/tests/Unit/Doctrine/Orm/RouteProviderTest.php +++ b/tests/Unit/Doctrine/Orm/RouteProviderTest.php @@ -203,13 +203,7 @@ public function testGetRoutesByNames(): void $this->objectRepositoryMock ->expects($this->at(0)) ->method('findOneBy') - ->with(['name' => $paths[0]]) - ->willReturn($this->routeMock) - ; - $this->objectRepositoryMock - ->expects($this->at(1)) - ->method('findOneBy') - ->with(['name' => $paths[1]]) + ->withConsecutive([['name' => $paths[0]]], [['name' => $paths[1]]]) ->willReturn($this->routeMock) ; @@ -225,14 +219,8 @@ public function testGetRoutesByNames(): void $candidatesMock ->expects($this->at(1)) ->method('isCandidate') - ->with($paths[1]) - ->willReturn(true) - ; - $candidatesMock - ->expects($this->at(2)) - ->method('isCandidate') - ->with($paths[2]) - ->willReturn(false) + ->withConsecutive([$paths[1]], [$paths[2]]) + ->willReturnOnConsecutiveCalls(true, false) ; $routeProvider = new RouteProvider($this->managerRegistryMock, $candidatesMock, 'Route'); diff --git a/tests/Unit/Doctrine/Phpcr/RouteProviderTest.php b/tests/Unit/Doctrine/Phpcr/RouteProviderTest.php index b5a21e1c..0a66a24c 100644 --- a/tests/Unit/Doctrine/Phpcr/RouteProviderTest.php +++ b/tests/Unit/Doctrine/Phpcr/RouteProviderTest.php @@ -87,10 +87,10 @@ public function testGetRouteCollectionForRequest(): void ->willReturn($candidates) ; - $objects = [ + $objects = new ArrayCollection([ new Route('/my'), $this, - ]; + ]); $this->dmMock ->expects($this->once()) @@ -327,28 +327,9 @@ public function testGetRoutesByNames(): void ; $this->candidatesMock - ->expects($this->at(0)) - ->method('isCandidate') - ->with('/cms/routes/test-route') - ->willReturn(true) - ; - $this->candidatesMock - ->expects($this->at(1)) - ->method('isCandidate') - ->with('/cms/simple/other-route') - ->willReturn(true) - ; - $this->candidatesMock - ->expects($this->at(2)) ->method('isCandidate') - ->with('/cms/routes/not-a-route') - ->willReturn(true) - ; - $this->candidatesMock - ->expects($this->at(3)) - ->method('isCandidate') - ->with('/outside/prefix') - ->willReturn(false) + ->withConsecutive(['/cms/routes/test-route'], ['/cms/simple/other-route'], ['/cms/routes/not-a-route'], ['/outside/prefix']) + ->willReturnOnConsecutiveCalls(true, true, true, false) ; $paths[] = '/outside/prefix'; @@ -374,21 +355,8 @@ public function testGetRoutesByNamesNotCandidates(): void ; $this->candidatesMock - ->expects($this->at(0)) ->method('isCandidate') - ->with('/cms/routes/test-route') - ->willReturn(false) - ; - $this->candidatesMock - ->expects($this->at(1)) - ->method('isCandidate') - ->with('/cms/simple/other-route') - ->willReturn(false) - ; - $this->candidatesMock - ->expects($this->at(2)) - ->method('isCandidate') - ->with('/cms/routes/not-a-route') + ->with(['/cms/routes/test-route'], ['/cms/simple/other-route'], ['/cms/routes/not-a-route']) ->willReturn(false) ; @@ -429,29 +397,15 @@ public function testGetRoutesByNamesUuid(): void ->willReturn($uow) ; $uow - ->expects($this->at(0)) ->method('getDocumentId') - ->with($route1) - ->willReturn('/cms/routes/test-route') - ; - $uow - ->expects($this->at(1)) - ->method('getDocumentId') - ->with($route2) - ->willReturn('/cms/routes/other-route') + ->withConsecutive([$route1], [$route2]) + ->willReturnOnConsecutiveCalls('/cms/routes/test-route', '/cms/routes/other-route') ; $this->candidatesMock - ->expects($this->at(0)) - ->method('isCandidate') - ->with('/cms/routes/test-route') - ->willReturn(true) - ; - $this->candidatesMock - ->expects($this->at(1)) ->method('isCandidate') - ->with('/cms/routes/other-route') - ->willReturn(false) + ->withConsecutive(['/cms/routes/test-route'], ['/cms/routes/other-route']) + ->willReturnOnConsecutiveCalls(true, false) ; $routeProvider = new RouteProvider($this->managerRegistryMock, $this->candidatesMock); @@ -469,6 +423,7 @@ private function doRouteDump($limit): void ->with(Route::class, 'd') ; + $query = $this->createMock(Query::class); $query ->expects($this->once())