Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PHPUnit 10 #335

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/composer.phar
/bin
/.phpcs-cache
/.phpunit.result.cache
/.idea
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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/" }
},
Expand Down
33 changes: 17 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="tests/bootstrap.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
displayDetailsOnPhpunitDeprecations="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="Hateoas Test Suite">
<directory>./tests/</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>

<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
);
}

Expand All @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions tests/Hateoas/Tests/HateoasBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Hateoas\UrlGenerator\CallableUrlGenerator;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerInterface;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Contains functional tests
Expand All @@ -29,9 +30,7 @@ public function testBuild()
$this->assertInstanceOf(SerializerInterface::class, $hateoas);
}

/**
* @dataProvider getTestSerializeAdrienBraultWithExclusionData
*/
#[DataProvider('getTestSerializeAdrienBraultWithExclusionData')]
public function testSerializeAdrienBraultWithExclusion($adrienBrault, $fakeAdrienBrault)
{
$hateoas = HateoasBuilder::buildHateoas();
Expand Down Expand Up @@ -71,7 +70,7 @@ public function testSerializeAdrienBraultWithExclusion($adrienBrault, $fakeAdrie
);
}

private static function getTestSerializeAdrienBraultWithExclusionData(): iterable
public static function getTestSerializeAdrienBraultWithExclusionData(): iterable
{
yield [
new Attribute\AdrienBrault(),
Expand Down
28 changes: 13 additions & 15 deletions tests/Hateoas/Tests/Representation/CollectionRepresentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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',
]),
];
}
}
13 changes: 5 additions & 8 deletions tests/Hateoas/Tests/Serializer/ExclusionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'];
Expand All @@ -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];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ public function getExtensions()
];
}

public function getFixturesDir()
protected static function getFixturesDirectory(): string
{
if (class_exists(AnnotationReader::class)) {
return __DIR__ . '/../Fixtures/';
} else {
return __DIR__ . '/../FixturesAttribute/';
}
}

/**
* for compatibility with Twig < 3.13
*/
public function getFixturesDir()
{
return self::getFixturesDirectory();
}
}
Loading