Skip to content

Commit

Permalink
Merge pull request #1725 from NatLibFi/issue1699-upgrade-phpunit-10
Browse files Browse the repository at this point in the history
Upgrade to PHPUnit 10
  • Loading branch information
osma authored Dec 18, 2024
2 parents a060b9b + b9cb29f commit 8e720a6
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 140 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"symfony/twig-bundle": "6.4.*"
},
"require-dev": {
"phpunit/phpunit": "9.6.*",
"phpunit/phpunit": "10.5.*",
"symfony/dom-crawler": "6.4.*",
"symfony/config": "6.4.*",
"symfony/runtime": "6.4.*",
Expand Down
27 changes: 16 additions & 11 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<?xml version="1.0"?>
<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">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src/controller</directory>
<directory suffix=".php">src/model</directory>
<directory suffix=".php">src/model/sparql</directory>
</include>
<exclude>
<directory>vendor</directory>
</exclude>
<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">
<php>
<ini name="date.timezone" value="UTC"/>
</php>
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="./report" lowUpperBound="35" highLowerBound="70"/>
Expand All @@ -17,7 +12,17 @@
<logging/>
<testsuites>
<testsuite name="tests">
<directory suffix=".php">tests</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/controller</directory>
<directory suffix=".php">src/model</directory>
<directory suffix=".php">src/model/sparql</directory>
</include>
<exclude>
<directory>vendor</directory>
</exclude>
</source>
</phpunit>
3 changes: 3 additions & 0 deletions src/model/resolver/LOCResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public function resolve(int $timeout): ?EasyRdf\Resource
'timeout' => $timeout));
$context = stream_context_create($opts);
$fd = fopen($this->uri, 'rb', false, $context);
if ($fd === false) {
return null;
}
$headers = stream_get_meta_data($fd)['wrapper_data'];
foreach ($headers as $header) {
if (strpos(strtolower($header), 'x-preflabel:') === 0) {
Expand Down
26 changes: 13 additions & 13 deletions tests/ConceptPropertyValueLiteralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ public function testGetLabelThatIsADate()
*/
public function testGetLabelThatIsABrokenDate()
{
set_error_handler(function ($code, $message) {
throw new \PHPUnit\Framework\Error($message,$code);
});
set_error_handler(
static function ( $errno, $errstr ) {
restore_error_handler();
throw new UserWarning( $errstr, $errno );
},
E_ALL
);

try {
$vocab = $this->model->getVocabulary('dates');
$vocab = $this->model->getVocabulary('dates');

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

$concept = $vocab->getConceptInfo("http://www.skosmos.skos/date/d2", "en");
$props = $concept->getProperties();
$propvals = $props['http://www.skosmos.skos/date/ownDate']->getValues();
} finally {
restore_error_handler();
}
$concept = $vocab->getConceptInfo("http://www.skosmos.skos/date/d2", "en");
$props = $concept->getProperties();
$propvals = $props['http://www.skosmos.skos/date/ownDate']->getValues();
}

/**
Expand Down
30 changes: 15 additions & 15 deletions tests/ConceptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public function testGetMappingPropertiesWithIdenticalLabels()
{
$vocab = $this->model->getVocabulary('duplicates');
$concept = $vocab->getConceptInfo("http://www.skosmos.skos/dup/d3", "en");
$props = $concept->getMappingProperties();
// suppress fsockopen PHP warnings caused by trying to resolve www.skosmos.skos
@$props = $concept->getMappingProperties();
$values = $props['skos:closeMatch']->getValues();
$this->assertCount(2, $values);
}
Expand Down Expand Up @@ -312,22 +313,21 @@ public function testGetDateWithCreatedAndModified()
*/
public function testGetTimestampInvalidWarning()
{
set_error_handler(function ($code, $message) {
throw new \PHPUnit\Framework\Error($message, $code);
});
set_error_handler(
static function ( $errno, $errstr ) {
restore_error_handler();
throw new UserWarning( $errstr, $errno );
},
E_ALL
);

try {
$vocab = $this->model->getVocabulary('test');

$this->expectException(\PHPUnit\Framework\Error::class);
$this->expectExceptionMessage("Failed to parse time string (1986-21-00) at position 6 (1): Unexpected character");
$vocab = $this->model->getVocabulary('test');

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

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

/**
Expand Down Expand Up @@ -612,7 +612,7 @@ public function testProcessExternalResource()
* Data provider for testGetModifiedDate test method.
* @return array
*/
public function modifiedDateDataProvider()
public static function modifiedDateDataProvider()
{
return [
["cat", "2018-12-13T06:28:14", "+00:00"], # set #0
Expand Down
9 changes: 6 additions & 3 deletions tests/ResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ protected function setUp(): void
public function testResolveLOCZeroTimeout()
{
$uri = "http://id.loc.gov/authorities/subjects/sh85016673"; // LCSH: Breakwaters
$resource = $this->resolver->resolve($uri, 0);
// use @ to suppress the timeout warning
@$resource = $this->resolver->resolve($uri, 0);
$this->assertNull($resource);
}

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

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

Expand Down
Loading

0 comments on commit 8e720a6

Please sign in to comment.