From 788bb0805c5b4f828d9aec1d4124461342bf5e35 Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 31 Oct 2024 18:04:34 +0100 Subject: [PATCH 1/6] Bump PHPUnit version to 10.5 --- .gitignore | 1 + composer.json | 3 +-- phpunit.xml.dist | 33 +++++++++++++++++---------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index f39b83c6..aa9967ae 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /composer.phar /bin /.phpcs-cache +/.phpunit.result.cache /.idea diff --git a/composer.json b/composer.json index edfc7429..590c7069 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "symfony/expression-language": "^3.4.47 || ~4.0 || ~5.0 || ~6.0 || ~7.0" }, "require-dev": { - "phpunit/phpunit": "^9.5.10", + "phpunit/phpunit": "^10.5.38", "doctrine/annotations": "^1.13.2 || ^2.0", "doctrine/coding-standard": "^12.0", "doctrine/persistence": "^1.3.4 | ^2.0 | ^3.0", @@ -40,7 +40,6 @@ "symfony/routing": "To use the SymfonyRouteFactory.", "twig/twig": "To use the Twig extensions." }, - "minimum-stability": "dev", "autoload": { "psr-4": { "Hateoas\\": "src/" } }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0e829222..e7beaf6e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,23 @@ - + - ./tests/ + tests - - - ./src/ - - + + + + src + + From 79b4cc4f8f1f98f052e6a0c35ee545e992940f03 Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 31 Oct 2024 18:05:26 +0100 Subject: [PATCH 2/6] Rename abstract test class to not execute this class as test --- .../{AbstractDriverTest.php => AbstractDriverTestCase.php} | 2 +- .../Configuration/Metadata/Driver/AnnotationDriverTest.php | 2 +- .../Tests/Configuration/Metadata/Driver/AttributeDriverTest.php | 2 +- .../Tests/Configuration/Metadata/Driver/XmlDriverTest.php | 2 +- .../Tests/Configuration/Metadata/Driver/YamlDriverTest.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename tests/Hateoas/Tests/Configuration/Metadata/Driver/{AbstractDriverTest.php => AbstractDriverTestCase.php} (99%) diff --git a/tests/Hateoas/Tests/Configuration/Metadata/Driver/AbstractDriverTest.php b/tests/Hateoas/Tests/Configuration/Metadata/Driver/AbstractDriverTestCase.php similarity index 99% rename from tests/Hateoas/Tests/Configuration/Metadata/Driver/AbstractDriverTest.php rename to tests/Hateoas/Tests/Configuration/Metadata/Driver/AbstractDriverTestCase.php index 51f14a0f..7e0d95cf 100644 --- a/tests/Hateoas/Tests/Configuration/Metadata/Driver/AbstractDriverTest.php +++ b/tests/Hateoas/Tests/Configuration/Metadata/Driver/AbstractDriverTestCase.php @@ -18,7 +18,7 @@ use Metadata\Driver\DriverInterface; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -abstract class AbstractDriverTest extends TestCase +abstract class AbstractDriverTestCase extends TestCase { protected function getExpressionEvaluator() { diff --git a/tests/Hateoas/Tests/Configuration/Metadata/Driver/AnnotationDriverTest.php b/tests/Hateoas/Tests/Configuration/Metadata/Driver/AnnotationDriverTest.php index 9aa85059..fd0c548f 100644 --- a/tests/Hateoas/Tests/Configuration/Metadata/Driver/AnnotationDriverTest.php +++ b/tests/Hateoas/Tests/Configuration/Metadata/Driver/AnnotationDriverTest.php @@ -7,7 +7,7 @@ use Doctrine\Common\Annotations\AnnotationReader; use Hateoas\Configuration\Metadata\Driver\AnnotationDriver; -class AnnotationDriverTest extends AbstractDriverTest +class AnnotationDriverTest extends AbstractDriverTestCase { public function setUp(): void { diff --git a/tests/Hateoas/Tests/Configuration/Metadata/Driver/AttributeDriverTest.php b/tests/Hateoas/Tests/Configuration/Metadata/Driver/AttributeDriverTest.php index 5e7e8e3e..3284f866 100644 --- a/tests/Hateoas/Tests/Configuration/Metadata/Driver/AttributeDriverTest.php +++ b/tests/Hateoas/Tests/Configuration/Metadata/Driver/AttributeDriverTest.php @@ -7,7 +7,7 @@ use Hateoas\Configuration\Metadata\Driver\AttributeDriver; use Hateoas\Tests\Fixtures\Attribute\User; -class AttributeDriverTest extends AbstractDriverTest +class AttributeDriverTest extends AbstractDriverTestCase { public function createDriver() { diff --git a/tests/Hateoas/Tests/Configuration/Metadata/Driver/XmlDriverTest.php b/tests/Hateoas/Tests/Configuration/Metadata/Driver/XmlDriverTest.php index 127a86bd..d3f5dd9f 100644 --- a/tests/Hateoas/Tests/Configuration/Metadata/Driver/XmlDriverTest.php +++ b/tests/Hateoas/Tests/Configuration/Metadata/Driver/XmlDriverTest.php @@ -7,7 +7,7 @@ use Hateoas\Configuration\Metadata\Driver\XmlDriver; use Metadata\Driver\FileLocator; -class XmlDriverTest extends AbstractDriverTest +class XmlDriverTest extends AbstractDriverTestCase { public function createDriver() { diff --git a/tests/Hateoas/Tests/Configuration/Metadata/Driver/YamlDriverTest.php b/tests/Hateoas/Tests/Configuration/Metadata/Driver/YamlDriverTest.php index c7d76107..57cfd573 100644 --- a/tests/Hateoas/Tests/Configuration/Metadata/Driver/YamlDriverTest.php +++ b/tests/Hateoas/Tests/Configuration/Metadata/Driver/YamlDriverTest.php @@ -7,7 +7,7 @@ use Hateoas\Configuration\Metadata\Driver\YamlDriver; use Metadata\Driver\FileLocator; -class YamlDriverTest extends AbstractDriverTest +class YamlDriverTest extends AbstractDriverTestCase { public function createDriver() { From d36784cb2def06eca291e1e26a299ebcd5d943c3 Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 31 Oct 2024 18:05:55 +0100 Subject: [PATCH 3/6] Fix data provider deprecations in PHPUnit 10.5 --- tests/Hateoas/Tests/HateoasBuilderTest.php | 7 ++--- .../CollectionRepresentationTest.php | 28 +++++++++---------- .../Tests/Serializer/ExclusionManagerTest.php | 13 ++++----- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/tests/Hateoas/Tests/HateoasBuilderTest.php b/tests/Hateoas/Tests/HateoasBuilderTest.php index 70e7d926..03bb357f 100644 --- a/tests/Hateoas/Tests/HateoasBuilderTest.php +++ b/tests/Hateoas/Tests/HateoasBuilderTest.php @@ -15,6 +15,7 @@ use Hateoas\UrlGenerator\CallableUrlGenerator; use JMS\Serializer\SerializationContext; use JMS\Serializer\SerializerInterface; +use PHPUnit\Framework\Attributes\DataProvider; /** * Contains functional tests @@ -29,9 +30,7 @@ public function testBuild() $this->assertInstanceOf(SerializerInterface::class, $hateoas); } - /** - * @dataProvider getTestSerializeAdrienBraultWithExclusionData - */ + #[DataProvider('getTestSerializeAdrienBraultWithExclusionData')] public function testSerializeAdrienBraultWithExclusion($adrienBrault, $fakeAdrienBrault) { $hateoas = HateoasBuilder::buildHateoas(); @@ -71,7 +70,7 @@ public function testSerializeAdrienBraultWithExclusion($adrienBrault, $fakeAdrie ); } - private static function getTestSerializeAdrienBraultWithExclusionData(): iterable + public static function getTestSerializeAdrienBraultWithExclusionData(): iterable { yield [ new Attribute\AdrienBrault(), diff --git a/tests/Hateoas/Tests/Representation/CollectionRepresentationTest.php b/tests/Hateoas/Tests/Representation/CollectionRepresentationTest.php index 838e661d..a38702fe 100644 --- a/tests/Hateoas/Tests/Representation/CollectionRepresentationTest.php +++ b/tests/Hateoas/Tests/Representation/CollectionRepresentationTest.php @@ -5,12 +5,11 @@ namespace Hateoas\Tests\Representation; use Hateoas\Representation\CollectionRepresentation; +use PHPUnit\Framework\Attributes\DataProvider; class CollectionRepresentationTest extends RepresentationTestCase { - /** - * @dataProvider getTestSerializeData - */ + #[DataProvider('getTestSerializeData')] public function testSerialize($resources) { $collection = new CollectionRepresentation($resources); @@ -58,21 +57,20 @@ public function testSerialize($resources) ); } - public function getTestSerializeData() + public static function getTestSerializeData(): iterable { - return [ + yield [ [ - [ - 'Adrien', - 'William', - ], - ], - [ - new \ArrayIterator([ - 'Adrien', - 'William', - ]), + 'Adrien', + 'William', ], ]; + + yield [ + new \ArrayIterator([ + 'Adrien', + 'William', + ]), + ]; } } diff --git a/tests/Hateoas/Tests/Serializer/ExclusionManagerTest.php b/tests/Hateoas/Tests/Serializer/ExclusionManagerTest.php index 0bb75818..6cece891 100644 --- a/tests/Hateoas/Tests/Serializer/ExclusionManagerTest.php +++ b/tests/Hateoas/Tests/Serializer/ExclusionManagerTest.php @@ -15,6 +15,7 @@ use JMS\Serializer\SerializationContext; use JMS\Serializer\Visitor\SerializationVisitorInterface; use Metadata\MetadataFactoryInterface; +use PHPUnit\Framework\Attributes\DataProvider; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; @@ -107,9 +108,7 @@ public function testSkipEmbedded() $this->assertTrue($exclusionManager->shouldSkipEmbedded($object, $relation, $context)); } - /** - * @dataProvider getTestSkipExcludeIfData - */ + #[DataProvider('getTestSkipExcludeIfData')] public function testSkipExcludeIf($exclude) { $object = (object) ['name' => 'adrien']; @@ -136,12 +135,10 @@ public function testSkipExcludeIf($exclude) $this->assertSame($exclude, $exclusionManager->shouldSkipEmbedded($object, $relation, $context)); } - public function getTestSkipExcludeIfData() + public static function getTestSkipExcludeIfData(): iterable { - return [ - [true], - [false], - ]; + yield [true]; + yield [false]; } /** From 90a1a82043bc68e6bc7b89c1f020dfafe9331d78 Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 31 Oct 2024 18:06:25 +0100 Subject: [PATCH 4/6] Fix method name but keep compatibility with Twig < 3.13 --- .../Twig/Extension/LinkExtensionIntegrationTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/Hateoas/Tests/Twig/Extension/LinkExtensionIntegrationTest.php b/tests/Hateoas/Tests/Twig/Extension/LinkExtensionIntegrationTest.php index 253149b8..9426f350 100644 --- a/tests/Hateoas/Tests/Twig/Extension/LinkExtensionIntegrationTest.php +++ b/tests/Hateoas/Tests/Twig/Extension/LinkExtensionIntegrationTest.php @@ -30,7 +30,7 @@ public function getExtensions() ]; } - public function getFixturesDir() + protected static function getFixturesDirectory(): string { if (class_exists(AnnotationReader::class)) { return __DIR__ . '/../Fixtures/'; @@ -38,4 +38,12 @@ public function getFixturesDir() return __DIR__ . '/../FixturesAttribute/'; } } + + /** + * for compatibility with Twig < 3.13 + */ + public function getFixturesDir() + { + return self::getFixturesDirectory(); + } } From ea287416d150e2a4fad059ad3fc409026186f41d Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 31 Oct 2024 18:06:38 +0100 Subject: [PATCH 5/6] Test against latest pagerfanta version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 590c7069..671f6d37 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "doctrine/annotations": "^1.13.2 || ^2.0", "doctrine/coding-standard": "^12.0", "doctrine/persistence": "^1.3.4 | ^2.0 | ^3.0", - "pagerfanta/core": "^2.4 || ^3.0", + "pagerfanta/core": "^2.4 || ^3.0 || ^4.0", "phpdocumentor/type-resolver": "^1.5.1", "phpspec/prophecy-phpunit": "^2.0.1", "phpspec/prophecy": "^1.16", From 0d627b4da633d56ce05e4140eeb890fea869685a Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 31 Oct 2024 19:15:08 +0100 Subject: [PATCH 6/6] Fix test follow-up of b8c83de04239866de4af92d4cd3911b0d7cda55c --- ...Tes.php => LinkExpressionFunctionTest.php} | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) rename tests/Hateoas/Tests/Expression/{LinkExpressionFunctionTes.php => LinkExpressionFunctionTest.php} (61%) diff --git a/tests/Hateoas/Tests/Expression/LinkExpressionFunctionTes.php b/tests/Hateoas/Tests/Expression/LinkExpressionFunctionTest.php similarity index 61% rename from tests/Hateoas/Tests/Expression/LinkExpressionFunctionTes.php rename to tests/Hateoas/Tests/Expression/LinkExpressionFunctionTest.php index 67ed222e..7c8e806a 100644 --- a/tests/Hateoas/Tests/Expression/LinkExpressionFunctionTes.php +++ b/tests/Hateoas/Tests/Expression/LinkExpressionFunctionTest.php @@ -4,10 +4,10 @@ namespace Hateoas\Tests\Expression; -use Hateoas\Expression\ExpressionEvaluator; use Hateoas\Expression\LinkExpressionFunction; use Hateoas\Helper\LinkHelper; use Hateoas\Tests\TestCase; +use JMS\Serializer\Expression\ExpressionEvaluator; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; class LinkExpressionFunctionTest extends TestCase @@ -18,12 +18,14 @@ public function testEvaluate() $linkHelperMock = $this->mockHelper('/foo', $object, 'self', false); - $expressionEvaluator = new ExpressionEvaluator(new ExpressionLanguage()); - $expressionEvaluator->registerFunction(new LinkExpressionFunction($linkHelperMock)); + $expressionLanguage = new ExpressionLanguage(); + $expressionLanguage->registerProvider(new LinkExpressionFunction()); + + $expressionEvaluator = new ExpressionEvaluator($expressionLanguage, ['link_helper' => $linkHelperMock]); $this->assertEquals( '/foo', - $expressionEvaluator->evaluate('expr(link(object, "self", false))', $object) + $expressionEvaluator->evaluate('link(object, "self", false)', ['object' => $object]) ); } @@ -34,37 +36,29 @@ public function testCompile() $linkHelperMock = $this->mockHelper('/foo', $object, 'self', false); $expressionLanguage = new ExpressionLanguage(); + $expressionLanguage->registerProvider(new LinkExpressionFunction()); + $expressionEvaluator = new ExpressionEvaluator($expressionLanguage); - $expressionEvaluator->registerFunction(new LinkExpressionFunction($linkHelperMock)); - $compiledExpression = $expressionLanguage->compile('link(object, "self", false)', ['object', 'link_helper']); + $compiledExpression = $expressionLanguage->compile('link(object, "self", false)', ['object']); // setup variables for expression eval - $object = $object; $link_helper = $linkHelperMock; $this->assertEquals('/foo', eval(sprintf('return %s;', $compiledExpression))); } - /** - * @param string $result - * @param \stdClass $expectedObject - * @param string $expectedRel - * @param bool $expectedAbsolute - * - * @return LinkHelper - */ - private function mockHelper($result, $expectedObject, $expectedRel, $expectedAbsolute) + private function mockHelper(string $result, \stdClass $expectedObject, string $expectedRel, bool $expectedAbsolute): LinkHelper { $linkHelperMock = $this - ->getMockBuilder('Hateoas\Helper\LinkHelper') + ->getMockBuilder(LinkHelper::class) ->disableOriginalConstructor() ->getMock(); $linkHelperMock ->expects($this->once()) ->method('getLinkHref') - ->will($this->returnValue('/foo')) + ->will($this->returnValue($result)) ->with($expectedObject, $expectedRel, $expectedAbsolute); return $linkHelperMock;