Skip to content

Commit

Permalink
get rid of mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Feb 17, 2024
1 parent 2e8d45d commit 90cdcc4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 83 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"jackalope/jackalope-doctrine-dbal": "^1.3",
"doctrine/phpcr-odm": "^1.4 || ^2.0",
"symfony/phpunit-bridge": "^7.0.3",
"matthiasnoback/symfony-dependency-injection-test": "^4.1.0",
"matthiasnoback/symfony-config-test": "^4.1.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.1.0 || ^5.1.0",
"matthiasnoback/symfony-config-test": "^4.1.0 || ^5.1.0",
"doctrine/orm": "^2.9",
"symfony-cmf/testing": "dev-sf7 as 4.2.0",
"doctrine/data-fixtures": "^1.0.0",
Expand Down Expand Up @@ -70,5 +70,5 @@
"composer/package-versions-deprecated": true
}
},
"minimum-stability": "beta"
"minimum-stability": "dev"
}
25 changes: 2 additions & 23 deletions tests/Unit/Doctrine/Orm/RouteProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,38 +201,17 @@ 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]])
->willReturn($this->routeMock)
;

$paths[] = '/no-candidate';

$candidatesMock = $this->createMock(CandidatesInterface::class);
$candidatesMock
->expects($this->at(0))
->method('isCandidate')
->with($paths[0])
->willReturn(true)
;
$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[0]], [$paths[1]], [$paths[2]])
->willReturnOnConsecutiveCalls(true, true, false)
;

$routeProvider = new RouteProvider($this->managerRegistryMock, $candidatesMock, 'Route');
Expand Down
68 changes: 11 additions & 57 deletions tests/Unit/Doctrine/Phpcr/RouteProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\PHPCR\DocumentManager;
use Doctrine\ODM\PHPCR\Query\Builder\From;
use Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder;
use Doctrine\ODM\PHPCR\Query\Builder\SourceFactory;
use Doctrine\ODM\PHPCR\Query\Query;
use Doctrine\ODM\PHPCR\UnitOfWork;
use Doctrine\Persistence\ManagerRegistry;
Expand Down Expand Up @@ -87,10 +87,10 @@ public function testGetRouteCollectionForRequest(): void
->willReturn($candidates)
;

$objects = [
$objects = new ArrayCollection([
new Route('/my'),
$this,
];
]);

$this->dmMock
->expects($this->once())
Expand Down Expand Up @@ -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';
Expand All @@ -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')
->withConsecutive(['/cms/routes/test-route'], ['/cms/simple/other-route'], ['/cms/routes/not-a-route'])
->willReturn(false)
;

Expand Down Expand Up @@ -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);
Expand All @@ -463,7 +417,7 @@ public function testGetRoutesByNamesUuid(): void

private function doRouteDump($limit): void
{
$from = $this->createMock(SourceFactory::class);
$from = $this->createMock(From::class);
$from->expects($this->once())
->method('document')
->with(Route::class, 'd')
Expand Down

0 comments on commit 90cdcc4

Please sign in to comment.