Skip to content

Commit 1a2ebbe

Browse files
committed
get rid of mocks
1 parent 2e8d45d commit 1a2ebbe

File tree

10 files changed

+82
-157
lines changed

10 files changed

+82
-157
lines changed

.github/workflows/test-application.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131

3232
steps:
3333
- name: Checkout project
34-
uses: actions/checkout@v3
34+
uses: actions/checkout@v4
3535

3636
- name: Install and configure PHP
3737
uses: shivammathur/setup-php@v2
@@ -46,7 +46,7 @@ jobs:
4646
composer global require --no-progress --no-scripts --no-plugins symfony/flex
4747
4848
- name: Install dependencies with Composer
49-
uses: ramsey/composer-install@v1
49+
uses: ramsey/composer-install@v2
5050
with:
5151
dependency-versions: ${{ matrix.dependencies }}
5252
composer-options: --prefer-dist

composer.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,28 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^8.0",
18+
"php": "^8.1",
1919
"symfony-cmf/routing": "^3.0",
20-
"symfony/framework-bundle": "^6.0 || ^7.0"
20+
"symfony/framework-bundle": "^6.4 || ^7.0"
2121
},
2222
"require-dev": {
23-
"jackalope/jackalope-doctrine-dbal": "^1.3",
23+
"doctrine/data-fixtures": "^1.0.0",
24+
"doctrine/doctrine-bundle": "^2.0",
25+
"doctrine/orm": "^2.9 || ^3.0",
26+
"doctrine/phpcr-bundle": "^2.3 || ^3.0",
2427
"doctrine/phpcr-odm": "^1.4 || ^2.0",
28+
"jackalope/jackalope-doctrine-dbal": "^1.3 || ^2.0",
29+
"matthiasnoback/symfony-dependency-injection-test": "^4.1.0 || ^5.1.0",
30+
"matthiasnoback/symfony-config-test": "^4.1.0 || ^5.1.0",
2531
"symfony/phpunit-bridge": "^7.0.3",
26-
"matthiasnoback/symfony-dependency-injection-test": "^4.1.0",
27-
"matthiasnoback/symfony-config-test": "^4.1.0",
28-
"doctrine/orm": "^2.9",
29-
"symfony-cmf/testing": "dev-sf7 as 4.2.0",
30-
"doctrine/data-fixtures": "^1.0.0",
3132
"symfony/form": "^6.0 || ^7.0",
33+
"symfony/monolog-bundle": "^3.5",
34+
"symfony/security-bundle": "^6.0 || ^7.0",
35+
"symfony/serializer": "^6.0 || ^7.0",
3236
"symfony/translation": "^6.0 || ^7.0",
3337
"symfony/validator": "^6.0 || ^7.0",
34-
"symfony/security-bundle": "^6.0 || ^7.0",
35-
"doctrine/doctrine-bundle": "^2.0",
3638
"symfony/twig-bundle": "^6.0 || ^7.0",
37-
"symfony/monolog-bundle": "^3.5",
38-
"doctrine/phpcr-bundle": "^2.3",
39-
"symfony/serializer": "^6.0 || ^7.0",
39+
"symfony-cmf/testing": "dev-sf7 as 4.2.0",
4040
"twig/twig": "^2.4.4 || ^3.0"
4141
},
4242
"suggest": {
@@ -70,5 +70,5 @@
7070
"composer/package-versions-deprecated": true
7171
}
7272
},
73-
"minimum-stability": "beta"
73+
"minimum-stability": "dev"
7474
}

tests/Fixtures/App/config/config.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
framework:
2-
serializer:
3-
enable_annotations: false
2+
serializer: ~
43
property_access: ~
5-
annotations: ~

tests/Unit/Doctrine/Orm/RouteProviderTest.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -201,38 +201,17 @@ public function testGetRoutesByNames(): void
201201
];
202202

203203
$this->objectRepositoryMock
204-
->expects($this->at(0))
205204
->method('findOneBy')
206-
->with(['name' => $paths[0]])
207-
->willReturn($this->routeMock)
208-
;
209-
$this->objectRepositoryMock
210-
->expects($this->at(1))
211-
->method('findOneBy')
212-
->with(['name' => $paths[1]])
213205
->willReturn($this->routeMock)
214206
;
215207

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

218210
$candidatesMock = $this->createMock(CandidatesInterface::class);
219211
$candidatesMock
220-
->expects($this->at(0))
221212
->method('isCandidate')
222-
->with($paths[0])
223-
->willReturn(true)
224-
;
225-
$candidatesMock
226-
->expects($this->at(1))
227-
->method('isCandidate')
228-
->with($paths[1])
229-
->willReturn(true)
230-
;
231-
$candidatesMock
232-
->expects($this->at(2))
233-
->method('isCandidate')
234-
->with($paths[2])
235-
->willReturn(false)
213+
->withConsecutive([$paths[0]], [$paths[1]], [$paths[2]])
214+
->willReturnOnConsecutiveCalls(true, true, false)
236215
;
237216

238217
$routeProvider = new RouteProvider($this->managerRegistryMock, $candidatesMock, 'Route');

