Skip to content

Commit b2a3b1e

Browse files
authored
Merge pull request #335 from W0rma/phpunit10
Use PHPUnit 10
2 parents 34396ee + 0d627b4 commit b2a3b1e

13 files changed

+67
-70
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/composer.phar
44
/bin
55
/.phpcs-cache
6+
/.phpunit.result.cache
67
/.idea

composer.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
"symfony/expression-language": "^3.4.47 || ~4.0 || ~5.0 || ~6.0 || ~7.0"
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "^9.5.10",
26+
"phpunit/phpunit": "^10.5.38",
2727
"doctrine/annotations": "^1.13.2 || ^2.0",
2828
"doctrine/coding-standard": "^12.0",
2929
"doctrine/persistence": "^1.3.4 | ^2.0 | ^3.0",
30-
"pagerfanta/core": "^2.4 || ^3.0",
30+
"pagerfanta/core": "^2.4 || ^3.0 || ^4.0",
3131
"phpdocumentor/type-resolver": "^1.5.1",
3232
"phpspec/prophecy-phpunit": "^2.0.1",
3333
"phpspec/prophecy": "^1.16",
@@ -40,7 +40,6 @@
4040
"symfony/routing": "To use the SymfonyRouteFactory.",
4141
"twig/twig": "To use the Twig extensions."
4242
},
43-
"minimum-stability": "dev",
4443
"autoload": {
4544
"psr-4": { "Hateoas\\": "src/" }
4645
},

phpunit.xml.dist

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
processIsolation="false"
9-
stopOnFailure="false"
10-
bootstrap="tests/bootstrap.php"
11-
>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
bootstrap="tests/bootstrap.php"
5+
cacheDirectory=".phpunit.cache"
6+
executionOrder="depends,defects"
7+
beStrictAboutCoverageMetadata="true"
8+
beStrictAboutOutputDuringTests="true"
9+
displayDetailsOnPhpunitDeprecations="true"
10+
failOnRisky="true"
11+
failOnWarning="true">
1212
<testsuites>
1313
<testsuite name="Hateoas Test Suite">
14-
<directory>./tests/</directory>
14+
<directory>tests</directory>
1515
</testsuite>
1616
</testsuites>
17-
<filter>
18-
<whitelist>
19-
<directory>./src/</directory>
20-
</whitelist>
21-
</filter>
17+
18+
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
19+
<include>
20+
<directory>src</directory>
21+
</include>
22+
</source>
2223
</phpunit>

tests/Hateoas/Tests/Configuration/Metadata/Driver/AbstractDriverTest.php tests/Hateoas/Tests/Configuration/Metadata/Driver/AbstractDriverTestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Metadata\Driver\DriverInterface;
1919
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
2020

