mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
Merge pull request #299 from creative-commoners/pulls/3/sapphire-test-nine
API phpunit 9 support
This commit is contained in:
commit
9de2764faa
@ -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"
|
||||
|
@ -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": {
|
||||
|
@ -1,7 +1,9 @@
|
||||
<phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Default">
|
||||
<directory>tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -27,7 +27,7 @@ class SearchVariantVersionedTest extends SapphireTest
|
||||
SearchVariantVersionedTest_Item::class
|
||||
);
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -15,7 +15,7 @@ class SearchableServiceTest extends SapphireTest
|
||||
|
||||
protected $usesDatabase = true;
|
||||
|
||||
public function setup()
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setup();
|
||||
SearchableService::singleton()->clearCache();
|
||||
|
@ -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',
|
||||
|
@ -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(
|
||||
"<field name='" . SearchUpdaterTest_Container::class . "_Field1' type='text' indexed='true' stored='true'",
|
||||
$schema
|
||||
);
|
||||
$this->assertContains(
|
||||
$this->assertStringContainsString(
|
||||
"<field name='" . SearchUpdaterTest_Container::class . "_Field2' type='text' indexed='true' stored='false'",
|
||||
$schema
|
||||
);
|
||||
@ -350,11 +351,11 @@ class SolrIndexTest extends SapphireTest
|
||||
$index2->addAllFulltextFields();
|
||||
$index2->addStoredField('Field2');
|
||||
$schema2 = $index2->getFieldDefinitions();
|
||||
$this->assertContains(
|
||||
$this->assertStringContainsString(
|
||||
"<field name='" . SearchUpdaterTest_Container::class . "_Field1' type='text' indexed='true' stored='false'",
|
||||
$schema2
|
||||
);
|
||||
$this->assertContains(
|
||||
$this->assertStringContainsString(
|
||||
"<field name='" . SearchUpdaterTest_Container::class . "_Field2' type='text' indexed='true' stored='true'",
|
||||
$schema2
|
||||
);
|
||||
|
@ -36,7 +36,7 @@ class SolrIndexVersionedTest extends SapphireTest
|
||||
SolrIndexVersionedTest_Object::class,
|
||||
];
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
// Need to be set before parent::setUp() since they're executed before the tests start
|
||||
Config::modify()->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();
|
||||
|
@ -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();
|
||||
|
@ -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");
|
||||
|
@ -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');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user