Skip to content

Commit 39422a1

Browse files
committed
Upgrade PHPUnit 10
1 parent ab45e12 commit 39422a1

28 files changed

+133
-125
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.php-cs-fixer.cache
2-
.phpunit.result.cache
2+
.phpunit.cache/
33
composer.lock
44
/composer-require-checker.phar
55
/drivers/

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
'@DoctrineAnnotation' => true,
2424
'@PHP81Migration' => true,
2525
'@PHP80Migration:risky' => true,
26-
'@PHPUnit84Migration:risky' => true,
26+
'@PHPUnit100Migration:risky' => true,
2727
'array_syntax' => ['syntax' => 'short'],
2828
'fopen_flags' => true,
2929
'header_comment' => ['header' => $fileHeaderComment, 'separate' => 'both'],

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
"doctrine/data-fixtures": "^1.5.3|^2.0",
5454
"doctrine/doctrine-fixtures-bundle": "^3.4.2|^4.0",
5555
"friendsofphp/php-cs-fixer": "^3.0",
56-
"phpunit/phpunit": "^9.0",
56+
"phpunit/phpunit": "^10.0",
5757
"symfony/dom-crawler": "^6.4|^7.4|^8.0",
58-
"symfony/panther": "^2.0.1",
58+
"symfony/panther": "^2.3",
5959
"symfony/webpack-encore-bundle": "^1.7.3|^2.4",
6060
"symfony/yaml": "^6.4|^7.4|^8.0",
6161
"vimeo/psalm": "^5.0"

phpunit.xml.dist

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
4-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.0/phpunit.xsd"
6-
backupGlobals="false"
7-
colors="true"
8-
beStrictAboutTestsThatDoNotTestAnything="false"
9-
bootstrap="tests/bootstrap.php"
10-
>
11-
<php>
12-
<env name="KERNEL_CLASS" value="Ecommit\CrudBundle\Tests\Functional\App\Kernel" />
13-
<env name="APP_ENV" value="test"/>
14-
<server name="PANTHER_WEB_SERVER_DIR" value="./tests/Functional/App/public" />
15-
<ini name="intl.default_locale" value="en" />
16-
</php>
17-
18-
<extensions>
19-
<extension class="Symfony\Component\Panther\ServerExtension" />
20-
</extensions>
21-
22-
<testsuites>
23-
<testsuite name="Project Test Suite">
24-
<directory>tests</directory>
25-
</testsuite>
26-
</testsuites>
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" colors="true" beStrictAboutTestsThatDoNotTestAnything="false" bootstrap="tests/bootstrap.php" cacheDirectory=".phpunit.cache">
4+
<php>
5+
<env name="KERNEL_CLASS" value="Ecommit\CrudBundle\Tests\Functional\App\Kernel"/>
6+
<env name="APP_ENV" value="test"/>
7+
<server name="PANTHER_WEB_SERVER_DIR" value="./tests/Functional/App/public"/>
8+
<ini name="intl.default_locale" value="en"/>
9+
</php>
10+
<extensions>
11+
<bootstrap class="Symfony\Component\Panther\ServerExtension"/>
12+
</extensions>
13+
<testsuites>
14+
<testsuite name="Project Test Suite">
15+
<directory>tests</directory>
16+
</testsuite>
17+
</testsuites>
2718
</phpunit>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use Symfony\Component\HttpFoundation\RequestStack;
2727
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2828

29-
abstract class AbstractCrudTest extends KernelTestCase
29+
abstract class AbstractCrudTestCase extends KernelTestCase
3030
{
3131
protected function setUp(): void
3232
{

tests/Crud/CrudColumnTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function testGetAliasSearch(): void
140140
$this->assertSame('val', $crudColumn->getAliasSearch());
141141
}
142142

143-
public function getBooleanProvier(): array
143+
public static function getBooleanProvier(): array
144144
{
145145
return [[true], [false]];
146146
}

tests/Crud/CrudConfigTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function testResetOptions(mixed $value, array $expected): void
182182
$this->assertSame($expected, $config->getOptions());
183183
}
184184

