Skip to content

Commit

Permalink
test: compatibility with PHPUnit 10 (#5701)
Browse files Browse the repository at this point in the history
* test: compatibility with PHPUnit 10

* fix

* another fix

* one more fix

* fix

* try again

* again

* fixed locally

* clean composer.json
  • Loading branch information
dunglas committed Jul 26, 2023
1 parent 8407875 commit f0698a4
Show file tree
Hide file tree
Showing 109 changed files with 943 additions and 806 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ jobs:
- name: Clear test app cache
run: tests/Fixtures/app/console cache:clear --ansi
- name: Run PHPUnit tests
run: vendor/bin/simple-phpunit
# The PHPUnit Bridge doesn't support PHPUnit 10 yet: https://github.com/symfony/symfony/issues/49069
run: vendor/bin/phpunit -c phpunit10.xml.dist

behat-symfony-next:
name: Behat (PHP ${{ matrix.php }}) (Symfony dev)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.php-cs-fixer.php
/.php-cs-fixer.cache
/.phpunit.result.cache
/.phpunit.cache/
/build/
/composer.lock
/composer.phar
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Both `simple-phpunit` and `behat` are development dependencies and should be ava

To launch unit tests:

vendor/bin/simple-phpunit --stop-on-failure -vvv
vendor/bin/simple-phpunit --stop-on-defect -vvv

If you want coverage, you will need the `pcov` PHP extension and run:

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"require-dev": {
"behat/behat": "^3.1",
"behat/mink": "^1.9@dev",
"behat/mink": "^1.9",
"doctrine/cache": "^1.11 || ^2.1",
"doctrine/common": "^3.2.2",
"doctrine/data-fixtures": "^1.2.2",
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" bootstrap="tests/Fixtures/app/bootstrap.php" colors="true">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" backupGlobals="false" bootstrap="tests/Fixtures/app/bootstrap.php" colors="true">
<php>
<ini name="error_reporting" value="-1" />
<ini name="memory_limit" value="-1" />
Expand Down
38 changes: 38 additions & 0 deletions phpunit10.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" backupGlobals="false" bootstrap="tests/Fixtures/app/bootstrap.php" colors="true" cacheDirectory=".phpunit.cache">
<php>
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="-1"/>
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=0&amp;ignoreFile=./tests/.ignored-deprecations"/>
<!-- This is necessary for GitHub Actions to work properly -->
<server name="SYMFONY_PHPUNIT_DIR" value="vendor/bin/.phpunit"/>
<server name="SYMFONY_PHPUNIT_REMOVE" value="symfony/yaml"/>
<server name="KERNEL_DIR" value="tests/Fixtures/app/"/>
<server name="KERNEL_CLASS" value="AppKernel"/>
<env name="APP_ENV" value="test"/>
</php>

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<groups>
<exclude>
<group>mongodb</group>
</exclude>
</groups>

<source>
<include>
<directory>.</directory>
</include>
<exclude>
<directory>features</directory>
<directory>tests</directory>
<directory>vendor</directory>
<file>.php-cs-fixer.dist.php</file>
</exclude>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions src/JsonSchema/Tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testCollectionJsonSchemaVersion(string $version, string $ref): v
$this->assertSame('Foo', $schema->getItemsDefinitionKey());
}

public function versionProvider(): iterable
public static function versionProvider(): iterable
{
yield [Schema::VERSION_JSON_SCHEMA, '#/definitions/Foo'];
yield [Schema::VERSION_SWAGGER, '#/definitions/Foo'];
Expand Down Expand Up @@ -85,7 +85,7 @@ public function testDefinitions(string $version, array $baseDefinitions): void
$this->assertArrayNotHasKey('components', $schema->getArrayCopy(false));
}

public function definitionsDataProvider(): iterable
public static function definitionsDataProvider(): iterable
{
yield [Schema::VERSION_OPENAPI, ['foo' => []]];
yield [Schema::VERSION_JSON_SCHEMA, ['foo' => []]];
Expand Down
22 changes: 12 additions & 10 deletions src/JsonSchema/Tests/TypeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testGetType(array $schema, Type $type): void
$this->assertEquals($schema, $typeFactory->getType($type, 'json', null, null, new Schema(Schema::VERSION_OPENAPI)));
}

public function typeProvider(): iterable
public static function typeProvider(): iterable
{
yield [['type' => 'integer'], new Type(Type::BUILTIN_TYPE_INT)];
yield [['nullable' => true, 'type' => 'integer'], new Type(Type::BUILTIN_TYPE_INT, true)];
Expand Down Expand Up @@ -169,7 +169,7 @@ public function testGetTypeWithJsonSchemaSyntax(array $schema, Type $type): void
$this->assertEquals($schema, $typeFactory->getType($type, 'json', null, null, new Schema(Schema::VERSION_JSON_SCHEMA)));
}

public function jsonSchemaTypeProvider(): iterable
public static function jsonSchemaTypeProvider(): iterable
{
yield [['type' => 'integer'], new Type(Type::BUILTIN_TYPE_INT)];
yield [['type' => ['integer', 'null']], new Type(Type::BUILTIN_TYPE_INT, true)];
Expand Down Expand Up @@ -290,7 +290,7 @@ public function testGetTypeWithOpenAPIV2Syntax(array $schema, Type $type): void
$this->assertEquals($schema, $typeFactory->getType($type, 'json', null, null, new Schema(Schema::VERSION_SWAGGER)));
}

public function openAPIV2TypeProvider(): iterable
public static function openAPIV2TypeProvider(): iterable
{
yield [['type' => 'integer'], new Type(Type::BUILTIN_TYPE_INT)];
yield [['type' => 'integer'], new Type(Type::BUILTIN_TYPE_INT, true)];
Expand Down Expand Up @@ -412,20 +412,21 @@ public function testGetClassType(): void
}

/** @dataProvider classTypeWithNullabilityDataProvider */
public function testGetClassTypeWithNullability(array $expected, SchemaFactoryInterface $schemaFactory, Schema $schema): void
public function testGetClassTypeWithNullability(array $expected, callable $schemaFactoryFactory, Schema $schema): void
{
$typeFactory = new TypeFactory();
$typeFactory->setSchemaFactory($schemaFactory);
$typeFactory->setSchemaFactory($schemaFactoryFactory($this));

self::assertEquals(
$expected,
$typeFactory->getType(new Type(Type::BUILTIN_TYPE_OBJECT, true, Dummy::class), 'jsonld', true, ['foo' => 'bar'], $schema)
);
}

public function classTypeWithNullabilityDataProvider(): iterable
public static function classTypeWithNullabilityDataProvider(): iterable
{
$schemaFactory = $this->createSchemaFactoryMock($schema = new Schema());
$schema = new Schema();
$schemaFactoryFactory = fn (self $that): SchemaFactoryInterface => $that->createSchemaFactoryMock($schema);

yield 'JSON-Schema version' => [
[
Expand All @@ -434,11 +435,12 @@ public function classTypeWithNullabilityDataProvider(): iterable
['type' => 'null'],
],
],
$schemaFactory,
$schemaFactoryFactory,
$schema,
];

$schemaFactory = $this->createSchemaFactoryMock($schema = new Schema(Schema::VERSION_OPENAPI));
$schema = new Schema(Schema::VERSION_OPENAPI);
$schemaFactoryFactory = fn (self $that): SchemaFactoryInterface => $that->createSchemaFactoryMock($schema);

yield 'OpenAPI < 3.1 version' => [
[
Expand All @@ -447,7 +449,7 @@ public function classTypeWithNullabilityDataProvider(): iterable
],
'nullable' => true,
],
$schemaFactory,
$schemaFactoryFactory,
$schema,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testValidMetadata(string $extractorClass, PropertyAdapterInterfa
$this->assertEquals($this->buildApiProperty(), $property);
}

public function getExtractors(): array
public static function getExtractors(): array
{
return [
[XmlPropertyExtractor::class, new XmlPropertyAdapter()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public function testValidMetadata(string $extractorClass, ResourceAdapterInterfa
$this->assertEquals(new ResourceMetadataCollection(self::RESOURCE_CLASS, $this->buildApiResources()), $collection);
}

public function getExtractors(): array
public static function getExtractors(): array
{
return [
[XmlResourceExtractor::class, new XmlResourceAdapter()],
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Tests/Extractor/XmlExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public function testInvalidXML(string $path, string $error): void
(new XmlResourceExtractor([$path]))->getResources();
}

public function getInvalidPaths(): array
public static function getInvalidPaths(): array
{
return [
[
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Tests/Extractor/YamlExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ public function testInvalidYaml(string $path, string $error): void
(new YamlResourceExtractor([$path]))->getResources();
}

public function getInvalidPaths(): array
public static function getInvalidPaths(): array
{
return [
[__DIR__.'/yaml/invalid/invalid_resources.yaml', '"resources" setting is expected to be null or an array, string given in "'.__DIR__.'/yaml/invalid/invalid_resources.yaml".'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SerializerPropertyMetadataFactoryTest extends TestCase
{
use ProphecyTrait;

public function groupsProvider(): array
public static function groupsProvider(): array
{
return [
[['dummy_read'], ['dummy_write']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testCreate(ApiResource $previous, ApiResource $expected, array $
$this->assertEquals($expected, $actual);
}

public function createProvider(): iterable
public static function createProvider(): iterable
{
yield [
new ApiResource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testInputOutputMetadata(mixed $input, ?array $expected): void
$this->assertSame($expected, $factory->create('Foo')[0]->getInput());
}

public function getAttributes(): array
public static function getAttributes(): array
{
return [
// no input class defined
Expand Down
4 changes: 2 additions & 2 deletions src/Metadata/Tests/Resource/Factory/LinkFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testCreateLinksFromIdentifiers(array $propertyNames, bool $compo
);
}

public function provideCreateLinksFromIdentifiersCases(): \Generator
public static function provideCreateLinksFromIdentifiersCases(): \Generator
{
yield 'no identifiers no id' => [
['slug'],
Expand Down Expand Up @@ -111,7 +111,7 @@ public function testCreateLinksFromAttributes(array $builtinTypes, array $expect
);
}

public function provideCreateLinksFromAttributesCases(): \Generator
public static function provideCreateLinksFromAttributesCases(): \Generator
{
yield 'no builtin types' => [
[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testGeneratesName(Operation $operation, string $expectedOperatio
$this->assertEquals($operation->withName($expectedOperationName), $result->getOperation($expectedOperationName));
}

public function operationProvider(): array
public static function operationProvider(): array
{
return [
[new Get(), '_api_a_get'],
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Tests/Resource/OperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testOperationConstructor(Operation $operation): void
$this->assertInstanceOf(Operation::class, $operation);
}

public function operationProvider(): \Generator
public static function operationProvider(): \Generator
{
$args = [];

Expand Down
12 changes: 3 additions & 9 deletions src/Test/DoctrineMongoDbOdmFilterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,15 @@ public function testApply(?array $properties, array $filterParameters, array $ex

protected function doTestApply(?array $properties, array $filterParameters, array $expectedPipeline, callable $filterFactory = null, string $resourceClass = null): void
{
if (null === $filterFactory) {
$filterFactory = function (ManagerRegistry $managerRegistry, array $properties = null): FilterInterface {
$filterClass = $this->filterClass;

return new $filterClass($managerRegistry, null, $properties);
};
}
$filterFactory ??= fn (self $that, ManagerRegistry $managerRegistry, array $properties = null): FilterInterface => new ($this->filterClass)($managerRegistry, null, $properties);

$repository = $this->repository;
if ($resourceClass) {
$repository = $this->manager->getRepository($resourceClass);
}
$resourceClass = $resourceClass ?: $this->resourceClass;
$aggregationBuilder = $repository->createAggregationBuilder();
$filterCallable = $filterFactory($this->managerRegistry, $properties);
$filterCallable = $filterFactory($this, $this->managerRegistry, $properties);
$context = ['filters' => $filterParameters];
$filterCallable->apply($aggregationBuilder, $resourceClass, null, $context);
$pipeline = [];
Expand All @@ -86,5 +80,5 @@ protected function buildFilter(array $properties = null)
return new $this->filterClass($this->managerRegistry, null, $properties);
}

abstract public function provideApplyTestData(): array;
abstract public static function provideApplyTestData(): array;
}
14 changes: 5 additions & 9 deletions src/Test/DoctrineOrmFilterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class DoctrineOrmFilterTestCase extends KernelTestCase

protected string $resourceClass = Dummy::class;

protected string $alias = 'o';
protected const ALIAS = 'o';

protected string $filterClass;

Expand All @@ -56,11 +56,7 @@ public function testApply(?array $properties, array $filterParameters, string $e
protected function doTestApply(?array $properties, array $filterParameters, string $expectedDql, array $expectedParameters = null, callable $filterFactory = null, string $resourceClass = null): void
{
if (null === $filterFactory) {
$filterFactory = function (ManagerRegistry $managerRegistry, array $properties = null): FilterInterface {
$filterClass = $this->filterClass;

return new $filterClass($managerRegistry, null, $properties);
};
$filterFactory = fn (self $that, ManagerRegistry $managerRegistry, array $properties = null): FilterInterface => new ($this->filterClass)($managerRegistry, null, $properties);
}

$repository = $this->repository;
Expand All @@ -69,8 +65,8 @@ protected function doTestApply(?array $properties, array $filterParameters, stri
$repository = $this->managerRegistry->getManagerForClass($resourceClass)->getRepository($resourceClass);
}
$resourceClass = $resourceClass ?: $this->resourceClass;
$queryBuilder = $repository->createQueryBuilder($this->alias);
$filterCallable = $filterFactory($this->managerRegistry, $properties);
$queryBuilder = $repository->createQueryBuilder(static::ALIAS);
$filterCallable = $filterFactory($this, $this->managerRegistry, $properties);
$filterCallable->apply($queryBuilder, new QueryNameGenerator(), $resourceClass, null, ['filters' => $filterParameters]);

$this->assertSame($expectedDql, $queryBuilder->getQuery()->getDQL());
Expand All @@ -92,5 +88,5 @@ protected function buildFilter(array $properties = null)
return new $this->filterClass($this->managerRegistry, null, $properties);
}

abstract public function provideApplyTestData(): array;
abstract public static function provideApplyTestData(): array;
}
2 changes: 1 addition & 1 deletion tests/Action/ExceptionActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function testActionWithOperationExceptionToStatus(
$this->assertTrue($response->headers->contains('X-Frame-Options', 'deny'));
}

public function provideOperationExceptionToStatusCases(): \Generator
public static function provideOperationExceptionToStatusCases(): \Generator
{
yield 'no mapping' => [
[],
Expand Down
4 changes: 2 additions & 2 deletions tests/Api/CompositeIdentifierParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testNormalizeCompositeCorrectly(array $identifiers): void
}
}

public function variousIdentifiers(): array
public static function variousIdentifiers(): array
{
return [[[
'a=bd;dc=d' => ['a' => 'bd', 'dc' => 'd'],
Expand All @@ -52,7 +52,7 @@ public function testStringify(array $identifiers): void
}
}

public function compositeIdentifiers(): array
public static function compositeIdentifiers(): array
{
return [[[
'a=bd;dc=d' => ['a' => 'bd', 'dc' => 'd'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ protected function setUp(): void

/**
* unsafe method should not use filter validations.
*
* @doesNotPerformAssertions
*/
public function testOnKernelRequestWithUnsafeMethod(): void
{
Expand All @@ -58,6 +60,8 @@ public function testOnKernelRequestWithUnsafeMethod(): void

/**
* If the tested filter is non-existent, then nothing should append.
*
* @doesNotPerformAssertions
*/
public function testOnKernelRequestWithWrongFilter(): void
{
Expand Down
Loading

0 comments on commit f0698a4

Please sign in to comment.