Skip to content

Commit 8e720a6

Browse files
authored
Merge pull request #1725 from NatLibFi/issue1699-upgrade-phpunit-10
Upgrade to PHPUnit 10
2 parents a060b9b + b9cb29f commit 8e720a6

10 files changed

+191
-140
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"symfony/twig-bundle": "6.4.*"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "9.6.*",
24+
"phpunit/phpunit": "10.5.*",
2525
"symfony/dom-crawler": "6.4.*",
2626
"symfony/config": "6.4.*",
2727
"symfony/runtime": "6.4.*",

phpunit.xml

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
<?xml version="1.0"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="tests/bootstrap.php" processIsolation="true" convertDeprecationsToExceptions="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage processUncoveredFiles="true">
4-
<include>
5-
<directory suffix=".php">src/controller</directory>
6-
<directory suffix=".php">src/model</directory>
7-
<directory suffix=".php">src/model/sparql</directory>
8-
</include>
9-
<exclude>
10-
<directory>vendor</directory>
11-
</exclude>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="tests/bootstrap.php" processIsolation="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
3+
<php>
4+
<ini name="date.timezone" value="UTC"/>
5+
</php>
6+
<coverage>
127
<report>
138
<clover outputFile="build/logs/clover.xml"/>
149
<html outputDirectory="./report" lowUpperBound="35" highLowerBound="70"/>
@@ -17,7 +12,17 @@
1712
<logging/>
1813
<testsuites>
1914
<testsuite name="tests">
20-
<directory suffix=".php">tests</directory>
15+
<directory>tests</directory>
2116
</testsuite>
2217
</testsuites>
18+
<source>
19+
<include>
20+
<directory suffix=".php">src/controller</directory>
21+
<directory suffix=".php">src/model</directory>
22+
<directory suffix=".php">src/model/sparql</directory>
23+
</include>
24+
<exclude>
25+
<directory>vendor</directory>
26+
</exclude>
27+
</source>
2328
</phpunit>

