Skip to content

Commit 3f0a6ac

Browse files
committed
upgrade phpunit and get rid of simple-phpunit
1 parent 81646e9 commit 3f0a6ac

File tree

10 files changed

+143
-56
lines changed

10 files changed

+143
-56
lines changed

.github/workflows/test-application.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
steps:
3434
- name: Checkout project
35-
uses: actions/checkout@v4
35+
uses: actions/checkout@v6
3636

3737
- name: Install and configure PHP
3838
uses: shivammathur/setup-php@v2
@@ -47,8 +47,5 @@ jobs:
4747
dependency-versions: ${{ matrix.dependencies }}
4848
composer-options: --prefer-dist
4949

50-
- name: Prepare phpunit
51-
run: vendor/bin/simple-phpunit install
52-
5350
- name: Execute test cases
5451
run: make test

Makefile

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,43 @@ list:
2727
@echo 'functional_tests_phpcr: will run functional tests with PHPCR'
2828
@echo 'functional_tests_orm: will run functional tests with ORM'
2929

30-
include ${TESTING_SCRIPTS_DIR}/make/unit_tests.mk
31-
include ${TESTING_SCRIPTS_DIR}/make/functional_tests_phpcr.mk
32-
include ${TESTING_SCRIPTS_DIR}/make/functional_tests_orm.mk
30+
unit_tests:
31+
@echo
32+
@echo '+++ run unit tests +++'
33+
ifeq ($(HAS_XDEBUG), 0)
34+
@vendor/bin/phpunit --coverage-clover build/logs/clover.xml --testsuite "unit tests"
35+
else
36+
@vendor/bin/phpunit --testsuite "unit tests"
37+
endif
38+
39+
functional_tests_orm:
40+
@if [ "${CONSOLE}" = "" ]; then echo "Console executable missing"; exit 1; fi
41+
@echo
42+
@echo '+++ create ORM database +++'
43+
@${CONSOLE} doctrine:schema:drop --env=orm --force
44+
@${CONSOLE} doctrine:database:create --env=orm || echo "Failed to create database. If this is sqlite, this is normal. Otherwise there will be an error with schema creation"
45+
@${CONSOLE} doctrine:schema:create --env=orm
46+
@echo '+++ run ORM functional tests +++'
47+
ifeq ($(HAS_XDEBUG), 0)
48+
@vendor/bin/phpunit --coverage-clover build/logs/clover.xml --testsuite "functional tests with orm"
49+
else
50+
@vendor/bin/phpunit --testsuite "functional tests with orm"
51+
endif
52+
@${CONSOLE} doctrine:database:drop --force
53+
54+
functional_tests_phpcr:
55+
@if [ "${CONSOLE}" = "" ]; then echo "Console executable missing"; exit 1; fi
56+
@echo
57+
@echo '+++ create PHPCR +++'
58+
@${CONSOLE} doctrine:phpcr:init:dbal --drop --force
59+
@${CONSOLE} doctrine:phpcr:repository:init
60+
@echo '+++ run PHPCR functional tests +++'
61+
ifeq ($(HAS_XDEBUG), 0)
62+
@vendor/bin/phpunit --coverage-clover build/logs/clover.xml --testsuite "functional tests with phpcr"
63+
else
64+
@vendor/bin/phpunit --testsuite "functional tests with phpcr"
65+
endif
66+
@${CONSOLE} doctrine:database:drop --force
3367

