Skip to content

Commit

Permalink
remove phpunit 8.5, add phpunit 10.5 (#2258)
Browse files Browse the repository at this point in the history
* remove phpunit 8.5, add phpunit 10.5

* add static to data providers

* rename abstract test class

* set error handler

* remove expection code assertions

* update phpunit config

* fix test class renamed
  • Loading branch information
DjordyKoert committed Apr 6, 2024
1 parent db14c1a commit a585e50
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 112 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

"doctrine/annotations": "^2.0",

"phpunit/phpunit": "^8.5|^9.6",
"phpunit/phpunit": "^9.6|^10.5",

"friendsofphp/php-cs-fixer": "^3.52",

Expand Down
8 changes: 7 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
backupGlobals="false"
colors="true"
failOnWarning="true"
Expand All @@ -24,4 +24,10 @@
<directory>tests</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions tests/Command/DumpCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testJson(array $jsonOptions, int $expectedJsonFlags)
);
}

public function provideJsonMode()
public static function provideJsonMode(): iterable
{
return [
'pretty print' => [[], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES],
Expand Down Expand Up @@ -64,7 +64,7 @@ public function testHtml($htmlConfig, string $expectedHtml)
self::assertStringContainsString($expectedHtml, $output);
}

public function provideAssetsMode()
public static function provideAssetsMode(): iterable
{
return [
'default mode is cdn' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use OpenApi\Context;
use PHPUnit\Framework\TestCase;

abstract class AbstractDescriberTest extends TestCase
abstract class AbstractDescriberTestCase extends TestCase
{
/** @var DescriberInterface */
protected $describer;
Expand Down
2 changes: 1 addition & 1 deletion tests/Describer/ApiPlatformDescriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use OpenApi\Context;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class ApiPlatformDescriberTest extends AbstractDescriberTest
class ApiPlatformDescriberTest extends AbstractDescriberTestCase
{
private $documentation;

Expand Down
2 changes: 1 addition & 1 deletion tests/Describer/RouteDescriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

class RouteDescriberTest extends AbstractDescriberTest
class RouteDescriberTest extends AbstractDescriberTestCase
{
private $routes;

Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/FOSRestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testFOSRestAction(string $route)
self::assertNotHasParameter('_format', 'path', $operation);
}

public function provideRoute(): iterable
public static function provideRoute(): iterable
{
yield 'Annotations' => ['/api/fosrest'];

Expand Down
10 changes: 5 additions & 5 deletions tests/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testFetchArticleAction(string $articleRoute)
$this->assertNotHasProperty('author', Util::getProperty($articleModel, 'author'));
}

public function provideArticleRoute(): iterable
public static function provideArticleRoute(): iterable
{
if (interface_exists(Reader::class)) {
yield 'Annotations' => ['/api/article/{id}'];
Expand Down Expand Up @@ -95,7 +95,7 @@ public function testSwaggerAction(string $path)
self::assertEquals('An example resource', $response->description);
}

public function swaggerActionPathsProvider()
public static function swaggerActionPathsProvider(): iterable
{
return [['/api/swagger'], ['/api/swagger2']];
}
Expand Down Expand Up @@ -133,7 +133,7 @@ public function testImplicitSwaggerAction(string $method)
self::assertEquals('#/components/schemas/User', $requestBody->content['application/json']->schema->items->ref);
}

public function implicitSwaggerActionMethodsProvider()
public static function implicitSwaggerActionMethodsProvider(): iterable
{
return [['get'], ['post']];
}
Expand Down Expand Up @@ -384,7 +384,7 @@ public function testSecurityAction(string $route)
self::assertEquals($expected, $operation->security);
}

public function provideSecurityRoute(): iterable
public static function provideSecurityRoute(): iterable
{
yield 'Annotations' => ['/api/security'];

Expand All @@ -402,7 +402,7 @@ public function testSecurityOverrideAction(string $route)
self::assertEquals([], $operation->security);
}

public function provideSecurityOverrideRoute(): iterable
public static function provideSecurityOverrideRoute(): iterable
{
yield 'Annotations' => ['/api/securityOverride'];

Expand Down
6 changes: 3 additions & 3 deletions tests/Model/ModelRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testNameCollisionsAreLogged(Type $type, array $arrayType)
$registry->register(new Model($type, ['group2']));
}

public function provideNameCollisionsTypes()
public static function provideNameCollisionsTypes(): iterable
{
yield [
new Type(Type::BUILTIN_TYPE_OBJECT, false, self::class),
Expand Down Expand Up @@ -169,7 +169,7 @@ public function testNameAliasingForObjects(string $expected, $groups, array $alt
self::assertEquals($expected, $registry->register(new Model($type, $groups)));
}

public function getNameAlternatives()
public static function getNameAlternatives(): iterable
{
return [
[
Expand Down Expand Up @@ -238,7 +238,7 @@ public function testUnsupportedTypeException(Type $type, string $stringType)
$registry->registerSchemas();
}

public function unsupportedTypesProvider()
public static function unsupportedTypesProvider(): iterable
{
return [
[new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true), 'mixed[]'],
Expand Down
2 changes: 1 addition & 1 deletion tests/ModelDescriber/Annotations/AnnotationReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class_exists(AnnotationReader::class) ? new AnnotationReader() : null,
self::assertEquals($schema->properties[1]->description, 'some description');
}

public function provideProperty(): iterable
public static function provideProperty(): iterable
{
yield 'Annotations' => [new class() {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testOptionalProperty($entity)
self::assertEquals($schema->required, ['property2']);
}

public function provideOptionalProperty(): iterable
public static function provideOptionalProperty(): iterable
{
if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) {
yield 'Annotations' => [
Expand Down Expand Up @@ -152,7 +152,7 @@ public function testAssertChoiceResultsInNumericArray($entity)
self::assertEquals($schema->properties[0]->enum, ['active', 'blocked']);
}

public function provideAssertChoiceResultsInNumericArray(): iterable
public static function provideAssertChoiceResultsInNumericArray(): iterable
{
define('TEST_ASSERT_CHOICE_STATUSES', [
1 => 'active',
Expand Down Expand Up @@ -200,7 +200,7 @@ public function testMultipleChoiceConstraintsApplyEnumToItems($entity)
self::assertEquals($schema->properties[0]->items->enum, ['one', 'two']);
}

public function provideMultipleChoiceConstraintsApplyEnumToItems(): iterable
public static function provideMultipleChoiceConstraintsApplyEnumToItems(): iterable
{
if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) {
yield 'Annotations' => [new class() {
Expand Down Expand Up @@ -240,7 +240,7 @@ public function testLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet($entity)
self::assertSame(1, $schema->properties[0]->minLength);
}

public function provideLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet(): iterable
public static function provideLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet(): iterable
{
if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) {
yield 'Annotations' => [
Expand Down Expand Up @@ -282,7 +282,7 @@ public function testLengthConstraintDoesNotSetMinLengthIfMinIsNotSet($entity)
self::assertSame(100, $schema->properties[0]->maxLength);
}

public function provideLengthConstraintDoesNotSetMinLengthIfMinIsNotSet(): iterable
public static function provideLengthConstraintDoesNotSetMinLengthIfMinIsNotSet(): iterable
{
if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) {
yield 'Annotations' => [
Expand Down Expand Up @@ -364,7 +364,7 @@ public function testCountConstraintDoesNotSetMinItemsIfMinIsNotSet($entity)
self::assertSame(10, $schema->properties[0]->maxItems);
}

public function provideCountConstraintDoesNotSetMinItemsIfMinIsNotSet(): iterable
public static function provideCountConstraintDoesNotSetMinItemsIfMinIsNotSet(): iterable
{
if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) {
yield 'Annotations' => [
Expand Down Expand Up @@ -406,7 +406,7 @@ public function testCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet($entity)
self::assertSame(10, $schema->properties[0]->minItems);
}

public function provideCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet(): iterable
public static function provideCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet(): iterable
{
if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) {
yield 'Annotations' => [
Expand Down Expand Up @@ -448,7 +448,7 @@ public function testRangeConstraintDoesNotSetMaximumIfMaxIsNotSet($entity)
self::assertSame(10, $schema->properties[0]->minimum);
}

public function provideRangeConstraintDoesNotSetMaximumIfMaxIsNotSet(): iterable
public static function provideRangeConstraintDoesNotSetMaximumIfMaxIsNotSet(): iterable
{
if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) {
yield 'Annotations' => [
Expand Down Expand Up @@ -490,7 +490,7 @@ public function testRangeConstraintDoesNotSetMinimumIfMinIsNotSet($entity)
self::assertSame(10, $schema->properties[0]->maximum);
}

public function provideRangeConstraintDoesNotSetMinimumIfMinIsNotSet(): iterable
public static function provideRangeConstraintDoesNotSetMinimumIfMinIsNotSet(): iterable
{
if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) {
yield 'Annotations' => [
Expand Down Expand Up @@ -609,7 +609,7 @@ public function testReaderWithValidationGroupsEnabledCanReadFromMultipleValidati
self::assertSame(1, $schema->properties[0]->minimum, 'should have read constraint in other group');
}

public function provideConstraintsWithGroups(): iterable
public static function provideConstraintsWithGroups(): iterable
{
if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) {
yield 'Annotations' => [new class() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ModelDescriber/FormModelDescriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testDescribeCreatesTokenPropertyDependingOnOptions(bool $csrfPro
}
}

public function provideCsrfProtectionOptions(): array
public static function provideCsrfProtectionOptions(): iterable
{
return [
[true, '_token', true],
Expand Down
14 changes: 7 additions & 7 deletions tests/Render/Html/GetNelmioAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public function test($mode, $asset, $expectedContent)
self::assertSame($expectedContent, $twigFunction->getCallable()->__invoke($mode, $asset));
}

public function provideAsset()
public static function provideAsset(): iterable
{
$cdnDir = 'https://cdn.jsdelivr.net/gh/nelmio/NelmioApiDocBundle/public';
$resourceDir = __DIR__.'/../../../public';

return $this->provideCss($cdnDir, $resourceDir)
+ $this->provideJs($cdnDir, $resourceDir)
+ $this->provideImage($cdnDir);
return self::provideCss($cdnDir, $resourceDir)
+ self::provideJs($cdnDir, $resourceDir)
+ self::provideImage($cdnDir);
}

private function provideCss($cdnDir, $resourceDir)
private static function provideCss($cdnDir, $resourceDir): array
{
return [
'bundled css' => [
Expand All @@ -66,7 +66,7 @@ private function provideCss($cdnDir, $resourceDir)
];
}

private function provideJs($cdnDir, $resourceDir)
private static function provideJs($cdnDir, $resourceDir): array
{
return [
'bundled js' => [
Expand All @@ -92,7 +92,7 @@ private function provideJs($cdnDir, $resourceDir)
];
}

private function provideImage($cdnDir)
private static function provideImage($cdnDir): array
{
return [
'bundled image' => [
Expand Down
4 changes: 2 additions & 2 deletions tests/RouteDescriber/RouteMetadataDescriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ public function testNonEnumPatterns($pattern)
self::assertEquals(Generator::UNDEFINED, $getPathParameter->schema->enum);
}

public function provideEnumPattern()
public static function provideEnumPattern(): iterable
{
yield ['1|2|3'];
yield ['srf|rtr|rsi'];
yield ['srf-1|srf-2'];
yield ['srf-1|srf-2'];
}

public function provideInvalidEnumPattern()
public static function provideInvalidEnumPattern(): iterable
{
yield ['|'];
yield ['|a'];
Expand Down
10 changes: 5 additions & 5 deletions tests/Routing/FilteredRouteCollectionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function testFilterWithInvalidOption(array $options)
);
}

public function getInvalidOptions(): array
public static function getInvalidOptions(): iterable
{
return [
[['invalid_option' => null]],
Expand Down Expand Up @@ -168,7 +168,7 @@ public function testMatchingRoutes(string $name, Route $route, array $options =
self::assertCount(1, $filteredRoutes);
}

public function getMatchingRoutes(): iterable
public static function getMatchingRoutes(): iterable
{
yield from [
['r1', new Route('/api/bar/action1')],
Expand Down Expand Up @@ -220,7 +220,7 @@ public function testMatchingRoutesWithAnnotation(string $name, Route $route, arr
self::assertCount(1, $filteredRoutes);
}

public function getMatchingRoutesWithAnnotation(): iterable
public static function getMatchingRoutesWithAnnotation(): iterable
{
yield from [
'with annotation only' => [
Expand Down Expand Up @@ -270,7 +270,7 @@ public function testNonMatchingRoutes(string $name, Route $route, array $options
self::assertCount(0, $filteredRoutes);
}

public function getNonMatchingRoutes(): array
public static function getNonMatchingRoutes(): iterable
{
return [
['r1', new Route('/api/bar/action1'), ['path_patterns' => ['^/apis']]],
Expand Down Expand Up @@ -326,7 +326,7 @@ public function testRoutesWithDisabledDefaultRoutes(
/**
* @return array<string,array>
*/
public function getRoutesWithDisabledDefaultRoutes(): array
public static function getRoutesWithDisabledDefaultRoutes(): iterable
{
return [
'non matching route without Annotation' => [
Expand Down
Loading

0 comments on commit a585e50

Please sign in to comment.