Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to PHPUnit 8; bump required PHP to 7.2+; fix Travis tests on PHP 7.4 #1127

Merged
merged 4 commits into from
Mar 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion model/DataObject.php
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions model/Model.php
Original file line number Diff line number Diff line change
@@ -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");
}

}
2 changes: 1 addition & 1 deletion model/VocabularyCategory.php
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 5 additions & 1 deletion model/sparql/GenericSparql.php
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion tests/ConceptMappingPropertyValueTest.php
Original file line number Diff line number Diff line change
@@ -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');
3 changes: 2 additions & 1 deletion tests/ConceptPropertyTest.php
Original file line number Diff line number Diff line change
@@ -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');
7 changes: 4 additions & 3 deletions tests/ConceptPropertyValueLiteralTest.php
Original file line number Diff line number Diff line change
@@ -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');
@@ -47,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();
3 changes: 2 additions & 1 deletion tests/ConceptPropertyValueTest.php
Original file line number Diff line number Diff line change
@@ -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');
6 changes: 4 additions & 2 deletions tests/ConceptSearchParametersTest.php
Original file line number Diff line number Diff line change
@@ -5,15 +5,17 @@ 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');
$this->request = $this->getMockBuilder('Request')->disableOriginalConstructor()->getMock();
$this->model = new Model(new GlobalConfig('/../tests/testconfig.ttl'));
}

protected function tearDown() {
protected function tearDown() : void
{
$this->params = null;
}

17 changes: 9 additions & 8 deletions tests/ConceptTest.php
Original file line number Diff line number Diff line change
@@ -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');
@@ -283,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);
}

/**
@@ -294,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);
}

/**
@@ -323,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);
}

/**
@@ -583,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);
}
4 changes: 2 additions & 2 deletions tests/DataObjectTest.php
Original file line number Diff line number Diff line change
@@ -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);
}
3 changes: 2 additions & 1 deletion tests/FeedbackTest.php
Original file line number Diff line number Diff line change
@@ -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();
9 changes: 5 additions & 4 deletions tests/GenericSparqlTest.php
Original file line number Diff line number Diff line change
@@ -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');
@@ -365,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']);
}

/**
@@ -731,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']);
}

/**
@@ -750,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']);
}

/**
2 changes: 1 addition & 1 deletion tests/GlobalConfigTest.php
Original file line number Diff line number Diff line change
@@ -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());
2 changes: 1 addition & 1 deletion tests/Http304Test.php
Original file line number Diff line number Diff line change
@@ -230,7 +230,7 @@ public function testHttp304()
$this->assertEquals("", $content);
}

public function tearDown()
public function tearDown() : void
{
parent::tearDown();
\Mockery::close();
8 changes: 4 additions & 4 deletions tests/JenaTextSparqlTest.php
Original file line number Diff line number Diff line change
@@ -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');
@@ -182,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');
@@ -270,7 +270,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']);
}

/**
@@ -336,7 +336,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']);
}

/**
16 changes: 9 additions & 7 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
@@ -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;
}

@@ -74,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);
}
@@ -92,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);
}
@@ -310,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: <http://example.com/myns#> .", $result);
$this->assertStringContainsString("@prefix my: <http://example.com/myns#> .", $result);
}

/**
3 changes: 2 additions & 1 deletion tests/PluginRegisterTest.php
Original file line number Diff line number Diff line change
@@ -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));
3 changes: 2 additions & 1 deletion tests/RequestTest.php
Original file line number Diff line number Diff line change
@@ -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');
Loading