src/model/resolver/LOCResource.php

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public function resolve(int $timeout): ?EasyRdf\Resource
1616
'timeout' => $timeout));
1717
$context = stream_context_create($opts);
1818
$fd = fopen($this->uri, 'rb', false, $context);
19+
if ($fd === false) {
20+
return null;
21+
}
1922
$headers = stream_get_meta_data($fd)['wrapper_data'];
2023
foreach ($headers as $header) {
2124
if (strpos(strtolower($header), 'x-preflabel:') === 0) {

tests/ConceptPropertyValueLiteralTest.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,22 @@ public function testGetLabelThatIsADate()
6161
*/
6262
public function testGetLabelThatIsABrokenDate()
6363
{
64-
set_error_handler(function ($code, $message) {
65-
throw new \PHPUnit\Framework\Error($message,$code);
66-
});
64+
set_error_handler(
65+
static function ( $errno, $errstr ) {
66+
restore_error_handler();
67+
throw new UserWarning( $errstr, $errno );
68+
},
69+
E_ALL
70+
);
6771

68-
try {
69-
$vocab = $this->model->getVocabulary('dates');
72+
$vocab = $this->model->getVocabulary('dates');
7073

71-
$this->expectException(\PHPUnit\Framework\Error::class);
72-
$this->expectExceptionMessage("Failed to parse time string (1986-21-00) at position 6 (1): Unexpected character");
74+
$this->expectException(UserWarning::class);
75+
$this->expectExceptionMessage("Failed to parse time string (1986-21-00) at position 6 (1): Unexpected character");
7376

74-
$concept = $vocab->getConceptInfo("http://www.skosmos.skos/date/d2", "en");
75-
$props = $concept->getProperties();
76-
$propvals = $props['http://www.skosmos.skos/date/ownDate']->getValues();
77-
} finally {
78-
restore_error_handler();
79-
}
77+
$concept = $vocab->getConceptInfo("http://www.skosmos.skos/date/d2", "en");
78+
$props = $concept->getProperties();
79+
$propvals = $props['http://www.skosmos.skos/date/ownDate']->getValues();
8080
}
8181

8282
/**

tests/ConceptTest.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ public function testGetMappingPropertiesWithIdenticalLabels()
227227
{
228228
$vocab = $this->model->getVocabulary('duplicates');
229229
$concept = $vocab->getConceptInfo("http://www.skosmos.skos/dup/d3", "en");
230-
$props = $concept->getMappingProperties();
230+
// suppress fsockopen PHP warnings caused by trying to resolve www.skosmos.skos
231+
@$props = $concept->getMappingProperties();
231232
$values = $props['skos:closeMatch']->getValues();
232233
$this->assertCount(2, $values);
233234
}
@@ -312,22 +313,21 @@ public function testGetDateWithCreatedAndModified()
312313
*/
313314
public function testGetTimestampInvalidWarning()
314315
{
315-
set_error_handler(function ($code, $message) {
316-
throw new \PHPUnit\Framework\Error($message, $code);
317-
});
316+
set_error_handler(
317+
static function ( $errno, $errstr ) {
318+
restore_error_handler();
319+
throw new UserWarning( $errstr, $errno );
320+
},
321+
E_ALL
322+
);
318323

319-
try {
320-
$vocab = $this->model->getVocabulary('test');
321-
322-
$this->expectException(\PHPUnit\Framework\Error::class);
323-
$this->expectExceptionMessage("Failed to parse time string (1986-21-00) at position 6 (1): Unexpected character");
324+
$vocab = $this->model->getVocabulary('test');
324325

325-
$concept = $vocab->getConceptInfo("http://www.skosmos.skos/test/ta114", "en");
326-
$concept->getDate(); # this should throw an ErrorException
326+
$this->expectException(UserWarning::class);
327+
$this->expectExceptionMessage("Failed to parse time string (1986-21-00) at position 6 (1): Unexpected character");
327328

328-
} finally {
329-
restore_error_handler();
330-
}
329+
$concept = $vocab->getConceptInfo("http://www.skosmos.skos/test/ta114", "en");
330+
$concept->getDate(); # this should throw an ErrorException
331331
}
332332

333333
/**
@@ -612,7 +612,7 @@ public function testProcessExternalResource()
612612
* Data provider for testGetModifiedDate test method.
613613
* @return array
614614
*/
615-
public function modifiedDateDataProvider()
615+
public static function modifiedDateDataProvider()
616616
{
617617
return [
618618
["cat", "2018-12-13T06:28:14", "+00:00"], # set #0

tests/ResolverTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ protected function setUp(): void
1919
public function testResolveLOCZeroTimeout()
2020
{
2121
$uri = "http://id.loc.gov/authorities/subjects/sh85016673"; // LCSH: Breakwaters
22-
$resource = $this->resolver->resolve($uri, 0);
22+
// use @ to suppress the timeout warning
23+
@$resource = $this->resolver->resolve($uri, 0);
2324
$this->assertNull($resource);
2425
}
2526

@@ -32,7 +33,8 @@ public function testResolveLOCZeroTimeout()
3233
public function testResolveWDQSZeroTimeout()
3334
{
3435
$uri = "http://www.wikidata.org/entity/Q42"; // Wikidata: Douglas Adams
35-
$resource = $this->resolver->resolve($uri, 0);
36+
// use @ to suppress the timeout warning
37+
@$resource = $this->resolver->resolve($uri, 0);
3638
$this->assertNull($resource);
3739
}
3840

@@ -45,7 +47,8 @@ public function testResolveWDQSZeroTimeout()
4547
public function testResolveLDZeroTimeout()
4648
{
4749
$uri = "http://paikkatiedot.fi/so/1000772/10048472"; // PNR: Ahlainen
48-
$resource = $this->resolver->resolve($uri, 0);
50+
// use @ to suppress the timeout warning
51+
@$resource = $this->resolver->resolve($uri, 0);
4952
$this->assertNull($resource);
5053
}
5154

0 commit comments

Comments
 (0)