185-
public function getTestResetOptionsProvider(): array
185+
public static function getTestResetOptionsProvider(): array
186186
{
187187
return [
188188
[null, []],
@@ -203,7 +203,7 @@ public function testOffsetExists(string $offset, bool $expected): void
203203
$this->assertSame($expected, $config->offsetExists($offset));
204204
}
205205

206-
public function getTestOffsetExistsProvider(): array
206+
public static function getTestOffsetExistsProvider(): array
207207
{
208208
return [
209209
['session_name', true],

tests/Crud/CrudFiltersTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testHas(string $filter, $expected): void
3535
$this->assertSame($expected, $this->crudFilters->has($filter));
3636
}
3737

38-
public function getTestHasProvider(): array
38+
public static function getTestHasProvider(): array
3939
{
4040
return [
4141
['filter_1', true],

tests/Crud/CrudTest.php

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
3131
use Symfony\Component\Validator\Exception\ValidationFailedException;
3232

33-
class CrudTest extends AbstractCrudTest
33+
class CrudTest extends AbstractCrudTestCase
3434
{
3535
/**
3636
* @dataProvider getTestCrudWithInvalidSessionNameProvider
@@ -45,7 +45,7 @@ public function testCrudWithInvalidSessionName(mixed $sessionName, string $expec
4545
$this->createCrud($crudOptions);
4646
}
4747

48-
public function getTestCrudWithInvalidSessionNameProvider(): array
48+
public static function getTestCrudWithInvalidSessionNameProvider(): array
4949
{
5050
return [
5151
['', InvalidOptionsException::class, '/The option "session_name" with value ".*" is invalid/'],
@@ -118,7 +118,7 @@ public function testAddColumnAlreadyExists(callable $callback): void
118118
$this->createCrud($crudConfig);
119119
}
120120

121-
public function getTestAddColumnAlreadyExistsProvider(): array
121+
public static function getTestAddColumnAlreadyExistsProvider(): array
122122
{
123123
return [
124124
[static function (CrudConfig $crudConfig): void {
@@ -249,20 +249,22 @@ public function testGetVirtualColumnNotExists(): void
249249
/**
250250
* @dataProvider getTestQueryBuilderProvider
251251
*/
252-
public function testQueryBuilder(mixed $queryBuilder): void
252+
public function testQueryBuilder(\Closure $queryBuilderFactory): void
253253
{
254+
$queryBuilder = $queryBuilderFactory($this);
255+
254256
$crudConfig = $this->createValidCrudConfig()
255257
->setQueryBuilder($queryBuilder);
256258
$crud = $this->createCrud($crudConfig);
257259
$this->assertSame($queryBuilder, $crud->getQueryBuilder());
258260
}
259261

260-
public function getTestQueryBuilderProvider(): array
262+
public static function getTestQueryBuilderProvider(): array
261263
{
262264
return [
263-
[$this->createMock(\Doctrine\ORM\QueryBuilder::class)],
264-
[$this->createMock(\Doctrine\DBAL\Query\QueryBuilder::class)],
265-
[$this->createMock(\Ecommit\CrudBundle\Crud\QueryBuilderInterface::class)],
265+
[static fn (self $testCase) => $testCase->createMock(\Doctrine\ORM\QueryBuilder::class)],
266+
[static fn (self $testCase) => $testCase->createMock(\Doctrine\DBAL\Query\QueryBuilder::class)],
267+
[static fn (self $testCase) => $testCase->createMock(\Ecommit\CrudBundle\Crud\QueryBuilderInterface::class)],
266268
];
267269
}
268270

@@ -771,7 +773,7 @@ public function testRequiredOptions(string $option): void
771773
$this->createCrud($crudConfig);
772774
}
773775

774-
public function getTestRequiredOptionsProvider(): array
776+
public static function getTestRequiredOptionsProvider(): array
775777
{
776778
return [
777779
['session_name'],
@@ -873,7 +875,7 @@ public function testChangeColumnsDisplayedWithBadValue(array $value): void
873875
$this->assertSame(['firstName'], $crud->getSessionValues()->getDisplayedColumns());
874876
}
875877

876-
public function getTestChangeColumnsDisplayedWithBadValueProvider(): array
878+
public static function getTestChangeColumnsDisplayedWithBadValueProvider(): array
877879
{
878880
return [
879881
[['bad_column']],
@@ -906,7 +908,7 @@ public function testChangeSortWithBadValue(mixed $value): void
906908
$this->assertSame('username', $crud->getSessionValues()->getSort());
907909
}
908910

909-
public function getTestChangeSortWithBadValueProvider(): array
911+
public static function getTestChangeSortWithBadValueProvider(): array
910912
{
911913
return [
912914
[null],
@@ -944,7 +946,7 @@ public function testChangeSortPersonalizedSortWithBadValue(mixed $value): void
944946
$this->assertSame('defaultPersonalizedSort', $crud->getSessionValues()->getSort());
945947
}
946948

947-
public function getTestChangeSortPersonalizedSortWithBadValueProvider(): array
949+
public static function getTestChangeSortPersonalizedSortWithBadValueProvider(): array
948950
{
949951
return [
950952
[null],
@@ -977,7 +979,7 @@ public function testChangeSortDirectionWithBadValue(mixed $value): void
977979
$this->assertSame(Crud::DESC, $crud->getSessionValues()->getSortDirection());
978980
}
979981

980-
public function getTestChangeSortDirectionWithBadValueProvider(): array
982+
public static function getTestChangeSortDirectionWithBadValueProvider(): array
981983
{
982984
return [
983985
[null],
@@ -1002,8 +1004,9 @@ public function testChangeSearchFormData(): void
10021004
/**
10031005
* @dataProvider getTestChangeSearchFormDataWithBadValueProvider
10041006
*/
1005-
public function testChangeSearchFormDataWithBadValue(?SearcherInterface $value): void
1007+
public function testChangeSearchFormDataWithBadValue(\Closure $valueFactory): void
10061008
{
1009+
$value = $valueFactory($this);
10071010
$crud = $this->createCrud($this->createValidCrudConfig(withSearcher: true));
10081011

10091012
$reflectionMethod = (new \ReflectionClass($crud))->getMethod('changeSearchFormData');
@@ -1013,11 +1016,11 @@ public function testChangeSearchFormDataWithBadValue(?SearcherInterface $value):
10131016
$this->assertEquals(new UserSearcher(), $crud->getSessionValues()->getSearchFormData());
10141017
}
10151018

1016-
public function getTestChangeSearchFormDataWithBadValueProvider(): array
1019+
public static function getTestChangeSearchFormDataWithBadValueProvider(): array
10171020
{
10181021
return [
1019-
[null],
1020-
[$this->createMock(SearcherInterface::class)],
1022+
[static fn (self $self) => null],
1023+
[static fn (self $self) => $self->createMock(SearcherInterface::class)],
10211024
];
10221025
}
10231026

@@ -1031,7 +1034,7 @@ public function testChangeSearchFormDataWithoutSearchForm(): void
10311034
$this->assertNull($crud->getSessionValues()->getSearchFormData());
10321035
}
10331036

1034-
public function getBoolProvider(): array
1037+
public static function getBoolProvider(): array
10351038
{
10361039
return [
10371040
[true],

tests/Crud/SearchFormBuilderTest.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
use Symfony\Component\Form\FormInterface;
2828
use Symfony\Component\Form\FormView;
2929

30-
class SearchFormBuilderTest extends AbstractCrudTest
30+
class SearchFormBuilderTest extends AbstractCrudTestCase
3131
{
3232
/**
3333
* @dataProvider getTestCreateFormBuilderProvider
@@ -39,7 +39,7 @@ public function testCreateFormBuilder(?string $type, string $expectedName, strin
3939
$this->assertInstanceOf($expectedType, $searchFormBuilder->getFormBuilder()->getFormConfig()->getType()->getInnerType());
4040
}
4141

42-
public function getTestCreateFormBuilderProvider(): array
42+
public static function getTestCreateFormBuilderProvider(): array
4343
{
4444
return [
4545
[null, 'crud_search_session_name', FormSearchType::class],
@@ -214,10 +214,17 @@ public function testCreateForm(): void
214214
public function testCreateFormWithDefaultColumnId(): void
215215
{
216216
$filter = $this->createMock(FilterInterface::class);
217-
$filter->expects($this->exactly(2))->method('buildForm')->withConsecutive(
218-
[self::callback(static fn ($value): bool => $value instanceof SearchFormBuilder), 'column1', self::callback(static fn ($value): bool => \is_array($value))],
219-
[self::callback(static fn ($value): bool => $value instanceof SearchFormBuilder), 'virtual1', self::callback(static fn ($value): bool => \is_array($value))],
220-
);
217+
$invokedCount = 0;
218+
$filter->expects($this->exactly(2))->method('buildForm')->willReturnCallback(static function ($searchFormBuilder, $property, $options) use (&$invokedCount): void {
219+
self::assertInstanceOf(SearchFormBuilder::class, $searchFormBuilder);
220+
if (0 === $invokedCount) {
221+
self::assertSame('column1', $property);
222+
} elseif (1 === $invokedCount) {
223+
self::assertSame('virtual1', $property);
224+
}
225+
++$invokedCount;
226+
self::assertIsArray($options);
227+
});
221228
$crudConfig = $this->createValidCrudConfig()
222229
->addColumn(['id' => 'column1', 'alias' => 'alias1'])
223230
->addVirtualColumn(['id' => 'virtual1', 'alias' => 'alias1']);
@@ -231,10 +238,17 @@ public function testCreateFormWithDefaultColumnId(): void
231238
public function testCreateFormWithColumnIdOption(): void
232239
{
233240
$filter = $this->createMock(FilterInterface::class);
234-
$filter->expects($this->exactly(2))->method('buildForm')->withConsecutive(
235-
[self::callback(static fn ($value): bool => $value instanceof SearchFormBuilder), 'property1', self::callback(static fn ($value): bool => \is_array($value))],
236-
[self::callback(static fn ($value): bool => $value instanceof SearchFormBuilder), 'property2', self::callback(static fn ($value): bool => \is_array($value))],
237-
);
241+
$invokedCount = 0;
242+
$filter->expects($this->exactly(2))->method('buildForm')->willReturnCallback(static function ($searchFormBuilder, $property, $options) use (&$invokedCount): void {
243+
self::assertInstanceOf(SearchFormBuilder::class, $searchFormBuilder);
244+
if (0 === $invokedCount) {
245+
self::assertSame('property1', $property);
246+
} elseif (1 === $invokedCount) {
247+
self::assertSame('property2', $property);
248+
}
249+
++$invokedCount;
250+
self::assertIsArray($options);
251+
});
238252
$crudConfig = $this->createValidCrudConfig()
239253
->addColumn(['id' => 'column1', 'alias' => 'alias1'])
240254
->addVirtualColumn(['id' => 'virtual1', 'alias' => 'alias1']);

0 commit comments

Comments
 (0)