diff --git a/.travis.yml b/.travis.yml index b070a17..e947f47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,8 @@ env: jobs: include: - php: 7.3 - env: # SUBSITES + env: - DB=MYSQL - REQUIRE_INSTALLER=4.x-dev - PHPUNIT_TEST=1 - - REQUIRE_EXTRA="symbiote/silverstripe-queuedjobs:^4.0 silverstripe/subsites:2.3.x-dev" + - REQUIRE_EXTRA="symbiote/silverstripe-queuedjobs:^4 silverstripe/subsites:^2" diff --git a/composer.json b/composer.json index f6088ad..75183dc 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ } ], "require": { - "php": ">=7.1", - "silverstripe/framework": "^4.0", + "php": "^7.3 || ^8.0", + "silverstripe/framework": "^4.10", "monolog/monolog": "~1.15", "ptcinc/solr-php-client": "^1.0", "symfony/process": "^3.2", @@ -30,7 +30,7 @@ }, "require-dev": { "silverstripe/cms": "^4.0", - "sminnee/phpunit": "^5.7", + "phpunit/phpunit": "^9.5", "squizlabs/php_codesniffer": "^3.0" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c33da18..6f39244 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,9 @@ - - tests/ - + + + tests/ + + diff --git a/tests/BatchedProcessorTest.php b/tests/BatchedProcessorTest.php index b3483da..5b4a935 100644 --- a/tests/BatchedProcessorTest.php +++ b/tests/BatchedProcessorTest.php @@ -42,7 +42,7 @@ class BatchedProcessorTest extends SapphireTest ], ]; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { // Disable illegal extensions if skipping this test if (class_exists(Subsite::class) || !interface_exists(QueuedJob::class)) { @@ -51,7 +51,7 @@ class BatchedProcessorTest extends SapphireTest parent::setUpBeforeClass(); } - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -82,7 +82,7 @@ class BatchedProcessorTest extends SapphireTest SearchUpdater::$processor = new SearchUpdateQueuedJobProcessor(); } - protected function tearDown() + protected function tearDown(): void { if ($this->oldProcessor) { SearchUpdater::$processor = $this->oldProcessor; diff --git a/tests/SearchUpdaterTest.php b/tests/SearchUpdaterTest.php index 5ed97ee..0426233 100644 --- a/tests/SearchUpdaterTest.php +++ b/tests/SearchUpdaterTest.php @@ -21,7 +21,7 @@ class SearchUpdaterTest extends SapphireTest private static $index = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -43,6 +43,7 @@ class SearchUpdaterTest extends SapphireTest { $item = new SearchUpdaterTest_Container(); $item->write(); + $this->assertTrue(true); // TODO: Make sure changing field1 updates item. // TODO: Get updating just field2 to not update item (maybe not possible - variants complicate) diff --git a/tests/SearchVariantSubsitesTest.php b/tests/SearchVariantSubsitesTest.php index 3238f13..d6991a0 100644 --- a/tests/SearchVariantSubsitesTest.php +++ b/tests/SearchVariantSubsitesTest.php @@ -18,13 +18,13 @@ class SearchVariantSubsiteTest extends SapphireTest { private static $index = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); // Check versioned available if (!class_exists(Subsite::class)) { - return $this->markTestSkipped('The subsites module is not installed'); + $this->markTestSkipped('The subsites module is not installed'); } if (self::$index === null) { diff --git a/tests/SearchVariantVersionedTest.php b/tests/SearchVariantVersionedTest.php index 3eb243e..311a8b8 100644 --- a/tests/SearchVariantVersionedTest.php +++ b/tests/SearchVariantVersionedTest.php @@ -27,7 +27,7 @@ class SearchVariantVersionedTest extends SapphireTest SearchVariantVersionedTest_Item::class ); - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/SearchableServiceTest.php b/tests/SearchableServiceTest.php index d4ea572..74a59ec 100644 --- a/tests/SearchableServiceTest.php +++ b/tests/SearchableServiceTest.php @@ -15,7 +15,7 @@ class SearchableServiceTest extends SapphireTest protected $usesDatabase = true; - public function setup() + protected function setUp(): void { parent::setup(); SearchableService::singleton()->clearCache(); diff --git a/tests/SolrIndexSubsitesTest.php b/tests/SolrIndexSubsitesTest.php index 25ee074..167383f 100644 --- a/tests/SolrIndexSubsitesTest.php +++ b/tests/SolrIndexSubsitesTest.php @@ -37,7 +37,7 @@ class SolrIndexSubsitesTest extends SapphireTest protected $server = null; - protected function setUp() + protected function setUp(): void { // Prevent parent::setUp() crashing on db build if (!class_exists(Subsite::class)) { @@ -64,7 +64,7 @@ class SolrIndexSubsitesTest extends SapphireTest SearchUpdater::clear_dirty_indexes(); } - protected function tearDown() + protected function tearDown(): void { if ($this->server) { $_SERVER = $this->server; @@ -221,6 +221,9 @@ class SolrIndexSubsitesTest extends SapphireTest public function testCorrectSubsiteIDOnFileWrite() { $subsiteIDs = ['0'] + $this->allFixtureIDs(Subsite::class); + $subsiteIDs = array_map(function ($v) { + return (string) $v; + }, $subsiteIDs); $mockWrites = [ '35910:File:a:0:{}' => [ 'base' => File::class, @@ -253,7 +256,7 @@ class SolrIndexSubsitesTest extends SapphireTest $this->assertCount(count($subsiteIDs), $mockWrite['statefulids']); foreach ($mockWrite['statefulids'] as $statefulIDs) { $this->assertContains( - $statefulIDs['state'][SearchVariantSubsites::class], + (string) $statefulIDs['state'][SearchVariantSubsites::class], $subsiteIDs, sprintf( 'Failed to assert that %s is in list of valid subsites: %s', diff --git a/tests/SolrIndexTest.php b/tests/SolrIndexTest.php index 34e71a7..ada6dac 100644 --- a/tests/SolrIndexTest.php +++ b/tests/SolrIndexTest.php @@ -4,6 +4,7 @@ namespace SilverStripe\FullTextSearch\Tests; use Apache_Solr_Document; use Page; +use PHPUnit\Framework\MockObject\MockObject; use SilverStripe\Assets\File; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Core\Config\Config; @@ -143,7 +144,7 @@ class SolrIndexTest extends SapphireTest */ public function testBoostedQuery() { - /** @var Solr3Service|PHPUnit_Framework_MockObject_MockObject $serviceMock */ + /** @var Solr3Service|MockObject $serviceMock */ $serviceMock = $this->getMockBuilder(Solr3Service::class) ->setMethods(['search']) ->getMock(); @@ -179,7 +180,7 @@ class SolrIndexTest extends SapphireTest Config::modify()->set(SearchVariantSubsites::class, 'enabled', false); } - /** @var Solr3Service|PHPUnit_Framework_MockObject_MockObject $serviceMock */ + /** @var Solr3Service|MockObject $serviceMock */ $serviceMock = $this->getMockBuilder(Solr3Service::class) ->setMethods(['search']) ->getMock(); @@ -336,11 +337,11 @@ class SolrIndexTest extends SapphireTest $index->addStoredField('Field1'); $index->addFulltextField('Field2'); $schema = $index->getFieldDefinitions(); - $this->assertContains( + $this->assertStringContainsString( "assertContains( + $this->assertStringContainsString( "addAllFulltextFields(); $index2->addStoredField('Field2'); $schema2 = $index2->getFieldDefinitions(); - $this->assertContains( + $this->assertStringContainsString( "assertContains( + $this->assertStringContainsString( "set(SearchVariantSubsites::class, 'enabled', false); @@ -58,7 +58,7 @@ class SolrIndexVersionedTest extends SapphireTest Versioned::set_stage(Versioned::DRAFT); } - protected function tearDown() + protected function tearDown(): void { Versioned::set_reading_mode($this->oldMode); parent::tearDown(); diff --git a/tests/SolrReindexQueuedTest.php b/tests/SolrReindexQueuedTest.php index 7adb103..2f586f6 100644 --- a/tests/SolrReindexQueuedTest.php +++ b/tests/SolrReindexQueuedTest.php @@ -46,13 +46,13 @@ class SolrReindexQueuedTest extends SapphireTest */ protected $service = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); if (!interface_exists(QueuedJob::class)) { $this->skipTest = true; - return $this->markTestSkipped("These tests need the QueuedJobs module installed to run"); + $this->markTestSkipped("These tests need the QueuedJobs module installed to run"); } // Set queued handler for reindex @@ -106,7 +106,7 @@ class SolrReindexQueuedTest extends SapphireTest return $serviceMock; } - protected function tearDown() + protected function tearDown(): void { FullTextSearch::force_index_list(); SolrReindexTest_Variant::disable(); diff --git a/tests/SolrReindexTest.php b/tests/SolrReindexTest.php index 28513b1..bdf98c1 100644 --- a/tests/SolrReindexTest.php +++ b/tests/SolrReindexTest.php @@ -57,7 +57,7 @@ class SolrReindexTest extends SapphireTest */ protected $service = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -111,7 +111,7 @@ class SolrReindexTest extends SapphireTest return $serviceMock->getMock(); } - protected function tearDown() + protected function tearDown(): void { FullTextSearch::force_index_list(); SolrReindexTest_Variant::disable(); @@ -259,7 +259,8 @@ class SolrReindexTest extends SapphireTest // Test that items in this variant / group are re-indexed // 120 divided into 6 groups should be 20 at least (max 21) - $this->assertEquals(21, count($ids), 'Group size is about 20', 1); + $c = count($ids); + $this->assertTrue($c === 20 || $c === 21, 'Group size is about 20'); foreach ($ids as $id) { // Each id should be % 6 == 2 $this->assertEquals(2, $id % 6, "ID $id Should match pattern ID % 6 = 2"); diff --git a/tests/SolrWritersTest.php b/tests/SolrWritersTest.php index 0354f05..779dedf 100644 --- a/tests/SolrWritersTest.php +++ b/tests/SolrWritersTest.php @@ -117,11 +117,9 @@ class SolrWritersTest extends SapphireTest $this->assertEquals(' OR ', $adapter->getConjunctionFor(SearchCriteria::CONJUNCTION_OR)); } - /** - * @expectedException InvalidArgumentException - */ public function testConjunctionFailure() { + $this->expectException(\InvalidArgumentException::class); $adapter = new SolrSearchAdapter(); $adapter->getConjunctionFor('FAIL'); }