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..671f6d37 100644 --- a/composer.json +++ b/composer.json @@ -23,11 +23,11 @@ "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", - "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", @@ -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 + + 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() { 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; 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]; } /** 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(); + } }