tests/Unit/Doctrine/Phpcr/ContentRepositoryTest.php

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Unit\Doctrine\Phpcr;
1313

1414
use Doctrine\ODM\PHPCR\DocumentManager;
15+
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
1516
use Doctrine\ODM\PHPCR\UnitOfWork;
1617
use Doctrine\Persistence\ManagerRegistry;
17-
use Doctrine\Persistence\ObjectManager;
1818
use PHPUnit\Framework\TestCase;
1919
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\ContentRepository;
2020

@@ -34,24 +34,22 @@ public function setUp(): void
3434
{
3535
$this->document = new \stdClass();
3636
$this->document2 = new \stdClass();
37-
$this->objectManager = $this->createMock(ObjectManager::class);
38-
$this->objectManager2 = $this->createMock(ObjectManager::class);
37+
$this->objectManager = $this->createMock(DocumentManagerInterface::class);
38+
$this->objectManager2 = $this->createMock(DocumentManagerInterface::class);
3939
$this->managerRegistry = $this->createMock(ManagerRegistry::class);
4040
}
4141

42-
public function testFindById()
42+
public function testFindById(): void
4343
{
4444
$this->objectManager
45-
->expects($this->any())
4645
->method('find')
4746
->with(null, 'id-123')
48-
->will($this->returnValue($this->document))
47+
->willReturn($this->document)
4948
;
5049

5150
$this->managerRegistry
52-
->expects($this->any())
5351
->method('getManager')
54-
->will($this->returnValue($this->objectManager))
52+
->willReturn($this->objectManager)
5553
;
5654

5755
$contentRepository = new ContentRepository($this->managerRegistry);
@@ -60,25 +58,25 @@ public function testFindById()
6058
$this->assertSame($this->document, $contentRepository->findById('id-123'));
6159
}
6260

63-
public function testGetContentId()
61+
public function testGetContentId(): void
6462
{
6563
$uow = $this->createMock(UnitOfWork::class);
6664
$uow->expects($this->once())
6765
->method('getDocumentId')
6866
->with($this->document)
69-
->will($this->returnValue('id-123'))
67+
->willReturn('id-123')
7068
;
7169

7270
$dm = $this->createMock(DocumentManager::class);
7371
$dm
7472
->expects($this->once())
7573
->method('getUnitOfWork')
76-
->will($this->returnValue($uow))
74+
->willReturn($uow)
7775
;
7876
$this->managerRegistry
7977
->expects($this->once())
8078
->method('getManager')
81-
->will($this->returnValue($dm))
79+
->willReturn($dm)
8280
;
8381

8482
$contentRepository = new ContentRepository($this->managerRegistry);
@@ -87,18 +85,18 @@ public function testGetContentId()
8785
$this->assertEquals('id-123', $contentRepository->getContentId($this->document));
8886
}
8987

90-
public function testGetContentIdNoObject()
88+
public function testGetContentIdNoObject(): void
9189
{
9290
$contentRepository = new ContentRepository($this->managerRegistry);
9391
$this->assertNull($contentRepository->getContentId('hello'));
9492
}
9593