3468
.PHONY: test
3569
test: unit_tests functional_tests_phpcr functional_tests_orm

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
"require": {
1818
"php": "^8.1",
1919
"symfony-cmf/routing": "^3.0.3",
20-
"symfony/framework-bundle": "^6.4 || ^7.0"
20+
"symfony/framework-bundle": "^8.0"
2121
},
2222
"require-dev": {
23-
"doctrine/data-fixtures": "^1.0.0",
23+
"doctrine/data-fixtures": "^1.2 || ^2.0",
2424
"doctrine/doctrine-bundle": "^2.8 || ^3.0",
2525
"doctrine/orm": "^2.9 || ^3.0.1 || ^4.0",
26-
"doctrine/phpcr-bundle": "^3.0",
27-
"doctrine/phpcr-odm": "^2.0",
26+
"doctrine/phpcr-bundle": "dev-sf-versions",
27+
"doctrine/phpcr-odm": "^2.0 || ^3.0",
2828
"jackalope/jackalope-doctrine-dbal": "^2.0",
2929
"phpstan/phpstan": "^2.0",
3030
"phpstan/phpstan-doctrine": "^2.0",
3131
"phpstan/phpstan-phpunit": "^2.0",
3232
"phpstan/phpstan-symfony": "^2.0",
33+
"phpunit/phpunit": "^10.5.63 || ^11.5.55 || ^12.5.13 || ^13",
3334
"matthiasnoback/symfony-dependency-injection-test": "^6.3",
3435
"matthiasnoback/symfony-config-test": "^6.2",
35-
"symfony/phpunit-bridge": "^7.0.3 || ^8.0",
3636
"symfony/form": "^6.4 || ^7.0 || ^8.0",
3737
"symfony/monolog-bundle": "^3.5 || ^4.0",
3838
"symfony/security-bundle": "^6.4 || ^7.0 || ^8.0",
@@ -41,7 +41,7 @@
4141
"symfony/validator": "^6.4 || ^7.0 || ^8.0",
4242
"symfony/var-exporter": "^6.4 || ^7.0 || ^8.0",
4343
"symfony/twig-bundle": "^6.4 || ^7.0 || ^8.0",
44-
"symfony-cmf/testing": "5.0.3",
44+
"symfony-cmf/testing": "dev-data-fixtures",
4545
"twig/twig": "^2.4.4 || ^3.0"
4646
},
4747
"suggest": {

tests/Fixtures/App/DataFixtures/Phpcr/LoadRouteData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class LoadRouteData implements FixtureInterface
2323
{
24-
public function load(ObjectManager $manager)
24+
public function load(ObjectManager $manager): void
2525
{
2626
if (!$manager instanceof DocumentManagerInterface) {
2727
throw new \InvalidArgumentException(sprintf('Expected %s, got %s', DocumentManagerInterface::class, get_class($manager)));

tests/Unit/DependencyInjection/CmfRoutingExtensionTest.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Bundle\PHPCRBundle\Initializer\GenericInitializer;
1515
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
16+
use PHPUnit\Framework\Attributes\DataProvider;
1617
use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\CmfRoutingExtension;
1718
use Symfony\Cmf\Component\Routing\ChainRouter;
1819
use Symfony\Component\DependencyInjection\Reference;
@@ -130,9 +131,7 @@ public function testWhitespaceInPriorities(): void
130131
);
131132
}
132133

133-
/**
134-
* @dataProvider getBasePathsTests
135-
*/
134+
#[DataProvider('getBasePathsTests')]
136135
public function testLoadBasePaths(array $phpcrConfig, array $routeBasepathsParameter): void
137136
{
138137
$this->container->setParameter(
@@ -163,7 +162,7 @@ public function testLoadBasePaths(array $phpcrConfig, array $routeBasepathsParam
163162
);
164163
}
165164

166-
public function getBasePathsTests(): array
165+
public static function getBasePathsTests(): array
167166
{
168167
return [
169168
[
@@ -188,9 +187,7 @@ public function getBasePathsTests(): array
188187
];
189188
}
190189

191-
/**
192-
* @dataProvider getBasePathsMergingTests
193-
*/
190+
#[DataProvider('getBasePathsMergingTests')]
194191
public function testRouteBasepathsMerging(array $phpcrConfig1, array $phpcrConfig2, array $routeBasepathsParameter): void
195192
{
196193
$this->container->setParameter(
@@ -232,28 +229,25 @@ public function testRouteBasepathsMerging(array $phpcrConfig1, array $phpcrConfi
232229
);
233230
}
234231

235-
public function getBasePathsMergingTests(): array
232+
public static function getBasePathsMergingTests(): array
236233
{
237234
return [
238235
[
239236
['route_basepaths' => ['/cms/test']],
240237
['route_basepaths' => ['/cms/test2']],
241238
['/cms/test', '/cms/test2'],
242-
'/cms/test',
243239
],
244240

245241
[
246242
['route_basepaths' => ['/cms/test']],
247243
['route_basepaths' => ['/cms/test2', '/cms/test3']],
248244
['/cms/test', '/cms/test2', '/cms/test3'],
249-
'/cms/test',
250245
],
251246

252247
[
253248
[],
254249
['route_basepaths' => ['/cms/test']],
255250
['/cms/test'],
256-
'/cms/test',
257251
],
258252
];
259253
}

tests/Unit/DependencyInjection/Compiler/ValidationPassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Unit\DependencyInjection\Compiler;
1313

1414
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
15+
use PHPUnit\Framework\Attributes\DataProvider;
1516
use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\Compiler\ValidationPass;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718

@@ -26,9 +27,8 @@ protected function registerCompilerPass(ContainerBuilder $container): void
2627
* It should register the PHPCR documents for validation only when:
2728
* - the PHP backend is enabled AND
2829
* - the validator service is available.
29-
*
30-
* @dataProvider provideDocumentsValidationContext
3130
*/
31+
#[DataProvider('provideDocumentsValidationContext')]
3232
public function testRegisterDocumentsValidation(bool $hasPhpcr, bool $hasValidator, bool $shouldBeRegistered): void
3333
{
3434
if ($hasPhpcr) {
@@ -71,7 +71,7 @@ public function testRegisterDocumentsValidation(bool $hasPhpcr, bool $hasValidat
7171
* - _$hasValidator: Is the validator available ?
7272
* - _$shouldBeRegistered_: Should the documents validation be registered ?
7373
*/
74-
public function provideDocumentsValidationContext(): array
74+
public static function provideDocumentsValidationContext(): array
7575
{
7676
return [
7777
[true, true, true],

tests/Unit/Doctrine/Orm/ContentRepositoryTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\Persistence\ManagerRegistry;
1515
use Doctrine\Persistence\ObjectManager;
1616
use Doctrine\Persistence\ObjectRepository;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1718
use PHPUnit\Framework\MockObject\MockObject;
1819
use PHPUnit\Framework\TestCase;
1920
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\ContentRepository;
@@ -60,9 +61,7 @@ public function testFindById(): void
6061
$this->assertSame($this->document, $foundDocument);
6162
}
6263

63-
/**
64-
* @dataProvider getFindCorrectModelAndIdData
65-
*/
64+
#[DataProvider('getFindCorrectModelAndIdData')]
6665
public function testFindCorrectModelAndId($input, $model, $id): void
6766
{
6867
$this->objectManager
@@ -89,7 +88,7 @@ public function testFindCorrectModelAndId($input, $model, $id): void
8988
$this->assertSame($this, $foundDocument);
9089
}
9190

92-
public function getFindCorrectModelAndIdData(): array
91+
public static function getFindCorrectModelAndIdData(): array
9392
{
9493
return [
9594
['Acme\ContentBundle\Entity\Content:12', 'Acme\ContentBundle\Entity\Content', 12],

tests/Unit/Doctrine/Orm/RouteProviderTest.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ protected function setUp(): void
3939
$this->managerRegistryMock = $this->createMock(ManagerRegistry::class);
4040
$this->objectRepositoryMock = $this->getMockBuilder(EntityRepository::class)
4141
->disableOriginalConstructor()
42-
->onlyMethods(['findOneBy', 'findBy'])
43-
->addMethods(['findByStaticPrefix'])
42+
->onlyMethods(['findOneBy', 'findBy', '__call'])
4443
->getMock();
4544
$this->candidatesMock = $this->createMock(CandidatesInterface::class);
4645
$this->candidatesMock
@@ -88,8 +87,8 @@ public function testGetRouteCollectionForRequest(): void
8887

8988
$this->objectRepositoryMock
9089
->expects($this->once())
91-
->method('findByStaticPrefix')
92-
->with($candidates, ['position' => 'ASC'])
90+
->method('__call')
91+
->with('findByStaticPrefix', [$candidates, ['position' => 'ASC']])
9392
->willReturn($objects)
9493
;
9594

@@ -111,7 +110,7 @@ public function testGetRouteCollectionForRequestEmpty(): void
111110

112111
$this->objectRepositoryMock
113112
->expects($this->never())
114-
->method('findByStaticPrefix')
113+
->method('__call')
115114
;
116115

117116
$routeProvider = new RouteProvider($this->managerRegistryMock, $this->candidatesMock, 'Route');
@@ -187,9 +186,24 @@ public function testGetRoutesByNames(): void
187186

188187
$candidatesMock = $this->createMock(CandidatesInterface::class);
189188
$candidatesMock
189+
->expects($this->exactly(3))
190190
->method('isCandidate')
191-
->withConsecutive([$paths[0]], [$paths[1]], [$paths[2]])
192-
->willReturnOnConsecutiveCalls(true, true, false)
191+
->willReturnCallback(function (string $path) use ($paths): bool {
192+
static $expectedCalls = [];
193+
194+
if ([] === $expectedCalls) {
195+
$expectedCalls = [
196+
[$paths[0], true],
197+
[$paths[1], true],
198+
[$paths[2], false],
199+
];
200+
}
201+
202+
[$expectedPath, $returnValue] = array_shift($expectedCalls);
203+
$this->assertSame($expectedPath, $path);
204+
205+
return $returnValue;
206+
})
193207
;
194208

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

tests/Unit/Doctrine/Phpcr/RouteProviderTest.php

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,21 @@ public function testGetRoutesByNames(): void
303303
;
304304

305305
$this->candidatesMock
306+
->expects($this->exactly(4))
306307
->method('isCandidate')
307-
->withConsecutive(['/cms/routes/test-route'], ['/cms/simple/other-route'], ['/cms/routes/not-a-route'], ['/outside/prefix'])
308-
->willReturnOnConsecutiveCalls(true, true, true, false)
308+
->willReturnCallback(function (string $path): bool {
309+
static $expectedCalls = [
310+
['/cms/routes/test-route', true],
311+
['/cms/simple/other-route', true],
312+
['/cms/routes/not-a-route', true],
313+
['/outside/prefix', false],
314+
];
315+
316+
[$expectedPath, $returnValue] = array_shift($expectedCalls);
317+
$this->assertSame($expectedPath, $path);
318+
319+
return $returnValue;
320+
})
309321
;
310322

311323
$paths[] = '/outside/prefix';
@@ -331,9 +343,19 @@ public function testGetRoutesByNamesNotCandidates(): void
331343
;
332344

333345
$this->candidatesMock
346+
->expects($this->exactly(3))
334347
->method('isCandidate')
335-
->withConsecutive(['/cms/routes/test-route'], ['/cms/simple/other-route'], ['/cms/routes/not-a-route'])
336-
->willReturn(false)
348+
->willReturnCallback(function (string $path): bool {
349+
static $expectedCalls = [
350+
'/cms/routes/test-route',
351+
'/cms/simple/other-route',
352+
'/cms/routes/not-a-route',
353+
];
354+
355+
$this->assertSame(array_shift($expectedCalls), $path);
356+
357+
return false;
358+
})
337359
;
338360

339361
$routeProvider = new RouteProvider($this->managerRegistryMock, $this->candidatesMock);
@@ -373,15 +395,39 @@ public function testGetRoutesByNamesUuid(): void
373395
->willReturn($uow)
374396
;
375397
$uow
398+
->expects($this->exactly(2))
376399
->method('getDocumentId')
377-
->withConsecutive([$route1], [$route2])
378-
->willReturnOnConsecutiveCalls('/cms/routes/test-route', '/cms/routes/other-route')
400+
->willReturnCallback(function ($route) use ($route1, $route2): string {
401+
static $expectedCalls = [];
402+
403+
if ([] === $expectedCalls) {
404+
$expectedCalls = [
405+
[$route1, '/cms/routes/test-route'],
406+
[$route2, '/cms/routes/other-route'],
407+
];
408+
}
409+
410+
[$expectedRoute, $returnValue] = array_shift($expectedCalls);
411+
$this->assertSame($expectedRoute, $route);
412+
413+
return $returnValue;
414+
})
379415
;
380416

381417
$this->candidatesMock
418+
->expects($this->exactly(2))
382419
->method('isCandidate')
383-
->withConsecutive(['/cms/routes/test-route'], ['/cms/routes/other-route'])
384-
->willReturnOnConsecutiveCalls(true, false)
420+
->willReturnCallback(function (string $path): bool {
421+
static $expectedCalls = [
422+
['/cms/routes/test-route', true],
423+
['/cms/routes/other-route', false],
424+
];
425+
426+
[$expectedPath, $returnValue] = array_shift($expectedCalls);
427+
$this->assertSame($expectedPath, $path);
428+
429+
return $returnValue;
430+
})
385431
;
386432

387433
$routeProvider = new RouteProvider($this->managerRegistryMock, $this->candidatesMock);

0 commit comments

Comments
 (0)