From 560fc8114b742ebfdb3197b7cb6f70fa76a08ca1 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Wed, 3 Mar 2021 12:55:25 +0200 Subject: [PATCH 1/4] Upgrade to PHPUnit 8; bump required PHP to 7.2+; try to fix Travis tests on PHP 7.4 --- .travis.yml | 2 -- composer.json | 2 +- tests/ConceptMappingPropertyValueTest.php | 3 ++- tests/ConceptPropertyTest.php | 3 ++- tests/ConceptPropertyValueLiteralTest.php | 3 ++- tests/ConceptPropertyValueTest.php | 3 ++- tests/ConceptSearchParametersTest.php | 6 ++++-- tests/ConceptTest.php | 3 ++- tests/FeedbackTest.php | 3 ++- tests/GenericSparqlTest.php | 3 ++- tests/GlobalConfigTest.php | 2 +- tests/Http304Test.php | 2 +- tests/JenaTextSparqlTest.php | 3 ++- tests/ModelTest.php | 6 ++++-- tests/PluginRegisterTest.php | 3 ++- tests/RequestTest.php | 3 ++- tests/ResolverTest.php | 3 ++- tests/RestControllerTest.php | 6 ++++-- tests/VocabularyCategoryTest.php | 3 ++- tests/VocabularyConfigTest.php | 3 ++- tests/VocabularyTest.php | 3 ++- tests/WebControllerTest.php | 3 ++- 22 files changed, 45 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 86c7dc589..9a9b50b64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ sudo: required dist: trusty language: php php: - - 7.1 - 7.2 - 7.3 - 7.4 @@ -35,6 +34,5 @@ env: matrix: exclude: allow_failures: - - php: 7.4 notifications: slack: kansalliskirjasto:9mOKu3Vws1CIddF5jqWgXbli diff --git a/composer.json b/composer.json index 13fdcb566..2354c2830 100644 --- a/composer.json +++ b/composer.json @@ -80,7 +80,7 @@ "grimmlink/qtip2": "3.0.3" }, "require-dev": { - "phpunit/phpunit": "7.2.0 - 7.5.20", + "phpunit/phpunit": "8.5.*", "umpirsky/twig-gettext-extractor": "1.3.*", "symfony/dom-crawler": "3.4.3", "mockery/mockery": "1.3.1" diff --git a/tests/ConceptMappingPropertyValueTest.php b/tests/ConceptMappingPropertyValueTest.php index 022f58924..11377191e 100644 --- a/tests/ConceptMappingPropertyValueTest.php +++ b/tests/ConceptMappingPropertyValueTest.php @@ -7,7 +7,8 @@ class ConceptMappingPropertyValueTest extends PHPUnit\Framework\TestCase private $vocab; private $props; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); diff --git a/tests/ConceptPropertyTest.php b/tests/ConceptPropertyTest.php index fe2ac300b..b9b55a0c2 100644 --- a/tests/ConceptPropertyTest.php +++ b/tests/ConceptPropertyTest.php @@ -4,7 +4,8 @@ class ConceptPropertyTest extends PHPUnit\Framework\TestCase { private $model; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); diff --git a/tests/ConceptPropertyValueLiteralTest.php b/tests/ConceptPropertyValueLiteralTest.php index fa8ca5d1b..0c36d0d71 100644 --- a/tests/ConceptPropertyValueLiteralTest.php +++ b/tests/ConceptPropertyValueLiteralTest.php @@ -6,7 +6,8 @@ class ConceptPropertyValueLiteralTest extends PHPUnit\Framework\TestCase private $concept; private $vocab; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); diff --git a/tests/ConceptPropertyValueTest.php b/tests/ConceptPropertyValueTest.php index cf0eccb61..6c133e26d 100644 --- a/tests/ConceptPropertyValueTest.php +++ b/tests/ConceptPropertyValueTest.php @@ -6,7 +6,8 @@ class ConceptPropertyValueTest extends PHPUnit\Framework\TestCase private $concept; private $vocab; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); diff --git a/tests/ConceptSearchParametersTest.php b/tests/ConceptSearchParametersTest.php index f6c70694a..dab94397c 100644 --- a/tests/ConceptSearchParametersTest.php +++ b/tests/ConceptSearchParametersTest.php @@ -5,7 +5,8 @@ class ConceptSearchParametersTest extends PHPUnit\Framework\TestCase private $model; private $request; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); @@ -13,7 +14,8 @@ protected function setUp() { $this->model = new Model(new GlobalConfig('/../tests/testconfig.ttl')); } - protected function tearDown() { + protected function tearDown() : void + { $this->params = null; } diff --git a/tests/ConceptTest.php b/tests/ConceptTest.php index 4a1472d81..fa2ed66ec 100644 --- a/tests/ConceptTest.php +++ b/tests/ConceptTest.php @@ -10,7 +10,8 @@ class ConceptTest extends PHPUnit\Framework\TestCase private $cbdVocab; private $cbdGraph; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); diff --git a/tests/FeedbackTest.php b/tests/FeedbackTest.php index 0b2925440..bf4a5d5f6 100644 --- a/tests/FeedbackTest.php +++ b/tests/FeedbackTest.php @@ -7,7 +7,8 @@ class FeedbackTest extends PHPUnit\Framework\TestCase private $model; private $request; - protected function setUp() { + protected function setUp() : void + { $config = new GlobalConfig('/../tests/testconfig-fordefaults.ttl'); $this->model = new Model($config); $this->request = \Mockery::mock('Request', array($this->model))->makePartial(); diff --git a/tests/GenericSparqlTest.php b/tests/GenericSparqlTest.php index e63979917..6ee6df64e 100644 --- a/tests/GenericSparqlTest.php +++ b/tests/GenericSparqlTest.php @@ -8,7 +8,8 @@ class GenericSparqlTest extends PHPUnit\Framework\TestCase private $vocab; private $params; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); diff --git a/tests/GlobalConfigTest.php b/tests/GlobalConfigTest.php index 4db3dda82..a33fa2c3a 100644 --- a/tests/GlobalConfigTest.php +++ b/tests/GlobalConfigTest.php @@ -11,7 +11,7 @@ class GlobalConfigTest extends PHPUnit\Framework\TestCase /** @var GlobalConfig */ private $configWithDefaults; - protected function setUp() + protected function setUp() : void { $this->config = new GlobalConfig('/../tests/testconfig.ttl'); $this->assertNotNull($this->config->getCache()); diff --git a/tests/Http304Test.php b/tests/Http304Test.php index f3d683b59..cbeafe1b0 100644 --- a/tests/Http304Test.php +++ b/tests/Http304Test.php @@ -230,7 +230,7 @@ public function testHttp304() $this->assertEquals("", $content); } - public function tearDown() + public function tearDown() : void { parent::tearDown(); \Mockery::close(); diff --git a/tests/JenaTextSparqlTest.php b/tests/JenaTextSparqlTest.php index e995bc54c..68b9bcc1e 100644 --- a/tests/JenaTextSparqlTest.php +++ b/tests/JenaTextSparqlTest.php @@ -8,7 +8,8 @@ class JenaTextSparqlTest extends PHPUnit\Framework\TestCase private $vocab; private $params; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 1b91bebec..f6299951a 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -5,7 +5,8 @@ class ModelTest extends PHPUnit\Framework\TestCase private $params; private $model; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); @@ -15,7 +16,8 @@ protected function setUp() { $this->params->method('getVocabs')->will($this->returnValue(array($this->model->getVocabulary('test')))); } - protected function tearDown() { + protected function tearDown() : void + { $this->params = null; } diff --git a/tests/PluginRegisterTest.php b/tests/PluginRegisterTest.php index f5ebd030b..a60c86f70 100644 --- a/tests/PluginRegisterTest.php +++ b/tests/PluginRegisterTest.php @@ -6,7 +6,8 @@ class PluginRegisterTest extends PHPUnit\Framework\TestCase private $concept; private $mockpr; - protected function setUp() { + protected function setUp() : void + { $this->mockpr = $this->getMockBuilder('PluginRegister')->setConstructorArgs(array(array('global-plugin')))->setMethods(array('getPlugins'))->getMock(); $stubplugs = array ('test-plugin' => array ( 'js' => array ( 0 => 'first.js', 1 => 'second.min.js', ), 'css' => array ( 0 => 'stylesheet.css', ), 'templates' => array ( 0 => 'template.html', ), ), 'only-css' => array ( 'css' => array ( 0 => 'super.css')), 'global-plugin' => array('js' => array('everywhere.js'))); $this->mockpr->method('getPlugins')->will($this->returnValue($stubplugs)); diff --git a/tests/RequestTest.php b/tests/RequestTest.php index 9c3df3948..b816bd705 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -5,7 +5,8 @@ class RequestTest extends PHPUnit\Framework\TestCase private $model; private $request; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); diff --git a/tests/ResolverTest.php b/tests/ResolverTest.php index 710d8adc3..397db2b2d 100644 --- a/tests/ResolverTest.php +++ b/tests/ResolverTest.php @@ -4,7 +4,8 @@ class ResolverTest extends PHPUnit\Framework\TestCase { private $resolver; - protected function setUp() { + protected function setUp() : void + { $model = new Model(new GlobalConfig('/../tests/testconfig.ttl')); $this->resolver = new Resolver($model); } diff --git a/tests/RestControllerTest.php b/tests/RestControllerTest.php index fbcb2ae9f..a8b6c698d 100644 --- a/tests/RestControllerTest.php +++ b/tests/RestControllerTest.php @@ -15,7 +15,8 @@ class RestControllerTest extends \PHPUnit\Framework\TestCase * @var RestController */ private $controller; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); @@ -28,7 +29,8 @@ protected function setUp() { $this->controller = new RestController($this->model); } - protected function tearDown() { + protected function tearDown() : void + { ob_clean(); } diff --git a/tests/VocabularyCategoryTest.php b/tests/VocabularyCategoryTest.php index 0aaae94fd..cc702e213 100644 --- a/tests/VocabularyCategoryTest.php +++ b/tests/VocabularyCategoryTest.php @@ -5,7 +5,8 @@ class VocabularyCategoryTest extends PHPUnit\Framework\TestCase private $model; private $mockres; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); diff --git a/tests/VocabularyConfigTest.php b/tests/VocabularyConfigTest.php index cc9fd9797..03b344b92 100644 --- a/tests/VocabularyConfigTest.php +++ b/tests/VocabularyConfigTest.php @@ -9,7 +9,8 @@ class VocabularyConfigTest extends PHPUnit\Framework\TestCase * @covers VocabularyConfig::getConfig * @throws Exception */ - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); diff --git a/tests/VocabularyTest.php b/tests/VocabularyTest.php index 8cfe693c1..88358a29b 100644 --- a/tests/VocabularyTest.php +++ b/tests/VocabularyTest.php @@ -7,7 +7,8 @@ class VocabularyTest extends \PHPUnit\Framework\TestCase */ private $model; - protected function setUp() { + protected function setUp() : void + { putenv("LANGUAGE=en_GB.utf8"); putenv("LC_ALL=en_GB.utf8"); setlocale(LC_ALL, 'en_GB.utf8'); diff --git a/tests/WebControllerTest.php b/tests/WebControllerTest.php index 1a9bfcbaf..3acb41b5e 100644 --- a/tests/WebControllerTest.php +++ b/tests/WebControllerTest.php @@ -7,7 +7,8 @@ class WebControllerTest extends TestCase private $webController; private $model; - protected function setUp() { + protected function setUp() : void + { $globalConfig = new GlobalConfig('/../tests/testconfig.ttl'); $this->model = Mockery::mock(new Model($globalConfig)); $this->webController = new WebController($this->model); From 9175e3a3b11babad1b00ec0936659cca4bb18e6c Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Thu, 4 Mar 2021 13:53:38 +0200 Subject: [PATCH 2/4] Robustness fix: avoid accessing null value as an array --- model/sparql/GenericSparql.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/model/sparql/GenericSparql.php b/model/sparql/GenericSparql.php index cedeeb1d9..c302b70b8 100644 --- a/model/sparql/GenericSparql.php +++ b/model/sparql/GenericSparql.php @@ -467,7 +467,11 @@ private function transformConceptInfoResults($result, $uris, $vocabs, $clang) { $conceptArray = array(); foreach ($uris as $index => $uri) { $conc = $result->resource($uri); - $vocab = (isset($vocabs) && sizeof($vocabs) == 1) ? $vocabs[0] : $vocabs[$index]; + if (is_array($vocabs)) { + $vocab = (sizeof($vocabs) == 1) ? $vocabs[0] : $vocabs[$index]; + } else { + $vocab = null; + } $conceptArray[] = new Concept($this->model, $vocab, $conc, $result, $clang); } return $conceptArray; From 10a40cae94dead382fcc29fc00f3fdd93132430d Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Wed, 10 Mar 2021 12:14:58 +0200 Subject: [PATCH 3/4] fix PHPUnit 8 warnings; switch to more specific exception types in a few cases --- model/DataObject.php | 2 +- model/Model.php | 4 ++-- model/VocabularyCategory.php | 2 +- tests/ConceptPropertyValueLiteralTest.php | 4 ++-- tests/ConceptTest.php | 14 +++++++------- tests/DataObjectTest.php | 4 ++-- tests/GenericSparqlTest.php | 6 +++--- tests/JenaTextSparqlTest.php | 4 ++-- tests/ModelTest.php | 10 +++++----- tests/VocabularyCategoryTest.php | 4 ++-- tests/VocabularyConfigTest.php | 12 ++++++++---- 11 files changed, 35 insertions(+), 31 deletions(-) diff --git a/model/DataObject.php b/model/DataObject.php index eded68410..a1359758d 100644 --- a/model/DataObject.php +++ b/model/DataObject.php @@ -27,7 +27,7 @@ class DataObject public function __construct($model, $resource) { if (!($model instanceof Model) || !($resource instanceof EasyRdf\Resource)) { - throw new Exception('Invalid constructor parameter given to DataObject.'); + throw new InvalidArgumentException('Invalid constructor parameter given to DataObject.'); } $this->model = $model; diff --git a/model/Model.php b/model/Model.php index 3c15f365b..a3cc27383 100644 --- a/model/Model.php +++ b/model/Model.php @@ -417,7 +417,7 @@ public function getVocabulary($vocid): Vocabulary return $voc; } } - throw new Exception("Vocabulary id '$vocid' not found in configuration."); + throw new ValueError("Vocabulary id '$vocid' not found in configuration."); } /** @@ -444,7 +444,7 @@ public function getVocabularyByGraph($graph, $endpoint = null) if (array_key_exists($key, $this->vocabsByGraph)) { return $this->vocabsByGraph[$key]; } else { - throw new Exception("no vocabulary found for graph $graph and endpoint $endpoint"); + throw new ValueError("no vocabulary found for graph $graph and endpoint $endpoint"); } } diff --git a/model/VocabularyCategory.php b/model/VocabularyCategory.php index aa80324af..1ef97397f 100644 --- a/model/VocabularyCategory.php +++ b/model/VocabularyCategory.php @@ -8,7 +8,7 @@ class VocabularyCategory extends DataObject public function __construct($model, $resource) { if (!($model instanceof Model)) { - throw new Exception('Invalid constructor parameter given to DataObject.'); + throw new InvalidArgumentException('Invalid constructor parameter given to DataObject.'); } $this->model = $model; diff --git a/tests/ConceptPropertyValueLiteralTest.php b/tests/ConceptPropertyValueLiteralTest.php index 0c36d0d71..9108b4c7a 100644 --- a/tests/ConceptPropertyValueLiteralTest.php +++ b/tests/ConceptPropertyValueLiteralTest.php @@ -48,14 +48,14 @@ public function testGetLabelThatIsADate() { $concepts = $vocab->getConceptInfo("http://www.skosmos.skos/date/d1", "en"); $props = $concepts[0]->getProperties(); $propvals = $props['http://www.skosmos.skos/date/ownDate']->getValues(); - $this->assertContains('8/8/15', $propvals['8/8/15']->getLabel()); + $this->assertStringContainsString('8/8/15', $propvals['8/8/15']->getLabel()); } /** * @covers ConceptPropertyValueLiteral::getLabel - * @expectedException PHPUnit\Framework\Error\Warning */ public function testGetLabelThatIsABrokenDate() { + $this->expectWarning(); $vocab = $this->model->getVocabulary('dates'); $concepts = $vocab->getConceptInfo("http://www.skosmos.skos/date/d2", "en"); $props = $concepts[0]->getProperties(); diff --git a/tests/ConceptTest.php b/tests/ConceptTest.php index fa2ed66ec..0885da8d3 100644 --- a/tests/ConceptTest.php +++ b/tests/ConceptTest.php @@ -284,7 +284,7 @@ public function testGetTimestamp() { $concepts = $vocab->getConceptInfo("http://www.skosmos.skos/test/ta123", "en"); $concept = $concepts[0]; $date = $concept->getDate(); - $this->assertContains('10/1/14', $date); + $this->assertStringContainsString('10/1/14', $date); } /** @@ -295,8 +295,8 @@ public function testGetDateWithCreatedAndModified() { $concepts = $vocab->getConceptInfo("http://www.skosmos.skos/date/d1", "en"); $concept = $concepts[0]; $date = $concept->getDate(); - $this->assertContains('1/3/00', $date); - $this->assertContains('6/6/12', $date); + $this->assertStringContainsString('1/3/00', $date); + $this->assertStringContainsString('6/6/12', $date); } /** @@ -324,7 +324,7 @@ public function testGetTimestampInvalidResult() { $concept = $concepts[0]; # we use @ to suppress the exceptions in order to be able to check the result $date = @$concept->getDate(); - $this->assertContains('1986-21-00', $date); + $this->assertStringContainsString('1986-21-00', $date); } /** @@ -584,9 +584,9 @@ public function testProcessExternalResource() { $concept->processExternalResource($res); $json = $concept->dumpJsonLd(); - $this->assertContains('HY', $json); - $this->assertContains('AK', $json); - $this->assertContains('OS', $json); + $this->assertStringContainsString('HY', $json); + $this->assertStringContainsString('AK', $json); + $this->assertStringContainsString('OS', $json); $contains_count = substr_count($json, "CONTAINS"); $this->assertEquals($contains_count, 3); } diff --git a/tests/DataObjectTest.php b/tests/DataObjectTest.php index d98010371..b87644513 100644 --- a/tests/DataObjectTest.php +++ b/tests/DataObjectTest.php @@ -7,11 +7,11 @@ class DataObjectTest extends PHPUnit\Framework\TestCase /** * @covers DataObject::__construct * @uses DataObject - * @expectedException \Exception - * @expectedExceptionMessage Invalid constructor parameter given to DataObject. */ public function testConstructorNoArguments() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("Invalid constructor parameter given to DataObject"); $obj = new DataObject(null, null); $this->assertNotNull($obj); } diff --git a/tests/GenericSparqlTest.php b/tests/GenericSparqlTest.php index 6ee6df64e..864051fa1 100644 --- a/tests/GenericSparqlTest.php +++ b/tests/GenericSparqlTest.php @@ -366,7 +366,7 @@ public function testQueryConceptsAlphabeticalSpecialChars() { public function testQueryConceptsAlphabeticalNumbers() { $actual = $this->sparql->queryConceptsAlphabetical('0-9', 'en'); $this->assertEquals(1, sizeof($actual)); - $this->assertContains("3D", $actual[0]['prefLabel']); + $this->assertStringContainsString("3D", $actual[0]['prefLabel']); } /** @@ -732,7 +732,7 @@ public function testQueryConceptsAsteriskBeforeTerm() $actual = $this->sparql->queryConcepts(array($voc), null, null, $this->params); $this->assertEquals(3, sizeof($actual)); foreach($actual as $match) - $this->assertContains('bass', $match['prefLabel'], '',true); + $this->assertStringContainsStringIgnoringCase('bass', $match['prefLabel']); } /** @@ -751,7 +751,7 @@ public function testQueryConceptsAsteriskBeforeAndAfterTerm() $actual = $this->sparql->queryConcepts(array($voc), null, null, $this->params); $this->assertEquals(3, sizeof($actual)); foreach($actual as $match) - $this->assertContains('bass', $match['prefLabel'], '',true); + $this->assertStringContainsStringIgnoringCase('bass', $match['prefLabel']); } /** diff --git a/tests/JenaTextSparqlTest.php b/tests/JenaTextSparqlTest.php index 68b9bcc1e..2e9efc86d 100644 --- a/tests/JenaTextSparqlTest.php +++ b/tests/JenaTextSparqlTest.php @@ -271,7 +271,7 @@ public function testQueryConceptsAlphabeticalSpecialChars() { public function testQueryConceptsAlphabeticalNumbers() { $actual = $this->sparql->queryConceptsAlphabetical('0-9', 'en'); $this->assertEquals(1, sizeof($actual)); - $this->assertContains("3D", $actual[0]['prefLabel']); + $this->assertStringContainsString("3D", $actual[0]['prefLabel']); } /** @@ -337,7 +337,7 @@ public function testQueryConceptsAsteriskBeforeTerm() $actual = $this->sparql->queryConcepts(array($voc), null, null, $this->params); $this->assertEquals(3, sizeof($actual)); foreach($actual as $match) - $this->assertContains('bass', $match['prefLabel'], '',true); + $this->assertStringContainsStringIgnoringCase('bass', $match['prefLabel']); } /** diff --git a/tests/ModelTest.php b/tests/ModelTest.php index f6299951a..ff4a00d09 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -76,10 +76,10 @@ public function testGetVocabularyById() { /** * @covers Model::getVocabulary - * @expectedException \Exception - * @expectedExceptionMessage Vocabulary id 'thisshouldnotbefound' not found in configuration */ public function testGetVocabularyByFalseId() { + $this->expectException(ValueError::class); + $this->expectExceptionMessage("Vocabulary id 'thisshouldnotbefound' not found in configuration"); $vocab = $this->model->getVocabulary('thisshouldnotbefound'); $this->assertInstanceOf('Vocabulary', $vocab); } @@ -94,10 +94,10 @@ public function testGetVocabularyByGraphUri() { /** * @covers Model::getVocabularyByGraph - * @expectedException \Exception - * @expectedExceptionMessage no vocabulary found for graph http://no/address and endpoint http://localhost:13030/skosmos-test/sparql */ public function testGetVocabularyByInvalidGraphUri() { + $this->expectException(ValueError::class); + $this->expectExceptionMessage("no vocabulary found for graph http://no/address and endpoint http://localhost:13030/skosmos-test/sparql"); $vocab = $this->model->getVocabularyByGraph('http://no/address'); $this->assertInstanceOf('Vocabulary', $vocab); } @@ -312,7 +312,7 @@ public function testSearchConceptsAndInfoWithOneVocabCaseInsensitivity() { public function testGetRdfCustomPrefix() { $result = $this->model->getRDF('prefix', 'http://www.skosmos.skos/prefix/p1', 'text/turtle'); - $this->assertContains("@prefix my: .", $result); + $this->assertStringContainsString("@prefix my: .", $result); } /** diff --git a/tests/VocabularyCategoryTest.php b/tests/VocabularyCategoryTest.php index cc702e213..3c77a520d 100644 --- a/tests/VocabularyCategoryTest.php +++ b/tests/VocabularyCategoryTest.php @@ -17,10 +17,10 @@ protected function setUp() : void /** * @covers VocabularyCategory::__construct - * @expectedException Exception - * @expectedExceptionMessage Invalid constructor parameter given to DataObject. */ public function testConstructorWithInvalidParameters() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("Invalid constructor parameter given to DataObject"); $vcat = new VocabularyCategory('invalid', 'invalid'); $this->assertNotNull($vcat); } diff --git a/tests/VocabularyConfigTest.php b/tests/VocabularyConfigTest.php index 03b344b92..aa0b43c8e 100644 --- a/tests/VocabularyConfigTest.php +++ b/tests/VocabularyConfigTest.php @@ -112,10 +112,11 @@ public function testGetDefaultLanguage() { /** * @covers VocabularyConfig::getDefaultLanguage - * @expectedException PHPUnit\Framework\Error\Error */ public function testGetDefaultLanguageWhenNotSet() { $vocab = $this->model->getVocabulary('testdiff'); + $this->expectError(); + $this->expectErrorMessage("Default language for vocabulary 'testdiff' unknown, choosing 'en'."); $lang = $vocab->getConfig()->getDefaultLanguage(); } @@ -171,10 +172,11 @@ public function testGetDataURLs() { /** * @covers VocabularyConfig::getDataURLs - * @expectedException PHPUnit\Framework\Error\Warning */ public function testGetDataURLsNotGuessable() { $vocab = $this->model->getVocabulary('test'); + $this->expectWarning(); + $this->expectWarningMessage("Could not guess format for ."); $url = $vocab->getConfig()->getDataURLs(); } @@ -200,10 +202,11 @@ public function testGetDataURLsMarc() { /** * @covers VocabularyConfig::getDataURLs - * @expectedException PHPUnit\Framework\Error\Warning */ public function testGetDataURLsMarcNotDefined() { $vocab = $this->model->getVocabulary('marc-undefined'); + $this->expectWarning(); + $this->expectWarningMessage("Could not guess format for ."); $url = $vocab->getConfig()->getDataURLs(); $this->assertEquals(array(), $url); } @@ -523,10 +526,11 @@ public function testGetPropertyOrderDefault() { /** * @covers VocabularyConfig::getPropertyOrder - * @expectedException PHPUnit\Framework\Error\Error */ public function testGetPropertyOrderUnknown() { $vocab = $this->model->getVocabulary('testUnknownPropertyOrder'); + $this->expectWarning(); + $this->expectWarningMessage("Property order for vocabulary 'testUnknownPropertyOrder' unknown, using default order"); $params = $vocab->getConfig()->getPropertyOrder(); $this->assertEquals(VocabularyConfig::DEFAULT_PROPERTY_ORDER, $params); } From adbe7acaa05f4724938db2b201d1a1e88283ff62 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Wed, 10 Mar 2021 12:52:02 +0200 Subject: [PATCH 4/4] fix PHPUnit warnings on PHP 7.4 (invalid @covers declarations) --- tests/JenaTextSparqlTest.php | 1 - tests/VocabularyTest.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/JenaTextSparqlTest.php b/tests/JenaTextSparqlTest.php index 2e9efc86d..525062e06 100644 --- a/tests/JenaTextSparqlTest.php +++ b/tests/JenaTextSparqlTest.php @@ -183,7 +183,6 @@ public function testQualifiedNotationAlphabeticalList() { /** * @covers JenaTextSparql::queryConceptsAlphabetical * @covers JenaTextSparql::generateAlphabeticalListQuery - * @covers JenaTextSparql::transformAlphabeticalListResults */ public function testQualifiedBroaderAlphabeticalList() { $voc = $this->model->getVocabulary('test-qualified-broader'); diff --git a/tests/VocabularyTest.php b/tests/VocabularyTest.php index 88358a29b..3e333fc1a 100644 --- a/tests/VocabularyTest.php +++ b/tests/VocabularyTest.php @@ -286,7 +286,7 @@ public function testSearchConceptsAlphabeticalQualifiedNotationGeneric() { * @covers Vocabulary::searchConceptsAlphabetical * @covers JenaTextSparql::queryConceptsAlphabetical * @covers JenaTextSparql::generateAlphabeticalListQuery - * @covers JenaTextSparql::transformAlphabeticalListResults + * @covers GenericSparql::transformAlphabeticalListResults */ public function testSearchConceptsAlphabeticalQualifiedNotation() { $vocab = $this->jenamodel->getVocabulary('test-qualified-notation'); @@ -329,7 +329,7 @@ public function testSearchConceptsAlphabeticalQualifiedBroaderGeneric() { * @covers Vocabulary::searchConceptsAlphabetical * @covers JenaTextSparql::queryConceptsAlphabetical * @covers JenaTextSparql::generateAlphabeticalListQuery - * @covers JenaTextSparql::transformAlphabeticalListResults + * @covers GenericSparql::transformAlphabeticalListResults */ public function testSearchConceptsAlphabeticalQualifiedBroader() { $vocab = $this->jenamodel->getVocabulary('test-qualified-broader');