Skip to content

Commit

Permalink
initial upgrade to PHPUnit 10; some warnings and deprecations remain
Browse files Browse the repository at this point in the history
  • Loading branch information
osma committed Dec 17, 2024
1 parent 40ce410 commit 8a2595b
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 105 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
25 changes: 15 additions & 10 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 @@ -20,4 +15,14 @@
<directory suffix=".php">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 Exception( $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(Exception::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
27 changes: 13 additions & 14 deletions tests/ConceptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,22 +312,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 Exception( $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(Exception::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 +611,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
Loading

0 comments on commit 8a2595b

Please sign in to comment.