96-
public function testGetContentIdException()
94+
public function testGetContentIdException(): void
9795
{
9896
$this->managerRegistry
9997
->expects($this->once())
10098
->method('getManager')
101-
->will($this->throwException(new \Exception()))
99+
->willThrowException(new \Exception())
102100
;
103101

104102
$contentRepository = new ContentRepository($this->managerRegistry);
@@ -111,35 +109,30 @@ public function testGetContentIdException()
111109
* Use findById() with two different document managers.
112110
* The two document managers will return different documents when searching for the same id.
113111
*/
114-
public function testChangingDocumentManager()
112+
public function testChangingDocumentManager(): void
115113
{
116114
$this->objectManager
117-
->expects($this->any())
118115
->method('find')
119116
->with(null, 'id-123')
120-
->will($this->returnValue($this->document))
117+
->willReturn($this->document)
121118
;
122119

123120
$this->objectManager2
124-
->expects($this->any())
125121
->method('find')
126122
->with(null, 'id-123')
127-
->will($this->returnValue($this->document2))
123+
->willReturn($this->document2)
128124
;
129125

130126
$objectManagers = [
131127
'default' => $this->objectManager,
132128
'new_manager' => $this->objectManager2,
133129
];
134130
$this->managerRegistry
135-
->expects($this->any())
136131
->method('getManager')
137-
->will(
138-
$this->returnCallback(
139-
function ($name) use ($objectManagers) {
140-
return $objectManagers[$name];
141-
}
142-
)
132+
->willReturnCallback(
133+
function ($name) use ($objectManagers) {
134+
return $objectManagers[$name];
135+
}
143136
);
144137

145138
$contentRepository = new ContentRepository($this->managerRegistry);

tests/Unit/Doctrine/Phpcr/PrefixCandidatesTest.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Unit\Doctrine\Phpcr;
1313

1414
use Doctrine\ODM\PHPCR\DocumentManager;
15-
use Doctrine\ODM\PHPCR\Query\Builder\ConstraintFactory;
15+
use Doctrine\ODM\PHPCR\Query\Builder\ConstraintOrx;
1616
use Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder;
17+
use Doctrine\ODM\PHPCR\Query\Builder\WhereAnd;
1718
use Doctrine\ODM\PHPCR\Translation\LocaleChooser\LocaleChooserInterface;
1819
use Doctrine\Persistence\ManagerRegistry;
1920
use PHPUnit\Framework\TestCase;
@@ -22,7 +23,7 @@
2223

2324
class PrefixCandidatesTest extends TestCase
2425
{
25-
public function testAddPrefix()
26+
public function testAddPrefix(): void
2627
{
2728
$candidates = new PrefixCandidates(['/routes']);
2829
$this->assertEquals(['/routes'], $candidates->getPrefixes());
@@ -32,7 +33,7 @@ public function testAddPrefix()
3233
$this->assertEquals(['/other'], $candidates->getPrefixes());
3334
}
3435

35-
public function testGetCandidates()
36+
public function testGetCandidates(): void
3637
{
3738
$request = Request::create('/my/path.html');
3839

@@ -54,7 +55,7 @@ public function testGetCandidates()
5455
);
5556
}
5657

57-
public function testGetCandidatesPercentEncoded()
58+
public function testGetCandidatesPercentEncoded(): void
5859
{
5960
$request = Request::create('/my/path%20percent%20encoded.html');
6061

@@ -76,7 +77,7 @@ public function testGetCandidatesPercentEncoded()
7677
);
7778
}
7879

79-
public function testGetCandidatesLocales()
80+
public function testGetCandidatesLocales(): void
8081
{
8182
$request = Request::create('/de/path.html');
8283

@@ -102,16 +103,15 @@ public function testGetCandidatesLocales()
102103
);
103104
}
104105

105-
public function testGetCandidatesLocalesDm()
106+
public function testGetCandidatesLocalesDm(): void
106107
{
107108
$request = Request::create('/de/path.html');
108109

109110
$dmMock = $this->createMock(DocumentManager::class);
110111
$managerRegistryMock = $this->createMock(ManagerRegistry::class);
111112
$managerRegistryMock
112-
->expects($this->any())
113113
->method('getManager')
114-
->will($this->returnValue($dmMock))
114+
->willReturn($dmMock)
115115
;
116116
$localeMock = $this->createMock(LocaleChooserInterface::class);
117117
$localeMock
@@ -122,14 +122,14 @@ public function testGetCandidatesLocalesDm()
122122
$dmMock
123123
->expects($this->once())
124124
->method('getLocaleChooserStrategy')
125-
->will($this->returnValue($localeMock))
125+
->willReturn($localeMock)
126126
;
127127

128128
$candidates = new PrefixCandidates(['/simple'], ['de', 'fr'], $managerRegistryMock);
129129
$candidates->getCandidates($request);
130130
}
131131

132-
public function testGetCandidatesLocalesDmNoLocale()
132+
public function testGetCandidatesLocalesDmNoLocale(): void
133133
{
134134
$request = Request::create('/it/path.html');
135135
$managerRegistryMock = $this->createMock(ManagerRegistry::class);
@@ -142,7 +142,7 @@ public function testGetCandidatesLocalesDmNoLocale()
142142
$candidates->getCandidates($request);
143143
}
144144

145-
public function testIsCandidate()
145+
public function testIsCandidate(): void
146146
{
147147
$candidates = new PrefixCandidates(['/routes']);
148148
$this->assertTrue($candidates->isCandidate('/routes'));
@@ -152,33 +152,33 @@ public function testIsCandidate()
152152
$this->assertFalse($candidates->isCandidate('/routesnotsame'));
153153
}
154154

155-
public function testRestrictQuery()
155+
public function testRestrictQuery(): void
156156
{
157-
$orX = $this->createMock(ConstraintFactory::class);
157+
$orX = $this->createMock(ConstraintOrx::class);
158158
$orX->expects($this->once())
159159
->method('descendant')
160160
->with('/routes', 'd')
161161
;
162-
$andWhere = $this->createMock(ConstraintFactory::class);
162+
$andWhere = $this->createMock(WhereAnd::class);
163163
$andWhere->expects($this->once())
164164
->method('orX')
165-
->will($this->returnValue($orX))
165+
->willReturn($orX)
166166
;
167167
$qb = $this->createMock(QueryBuilder::class);
168168
$qb->expects($this->once())
169169
->method('andWhere')
170-
->will($this->returnValue($andWhere))
170+
->willReturn($andWhere)
171171
;
172172
$qb->expects($this->once())
173173
->method('getPrimaryAlias')
174-
->will($this->returnValue('d'))
174+
->willReturn('d')
175175
;
176176

177177
$candidates = new PrefixCandidates(['/routes']);
178178
$candidates->restrictQuery($qb);
179179
}
180180

181-
public function testRestrictQueryGlobal()
181+
public function testRestrictQueryGlobal(): void
182182
{
183183
$qb = $this->createMock(QueryBuilder::class);
184184
$qb->expects($this->never())

0 commit comments

Comments
 (0)