21-
abstract class AbstractDriverTest extends TestCase
21+
abstract class AbstractDriverTestCase extends TestCase
2222
{
2323
protected function getExpressionEvaluator()
2424
{

tests/Hateoas/Tests/Configuration/Metadata/Driver/AnnotationDriverTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Doctrine\Common\Annotations\AnnotationReader;
88
use Hateoas\Configuration\Metadata\Driver\AnnotationDriver;
99

10-
class AnnotationDriverTest extends AbstractDriverTest
10+
class AnnotationDriverTest extends AbstractDriverTestCase
1111
{
1212
public function setUp(): void
1313
{

tests/Hateoas/Tests/Configuration/Metadata/Driver/AttributeDriverTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Hateoas\Configuration\Metadata\Driver\AttributeDriver;
88
use Hateoas\Tests\Fixtures\Attribute\User;
99

10-
class AttributeDriverTest extends AbstractDriverTest
10+
class AttributeDriverTest extends AbstractDriverTestCase
1111
{
1212
public function createDriver()
1313
{

tests/Hateoas/Tests/Configuration/Metadata/Driver/XmlDriverTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Hateoas\Configuration\Metadata\Driver\XmlDriver;
88
use Metadata\Driver\FileLocator;
99

10-
class XmlDriverTest extends AbstractDriverTest
10+
class XmlDriverTest extends AbstractDriverTestCase
1111
{
1212
public function createDriver()
1313
{

tests/Hateoas/Tests/Configuration/Metadata/Driver/YamlDriverTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Hateoas\Configuration\Metadata\Driver\YamlDriver;
88
use Metadata\Driver\FileLocator;
99

10-
class YamlDriverTest extends AbstractDriverTest
10+
class YamlDriverTest extends AbstractDriverTestCase
1111
{
1212
public function createDriver()
1313
{

tests/Hateoas/Tests/Expression/LinkExpressionFunctionTes.php tests/Hateoas/Tests/Expression/LinkExpressionFunctionTest.php

+12-18
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Hateoas\Tests\Expression;
66

7-
use Hateoas\Expression\ExpressionEvaluator;
87
use Hateoas\Expression\LinkExpressionFunction;
98
use Hateoas\Helper\LinkHelper;
109
use Hateoas\Tests\TestCase;
10+
use JMS\Serializer\Expression\ExpressionEvaluator;
1111
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1212

1313
class LinkExpressionFunctionTest extends TestCase
@@ -18,12 +18,14 @@ public function testEvaluate()
1818

1919
$linkHelperMock = $this->mockHelper('/foo', $object, 'self', false);
2020

21-
$expressionEvaluator = new ExpressionEvaluator(new ExpressionLanguage());
22-
$expressionEvaluator->registerFunction(new LinkExpressionFunction($linkHelperMock));
21+
$expressionLanguage = new ExpressionLanguage();
22+
$expressionLanguage->registerProvider(new LinkExpressionFunction());
23+
24+
$expressionEvaluator = new ExpressionEvaluator($expressionLanguage, ['link_helper' => $linkHelperMock]);
2325

2426
$this->assertEquals(
2527
'/foo',
26-
$expressionEvaluator->evaluate('expr(link(object, "self", false))', $object)
28+
$expressionEvaluator->evaluate('link(object, "self", false)', ['object' => $object])
2729
);
2830
}
2931

@@ -34,37 +36,29 @@ public function testCompile()
3436
$linkHelperMock = $this->mockHelper('/foo', $object, 'self', false);
3537

3638
$expressionLanguage = new ExpressionLanguage();
39+
$expressionLanguage->registerProvider(new LinkExpressionFunction());
40+
3741
$expressionEvaluator = new ExpressionEvaluator($expressionLanguage);
38-
$expressionEvaluator->registerFunction(new LinkExpressionFunction($linkHelperMock));
3942

40-
$compiledExpression = $expressionLanguage->compile('link(object, "self", false)', ['object', 'link_helper']);
43+
$compiledExpression = $expressionLanguage->compile('link(object, "self", false)', ['object']);
4144

4245
// setup variables for expression eval
43-
$object = $object;
4446
$link_helper = $linkHelperMock;
4547

4648
$this->assertEquals('/foo', eval(sprintf('return %s;', $compiledExpression)));
4749
}
4850

49-
/**
50-
* @param string $result
51-
* @param \stdClass $expectedObject
52-
* @param string $expectedRel
53-
* @param bool $expectedAbsolute
54-
*
55-
* @return LinkHelper
56-
*/
57-
private function mockHelper($result, $expectedObject, $expectedRel, $expectedAbsolute)
51+
private function mockHelper(string $result, \stdClass $expectedObject, string $expectedRel, bool $expectedAbsolute): LinkHelper
5852
{
5953
$linkHelperMock = $this
60-
->getMockBuilder('Hateoas\Helper\LinkHelper')
54+
->getMockBuilder(LinkHelper::class)
6155
->disableOriginalConstructor()
6256
->getMock();
6357

6458
$linkHelperMock
6559
->expects($this->once())
6660
->method('getLinkHref')
67-
->will($this->returnValue('/foo'))
61+
->will($this->returnValue($result))
6862
->with($expectedObject, $expectedRel, $expectedAbsolute);
6963

7064
return $linkHelperMock;

tests/Hateoas/Tests/HateoasBuilderTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Hateoas\UrlGenerator\CallableUrlGenerator;
1616
use JMS\Serializer\SerializationContext;
1717
use JMS\Serializer\SerializerInterface;
18+
use PHPUnit\Framework\Attributes\DataProvider;
1819

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

32-
/**
33-
* @dataProvider getTestSerializeAdrienBraultWithExclusionData
34-
*/
33+
#[DataProvider('getTestSerializeAdrienBraultWithExclusionData')]
3534
public function testSerializeAdrienBraultWithExclusion($adrienBrault, $fakeAdrienBrault)
3635
{
3736
$hateoas = HateoasBuilder::buildHateoas();
@@ -71,7 +70,7 @@ public function testSerializeAdrienBraultWithExclusion($adrienBrault, $fakeAdrie
7170
);
7271
}
7372

74-
private static function getTestSerializeAdrienBraultWithExclusionData(): iterable
73+
public static function getTestSerializeAdrienBraultWithExclusionData(): iterable
7574
{
7675
yield [
7776
new Attribute\AdrienBrault(),

tests/Hateoas/Tests/Representation/CollectionRepresentationTest.php

+13-15
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
namespace Hateoas\Tests\Representation;
66

77
use Hateoas\Representation\CollectionRepresentation;
8+
use PHPUnit\Framework\Attributes\DataProvider;
89

910
class CollectionRepresentationTest extends RepresentationTestCase
1011
{
11-
/**
12-
* @dataProvider getTestSerializeData
13-
*/
12+
#[DataProvider('getTestSerializeData')]
1413
public function testSerialize($resources)
1514
{
1615
$collection = new CollectionRepresentation($resources);
@@ -58,21 +57,20 @@ public function testSerialize($resources)
5857
);
5958
}
6059

61-
public function getTestSerializeData()
60+
public static function getTestSerializeData(): iterable
6261
{
63-
return [
62+
yield [
6463
[
65-
[
66-
'Adrien',
67-
'William',
68-
],
69-
],
70-
[
71-
new \ArrayIterator([
72-
'Adrien',
73-
'William',
74-
]),
64+
'Adrien',
65+
'William',
7566
],
7667
];
68+
69+
yield [
70+
new \ArrayIterator([
71+
'Adrien',
72+
'William',
73+
]),
74+
];
7775
}
7876
}

tests/Hateoas/Tests/Serializer/ExclusionManagerTest.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use JMS\Serializer\SerializationContext;
1616
use JMS\Serializer\Visitor\SerializationVisitorInterface;
1717
use Metadata\MetadataFactoryInterface;
18+
use PHPUnit\Framework\Attributes\DataProvider;
1819
use Prophecy\Argument;
1920
use Prophecy\PhpUnit\ProphecyTrait;
2021
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
@@ -107,9 +108,7 @@ public function testSkipEmbedded()
107108
$this->assertTrue($exclusionManager->shouldSkipEmbedded($object, $relation, $context));
108109
}
109110

110-
/**
111-
* @dataProvider getTestSkipExcludeIfData
112-
*/
111+
#[DataProvider('getTestSkipExcludeIfData')]
113112
public function testSkipExcludeIf($exclude)
114113
{
115114
$object = (object) ['name' => 'adrien'];
@@ -136,12 +135,10 @@ public function testSkipExcludeIf($exclude)
136135
$this->assertSame($exclude, $exclusionManager->shouldSkipEmbedded($object, $relation, $context));
137136
}
138137

139-
public function getTestSkipExcludeIfData()
138+
public static function getTestSkipExcludeIfData(): iterable
140139
{
141-
return [
142-
[true],
143-
[false],
144-
];
140+
yield [true];
141+
yield [false];
145142
}
146143

147144
/**

tests/Hateoas/Tests/Twig/Extension/LinkExtensionIntegrationTest.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@ public function getExtensions()
3030
];
3131
}
3232

33-
public function getFixturesDir()
33+
protected static function getFixturesDirectory(): string
3434
{
3535
if (class_exists(AnnotationReader::class)) {
3636
return __DIR__ . '/../Fixtures/';
3737
} else {
3838
return __DIR__ . '/../FixturesAttribute/';
3939
}
4040
}
41+
42+
/**
43+
* for compatibility with Twig < 3.13
44+
*/
45+
public function getFixturesDir()
46+
{
47+
return self::getFixturesDirectory();
48+
}
4149
}

0 commit comments

Comments
 (0)