diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 03c100040..bbf78b6d5 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -80,7 +80,7 @@ jobs: - name: Run tests run: | vendor/bin/phpstan analyze src/ tests/ --level=1 --memory-limit=1G - vendor/bin/phpunit -c phpunit.xml --exclude-group skip_for_solr_${{ matrix.mode }} -v --coverage-clover build/logs/clover.xml + vendor/bin/phpunit -c phpunit.xml --exclude-group skip_for_solr_${{ matrix.mode }} --coverage-clover build/logs/clover.xml - name: Execute examples run: | diff --git a/.gitignore b/.gitignore index 5b163c9f8..ee8061ec7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ /lucene-solr /vendor .idea -/.phpunit.result.cache +/.phpunit.cache /.php_cs.cache /.phpcs-cache .DS_Store diff --git a/composer.json b/composer.json index 339651ad1..d8d1d3dda 100755 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "phpstan/phpstan": "^1.0", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^10.5", "rawr/phpunit-data-provider": "^3.3", "roave/security-advisories": "dev-master", "symfony/event-dispatcher": "^5.0 || ^6.0 || ^7.0" diff --git a/phpunit.xml b/phpunit.xml index 35f7a1b93..b906d5f42 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,16 +1,18 @@ - - src - @@ -21,6 +23,11 @@ tests + + + src + + diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 0fd928a06..5e255ebd1 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -8,10 +8,7 @@ class ClientTest extends TestCase { - /** - * @var string - */ - protected static $installedVersion; + protected static string $installedVersion; public static function setUpBeforeClass(): void { @@ -23,11 +20,8 @@ public static function setUpBeforeClass(): void ; if (!preg_match($semverRegex, self::$installedVersion)) { - self::assertSame(self::$installedVersion, Client::getVersion()); self::markTestSkipped(sprintf('Skipping tests against non-semantic version string %s.', self::$installedVersion)); } - - parent::setUpBeforeClass(); } public function testGetVersion() diff --git a/tests/Component/Analytics/Facet/ObjectTraitTest.php b/tests/Component/Analytics/Facet/ObjectTraitTest.php index 060bbf9dc..4f2c803e2 100644 --- a/tests/Component/Analytics/Facet/ObjectTraitTest.php +++ b/tests/Component/Analytics/Facet/ObjectTraitTest.php @@ -18,14 +18,21 @@ */ class ObjectTraitTest extends TestCase { + protected object $objectTrait; + + public function setUp(): void + { + $this->objectTrait = new class() { + use ObjectTrait; + }; + } + /** * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testNullReturn(): void { - $mock = $this->getMockForTrait(ObjectTrait::class); - - $this->assertNull($mock->ensureObject(AbstractFacet::class, null)); + $this->assertNull($this->objectTrait->ensureObject(AbstractFacet::class, null)); } /** @@ -34,9 +41,7 @@ public function testNullReturn(): void */ public function testReturnVariable(): void { - $mock = $this->getMockForTrait(ObjectTrait::class); - - $this->assertInstanceOf(PivotFacet::class, $mock->ensureObject(AbstractFacet::class, new PivotFacet())); + $this->assertInstanceOf(PivotFacet::class, $this->objectTrait->ensureObject(AbstractFacet::class, new PivotFacet())); } /** @@ -44,11 +49,8 @@ public function testReturnVariable(): void */ public function testNonExistingClass(): void { - $mock = $this->getMockForTrait(ObjectTrait::class); - $this->expectException(InvalidArgumentException::class); - - $mock->ensureObject('Foo\Bar', new PivotFacet()); + $this->objectTrait->ensureObject('Foo\Bar', new PivotFacet()); } /** @@ -57,9 +59,7 @@ public function testNonExistingClass(): void */ public function testFromArray(): void { - $mock = $this->getMockForTrait(ObjectTrait::class); - - $this->assertInstanceOf(Sort::class, $mock->ensureObject(Sort::class, [])); + $this->assertInstanceOf(Sort::class, $this->objectTrait->ensureObject(Sort::class, [])); } /** @@ -68,9 +68,7 @@ public function testFromArray(): void */ public function testFromClassMap(): void { - $mock = $this->getMockForTrait(ObjectTrait::class); - - $this->assertInstanceOf(PivotFacet::class, $mock->ensureObject(AbstractFacet::class, ['type' => AbstractFacet::TYPE_PIVOT])); + $this->assertInstanceOf(PivotFacet::class, $this->objectTrait->ensureObject(AbstractFacet::class, ['type' => AbstractFacet::TYPE_PIVOT])); } /** @@ -78,11 +76,8 @@ public function testFromClassMap(): void */ public function testInvalidVariableType(): void { - $mock = $this->getMockForTrait(ObjectTrait::class); - $this->expectException(InvalidArgumentException::class); - - $mock->ensureObject(PivotFacet::class, true); + $this->objectTrait->ensureObject(PivotFacet::class, true); } /** @@ -90,9 +85,7 @@ public function testInvalidVariableType(): void */ public function testInvalidMappingType(): void { - $mock = $this->getMockForTrait(ObjectTrait::class); - $this->expectException(InvalidArgumentException::class); - $mock->ensureObject(AbstractFacet::class, ['type' => 'foo']); + $this->objectTrait->ensureObject(AbstractFacet::class, ['type' => 'foo']); } } diff --git a/tests/Component/DisMaxTest.php b/tests/Component/DisMaxTest.php index 9c00272c7..784041b4b 100644 --- a/tests/Component/DisMaxTest.php +++ b/tests/Component/DisMaxTest.php @@ -157,6 +157,11 @@ public function testSetAndGetBoostQuery() ); } + public function testGetBoostQueryWithNonExistentKey() + { + $this->assertNull($this->disMax->getBoostQuery('foobar')); + } + public function testAddBoostQueryWithArray() { $query = 'cat:1^3'; @@ -249,6 +254,69 @@ public function testAddBoostQueriesWithOuterKeys() $this->assertEquals($bqs2, $this->disMax->getBoostQueries()); } + public function testRemoveBoostQueryByKey() + { + $bqs = [ + 'key1' => ['query' => 'cat:1'], + 'key2' => ['query' => 'cat:2'], + ]; + + $this->disMax->addBoostQueries($bqs); + $this->disMax->removeBoostQuery('key1'); + + $this->assertNull($this->disMax->getBoostQuery('key1')); + $this->assertNotNull($this->disMax->getBoostQuery('key2')); + } + + public function testRemoveBoostQueryByObject() + { + $bq1 = new BoostQuery(); + $bq1->setKey('key1')->setQuery('cat:1'); + + $bq2 = new BoostQuery(); + $bq2->setKey('key2')->setQuery('cat:2'); + + $this->disMax->addBoostQueries([$bq1, $bq2]); + $this->disMax->removeBoostQuery($bq1); + + $this->assertNull($this->disMax->getBoostQuery('key1')); + $this->assertNotNull($this->disMax->getBoostQuery('key2')); + } + + public function testClearBoostQueries() + { + $bqs = [ + 'key1' => ['query' => 'cat:1'], + 'key2' => ['query' => 'cat:2'], + ]; + + $this->disMax->addBoostQueries($bqs); + $this->disMax->clearBoostQueries(); + + $this->assertCount(0, $this->disMax->getBoostQueries()); + } + + public function testSetBoostQueries() + { + $bqs1 = [ + 'key1' => (new BoostQuery())->setKey('key1')->setQuery('cat:1'), + 'key2' => (new BoostQuery())->setKey('key2')->setQuery('cat:2'), + ]; + + $this->disMax->setBoostQueries($bqs1); + + $this->assertSame($bqs1, $this->disMax->getBoostQueries()); + + $bqs2 = [ + 'key3' => (new BoostQuery())->setKey('key3')->setQuery('cat:3'), + 'key4' => (new BoostQuery())->setKey('key4')->setQuery('cat:4'), + ]; + + $this->disMax->setBoostQueries($bqs2); + + $this->assertSame($bqs2, $this->disMax->getBoostQueries()); + } + public function testSetAndGetBoostFunctions() { $value = 'funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2'; diff --git a/tests/Component/Facet/PivotTest.php b/tests/Component/Facet/PivotTest.php index 1adb59adb..0c937da86 100644 --- a/tests/Component/Facet/PivotTest.php +++ b/tests/Component/Facet/PivotTest.php @@ -145,14 +145,16 @@ public function testAddStat() { $expectedStats = $this->facet->getLocalParameters()->getStats(); $expectedStats[] = 'newstat'; - $this->facet->getLocalParameters()->setStat('newstat'); + $this->facet->addStat('newstat'); + $this->assertSame($expectedStats, $this->facet->getStats()); $this->assertSame($expectedStats, $this->facet->getLocalParameters()->getStats()); } public function testClearStats() { - $this->facet->getLocalParameters()->setStat('newstat'); - $this->facet->getLocalParameters()->clearStats(); + $this->facet->addStat('newstat'); + $this->facet->clearStats(); + $this->assertSame([], $this->facet->getStats()); $this->assertSame([], $this->facet->getLocalParameters()->getStats()); } @@ -160,24 +162,35 @@ public function testAddStats() { $stats = ['stat1', 'stat2']; - $this->facet->getLocalParameters()->clearStats(); - $this->facet->getLocalParameters()->addStats($stats); + $this->facet->clearStats(); + $this->facet->addStats($stats); + $this->assertSame($stats, $this->facet->getStats()); $this->assertSame($stats, $this->facet->getLocalParameters()->getStats()); } + public function testAddStatsAsString() + { + $this->facet->clearStats(); + $this->facet->addStats('stat1, stat2'); + $this->assertSame(['stat1', 'stat2'], $this->facet->getStats()); + $this->assertSame(['stat1', 'stat2'], $this->facet->getLocalParameters()->getStats()); + } + public function testRemoveStat() { - $this->facet->getLocalParameters()->clearStats(); - $this->facet->getLocalParameters()->addStats(['stat1', 'stat2']); - $this->facet->getLocalParameters()->removeStat('stat1'); + $this->facet->clearStats(); + $this->facet->addStats(['stat1', 'stat2']); + $this->facet->removeStat('stat1'); + $this->assertSame(['stat2'], $this->facet->getStats()); $this->assertSame(['stat2'], $this->facet->getLocalParameters()->getStats()); } public function testSetStats() { - $this->facet->getLocalParameters()->clearStats(); - $this->facet->getLocalParameters()->setStats(['stat1', 'stat2']); - $this->facet->getLocalParameters()->setStats(['stat3', 'stat4']); + $this->facet->clearStats(); + $this->facet->setStats(['stat1', 'stat2']); + $this->facet->setStats(['stat3', 'stat4']); $this->assertSame(['stat3', 'stat4'], $this->facet->getStats()); + $this->assertSame(['stat3', 'stat4'], $this->facet->getLocalParameters()->getStats()); } } diff --git a/tests/Component/FacetSetTest.php b/tests/Component/FacetSetTest.php index 051d9e830..241631c82 100644 --- a/tests/Component/FacetSetTest.php +++ b/tests/Component/FacetSetTest.php @@ -427,7 +427,7 @@ public function testCreateFacetWithInvalidType() $this->facetSet->createFacet('invalidtype'); } - public function createFacetAddProvider() + public static function createFacetAddProvider(): array { return [ [true], diff --git a/tests/Component/ResponseParser/AnalyticsTest.php b/tests/Component/ResponseParser/AnalyticsTest.php index ac4eaa5eb..260dfc254 100644 --- a/tests/Component/ResponseParser/AnalyticsTest.php +++ b/tests/Component/ResponseParser/AnalyticsTest.php @@ -102,8 +102,8 @@ public function testParseData(): void $parser = new ResponseParser(); $result = $parser->parse(null, $component, $data); - $this->assertCount(\count($result->getResults()), $result); - $this->assertCount(\count($result->getIterator()), $result); + $this->assertSameSize($result->getResults(), $result); + $this->assertSameSize($result->getIterator(), $result); $this->assertArrayHasKey('geo_sales', $result->getGroupings()); $this->assertInstanceOf(AnalyticsResult::class, $result); @@ -123,8 +123,8 @@ public function testParseData(): void $this->assertSame('country', $facets[0]->getPivot()); $this->assertSame('usa', $facets[0]->getValue()); - $this->assertCount(\count($facets[0]->getResults()), $facets[0]); - $this->assertCount(\count($facets[0]->getIterator()), $facets[0]); + $this->assertSameSize($facets[0]->getResults(), $facets[0]); + $this->assertSameSize($facets[0]->getIterator(), $facets[0]); $this->assertCount(1, $facets[0]->getChildren()); $this->assertCount(1, $facets[0]->getChildren()[0]->getChildren()); diff --git a/tests/Component/ResponseParser/SpellcheckTest.php b/tests/Component/ResponseParser/SpellcheckTest.php index 256d9ec31..910493d59 100644 --- a/tests/Component/ResponseParser/SpellcheckTest.php +++ b/tests/Component/ResponseParser/SpellcheckTest.php @@ -56,7 +56,7 @@ public function testParseExtended($data) ); } - public function providerParseExtended() + public static function providerParseExtended(): array { return [ 'solr4' => [ @@ -237,7 +237,7 @@ public function testParse($data) $this->assertEquals('dell ultrasharp new', $collations[1]->getQuery()); } - public function providerParse() + public static function providerParse(): array { return [ 'solr4' => [ @@ -333,7 +333,7 @@ public function testParseSingleCollation($data) $this->assertEquals(['word' => 'ultrasharpy', 'freq' => 1], $words[1]); } - public function providerParseSingleCollation() + public static function providerParseSingleCollation(): array { return [ 'solr4' => [ diff --git a/tests/Component/ResponseParser/SuggesterTest.php b/tests/Component/ResponseParser/SuggesterTest.php index 54ef90196..510764aa6 100644 --- a/tests/Component/ResponseParser/SuggesterTest.php +++ b/tests/Component/ResponseParser/SuggesterTest.php @@ -51,7 +51,7 @@ public function testParse($data) $this->assertEquals($allExpected, $result->getAll()); } - public function providerParse() + public static function providerParse(): array { return [ 0 => [ diff --git a/tests/Component/ResponseParser/TermVectorTest.php b/tests/Component/ResponseParser/TermVectorTest.php index e45608788..8b230f713 100644 --- a/tests/Component/ResponseParser/TermVectorTest.php +++ b/tests/Component/ResponseParser/TermVectorTest.php @@ -233,7 +233,7 @@ public function testParseWtPhps(Result $expectedResult) $this->assertEquals($expectedResult, $result); } - public function expectedResultProvider(): array + public static function expectedResultProvider(): array { $result = new Result( [ @@ -358,7 +358,7 @@ public function testParseAmbiguousKeysWtPhps(Result $expectedResult) $this->assertEquals($expectedResult, $result); } - public function expectedResultAmbiguousKeysProvider(): array + public static function expectedResultAmbiguousKeysProvider(): array { $result = new Result( [ @@ -457,7 +457,7 @@ public function testParseDoubleKeysWtPhps(Result $expectedResult) $this->assertEquals($expectedResult, $result); } - public function expectedResultDoubleKeysProvider(): array + public static function expectedResultDoubleKeysProvider(): array { $result = new Result( [ @@ -540,7 +540,7 @@ public function testParseNoDocumentsWtPhps(Result $expectedResult) $this->assertEquals($expectedResult, $result); } - public function expectedResultNoDocumentsProvider(): array + public static function expectedResultNoDocumentsProvider(): array { $result = new Result( [], diff --git a/tests/Component/Result/Debug/DebugTest.php b/tests/Component/Result/Debug/DebugTest.php index d570c58f8..84862e839 100644 --- a/tests/Component/Result/Debug/DebugTest.php +++ b/tests/Component/Result/Debug/DebugTest.php @@ -99,6 +99,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->explain), $this->result); + $this->assertSameSize($this->explain, $this->result); } } diff --git a/tests/Component/Result/Debug/DocumentSetTest.php b/tests/Component/Result/Debug/DocumentSetTest.php index 92287bf22..580fb6364 100644 --- a/tests/Component/Result/Debug/DocumentSetTest.php +++ b/tests/Component/Result/Debug/DocumentSetTest.php @@ -59,6 +59,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->docs), $this->result); + $this->assertSameSize($this->docs, $this->result); } } diff --git a/tests/Component/Result/Debug/DocumentTest.php b/tests/Component/Result/Debug/DocumentTest.php index 7acd73441..1d74abdde 100644 --- a/tests/Component/Result/Debug/DocumentTest.php +++ b/tests/Component/Result/Debug/DocumentTest.php @@ -61,7 +61,7 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->details), $this->result); + $this->assertSameSize($this->details, $this->result); } public function testToString() diff --git a/tests/Component/Result/Debug/TimingPhaseTest.php b/tests/Component/Result/Debug/TimingPhaseTest.php index 44038dbff..2247bdb1e 100644 --- a/tests/Component/Result/Debug/TimingPhaseTest.php +++ b/tests/Component/Result/Debug/TimingPhaseTest.php @@ -69,6 +69,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->timings), $this->result); + $this->assertSameSize($this->timings, $this->result); } } diff --git a/tests/Component/Result/Debug/TimingTest.php b/tests/Component/Result/Debug/TimingTest.php index 7faa02b32..d88a5cd68 100644 --- a/tests/Component/Result/Debug/TimingTest.php +++ b/tests/Component/Result/Debug/TimingTest.php @@ -70,6 +70,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->phases), $this->result); + $this->assertSameSize($this->phases, $this->result); } } diff --git a/tests/Component/Result/MoreLikeThis/MoreLikeThisTest.php b/tests/Component/Result/MoreLikeThis/MoreLikeThisTest.php index 1ea6d441b..5586a75fa 100644 --- a/tests/Component/Result/MoreLikeThis/MoreLikeThisTest.php +++ b/tests/Component/Result/MoreLikeThis/MoreLikeThisTest.php @@ -109,6 +109,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->results), $this->mlt); + $this->assertSameSize($this->results, $this->mlt); } } diff --git a/tests/Component/Result/MoreLikeThis/ResultTest.php b/tests/Component/Result/MoreLikeThis/ResultTest.php index 89ef55fec..48bb939fe 100644 --- a/tests/Component/Result/MoreLikeThis/ResultTest.php +++ b/tests/Component/Result/MoreLikeThis/ResultTest.php @@ -55,6 +55,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->docs), $this->mltResult); + $this->assertSameSize($this->docs, $this->mltResult); } } diff --git a/tests/Component/Result/Spellcheck/CollationTest.php b/tests/Component/Result/Spellcheck/CollationTest.php index ed45cd2d7..e8c8afe70 100644 --- a/tests/Component/Result/Spellcheck/CollationTest.php +++ b/tests/Component/Result/Spellcheck/CollationTest.php @@ -57,6 +57,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->corrections), $this->result); + $this->assertSameSize($this->corrections, $this->result); } } diff --git a/tests/Component/Result/Spellcheck/SpellcheckTest.php b/tests/Component/Result/Spellcheck/SpellcheckTest.php index 7c2127407..096dbcf25 100644 --- a/tests/Component/Result/Spellcheck/SpellcheckTest.php +++ b/tests/Component/Result/Spellcheck/SpellcheckTest.php @@ -89,6 +89,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->suggestions), $this->result); + $this->assertSameSize($this->suggestions, $this->result); } } diff --git a/tests/Component/Result/Suggester/ResultTest.php b/tests/Component/Result/Suggester/ResultTest.php index fabcdbeb3..80d35ff23 100644 --- a/tests/Component/Result/Suggester/ResultTest.php +++ b/tests/Component/Result/Suggester/ResultTest.php @@ -57,6 +57,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->docs), $this->result); + $this->assertSameSize($this->docs, $this->result); } } diff --git a/tests/Component/Stats/StatsTest.php b/tests/Component/Stats/StatsTest.php index 49df9bef3..37fbbc826 100644 --- a/tests/Component/Stats/StatsTest.php +++ b/tests/Component/Stats/StatsTest.php @@ -62,7 +62,7 @@ public function testCreateFieldWithKey() $field = $this->stats->createField('mykey'); // check class - $this->assertThat($field, $this->isInstanceOf('Solarium\Component\Stats\Field')); + $this->assertInstanceOf(Field::class, $field); $this->assertSame( 'mykey', @@ -76,7 +76,7 @@ public function testCreateFieldWithOptions() $field = $this->stats->createField($options); // check class - $this->assertThat($field, $this->isInstanceOf('Solarium\Component\Stats\Field')); + $this->assertInstanceOf(Field::class, $field); // check option forwarding $fieldOptions = $field->getOptions(); diff --git a/tests/Component/SuggesterTest.php b/tests/Component/SuggesterTest.php index 76b2f565a..76b80a8a9 100644 --- a/tests/Component/SuggesterTest.php +++ b/tests/Component/SuggesterTest.php @@ -123,4 +123,15 @@ public function testSetAndGetCount() $this->suggester->getCount() ); } + + public function testSetAndGetBuildAll() + { + $value = true; + $this->suggester->setBuildAll($value); + + $this->assertEquals( + $value, + $this->suggester->getBuildAll() + ); + } } diff --git a/tests/Core/Client/Adapter/CurlTest.php b/tests/Core/Client/Adapter/CurlTest.php index d6f5dc627..86a61b2cc 100644 --- a/tests/Core/Client/Adapter/CurlTest.php +++ b/tests/Core/Client/Adapter/CurlTest.php @@ -11,6 +11,9 @@ use Solarium\Exception\HttpException; use Solarium\Exception\InvalidArgumentException; +/** + * @requires extension curl + */ class CurlTest extends TestCase { use TimeoutAwareTestTrait; @@ -24,10 +27,6 @@ class CurlTest extends TestCase public function setUp(): void { - if (!\function_exists('curl_init')) { - $this->markTestSkipped('cURL not available, skipping cURL adapter tests.'); - } - $this->adapter = new Curl(); } @@ -131,7 +130,7 @@ public function testCreateHandleForRequestMethod(string $method) curl_close($handle); } - public function methodProvider(): array + public static function methodProvider(): array { return [ [Request::METHOD_GET], diff --git a/tests/Core/Client/ClientTest.php b/tests/Core/Client/ClientTest.php index d44a360e8..e2e78e891 100644 --- a/tests/Core/Client/ClientTest.php +++ b/tests/Core/Client/ClientTest.php @@ -91,7 +91,7 @@ public function testConfigMode() $adapter = $this->client->getAdapter(); - $this->assertThat($adapter, $this->isInstanceOf(MyAdapter::class)); + $this->assertInstanceOf(MyAdapter::class, $adapter); $this->assertSame(8080, $this->client->getEndpoint('myhost')->getPort()); $queryTypes = $this->client->getQueryTypes(); @@ -101,7 +101,7 @@ public function testConfigMode() ); $plugin = $this->client->getPlugin('myplugin'); - $this->assertThat($plugin, $this->isInstanceOf(MyClientPlugin::class)); + $this->assertInstanceOf(MyClientPlugin::class, $plugin); $this->assertSame($options['plugin']['myplugin']['options'], $plugin->getOptions()); } @@ -153,7 +153,7 @@ public function testConfigModeWithoutKeys() $adapter = $this->client->getAdapter(); - $this->assertThat($adapter, $this->isInstanceOf(MyAdapter::class)); + $this->assertInstanceOf(MyAdapter::class, $adapter); $this->assertSame(8080, $this->client->getEndpoint('myhost')->getPort()); $queryTypes = $this->client->getQueryTypes(); @@ -163,7 +163,7 @@ public function testConfigModeWithoutKeys() ); $plugin = $this->client->getPlugin('myplugin'); - $this->assertThat($plugin, $this->isInstanceOf(MyClientPlugin::class)); + $this->assertInstanceOf(MyClientPlugin::class, $plugin); $this->assertSame($options['plugin'][0]['options'], $plugin->getOptions()); } @@ -171,14 +171,14 @@ public function testCreateEndpoint() { $endpoint = $this->client->createEndpoint(); $this->assertNull($endpoint->getKey()); - $this->assertThat($endpoint, $this->isInstanceOf(Endpoint::class)); + $this->assertInstanceOf(Endpoint::class, $endpoint); } public function testCreateEndpointWithKey() { $endpoint = $this->client->createEndpoint('key1'); $this->assertSame('key1', $endpoint->getKey()); - $this->assertThat($endpoint, $this->isInstanceOf(Endpoint::class)); + $this->assertInstanceOf(Endpoint::class, $endpoint); } public function testCreateEndpointWithSetAsDefault() @@ -198,7 +198,7 @@ public function testCreateEndpointWithArray() $endpoint = $this->client->createEndpoint($options); $this->assertSame('server2', $endpoint->getKey()); $this->assertSame('s2.local', $endpoint->getHost()); - $this->assertThat($endpoint, $this->isInstanceOf(Endpoint::class)); + $this->assertInstanceOf(Endpoint::class, $endpoint); } public function testAddAndGetEndpoint() @@ -374,7 +374,7 @@ public function testSetAndGetAdapterWithObject() { $adapterClass = MyAdapter::class; $this->client->setAdapter(new $adapterClass()); - $this->assertThat($this->client->getAdapter(), $this->isInstanceOf($adapterClass)); + $this->assertInstanceOf($adapterClass, $this->client->getAdapter()); } public function testRegisterQueryTypeAndGetQueryTypes() @@ -397,16 +397,8 @@ public function testRegisterAndGetPlugin() $this->client->registerPlugin('testplugin', MyClientPlugin::class, $options); $plugin = $this->client->getPlugin('testplugin'); - - $this->assertThat( - $plugin, - $this->isInstanceOf(MyClientPlugin::class) - ); - - $this->assertSame( - $options, - $plugin->getOptions() - ); + $this->assertInstanceOf(MyClientPlugin::class, $plugin); + $this->assertSame($options, $plugin->getOptions()); } public function testRegisterInvalidPlugin() @@ -425,10 +417,7 @@ public function testGetInvalidPlugin() public function testAutoloadPlugin() { $loadbalancer = $this->client->getPlugin('loadbalancer'); - $this->assertThat( - $loadbalancer, - $this->isInstanceOf(Loadbalancer::class) - ); + $this->assertInstanceOf(Loadbalancer::class, $loadbalancer); } public function testAutoloadInvalidPlugin() @@ -519,13 +508,16 @@ public function testCreateRequestPrePlugin() $expectedEvent->setName(Events::PRE_CREATE_REQUEST); } - $observer = $this->getMockBuilder(AbstractPlugin::class) - ->addMethods(['preCreateRequest']) - ->getMock(); - /* @phpstan-ignore-next-line */ - $observer->expects($this->once()) - ->method('preCreateRequest') - ->with($this->equalTo($expectedEvent)); + $observer = new class() extends AbstractPlugin { + public PreCreateRequestEvent $event; + + public function preCreateRequest(PreCreateRequestEvent $event): self + { + $this->event = $event; + + return $this; + } + }; $this->client->registerPlugin('testplugin', $observer); $this->client->getEventDispatcher()->addListener( @@ -534,6 +526,7 @@ public function testCreateRequestPrePlugin() ); $this->client->createRequest($query); + $this->assertEquals($expectedEvent, $observer->event); } public function testCreateRequestPostPlugin() @@ -546,13 +539,16 @@ public function testCreateRequestPostPlugin() $expectedEvent->setName(Events::POST_CREATE_REQUEST); } - $observer = $this->getMockBuilder(AbstractPlugin::class) - ->addMethods(['postCreateRequest']) - ->getMock(); - /* @phpstan-ignore-next-line */ - $observer->expects($this->once()) - ->method('postCreateRequest') - ->with($this->equalTo($expectedEvent)); + $observer = new class() extends AbstractPlugin { + public PostCreateRequestEvent $event; + + public function postCreateRequest(PostCreateRequestEvent $event): self + { + $this->event = $event; + + return $this; + } + }; $this->client->registerPlugin('testplugin', $observer); $this->client->getEventDispatcher()->addListener( @@ -561,6 +557,7 @@ public function testCreateRequestPostPlugin() ); $this->client->createRequest($query); + $this->assertEquals($expectedEvent, $observer->event); } public function testCreateRequestWithOverridingPlugin() @@ -598,10 +595,7 @@ public function testCreateResult() $response = new Response('', ['HTTP/1.0 200 OK']); $result = $this->client->createResult($query, $response); - $this->assertThat( - $result, - $this->isInstanceOf($query->getResultClass()) - ); + $this->assertInstanceOf($query->getResultClass(), $result); } public function testCreateResultPrePlugin() @@ -614,13 +608,16 @@ public function testCreateResultPrePlugin() $expectedEvent->setName(Events::PRE_CREATE_RESULT); } - $observer = $this->getMockBuilder(AbstractPlugin::class) - ->addMethods(['preCreateResult']) - ->getMock(); - /* @phpstan-ignore-next-line */ - $observer->expects($this->once()) - ->method('preCreateResult') - ->with($this->equalTo($expectedEvent)); + $observer = new class() extends AbstractPlugin { + public PreCreateResultEvent $event; + + public function preCreateResult(PreCreateResultEvent $event): self + { + $this->event = $event; + + return $this; + } + }; $this->client->registerPlugin('testplugin', $observer); $this->client->getEventDispatcher()->addListener( @@ -629,6 +626,7 @@ public function testCreateResultPrePlugin() ); $this->client->createResult($query, $response); + $this->assertEquals($expectedEvent, $observer->event); } public function testCreateResultPostPlugin() @@ -641,13 +639,17 @@ public function testCreateResultPostPlugin() $expectedEvent->setDispatcher($this->client->getEventDispatcher()); $expectedEvent->setName(Events::POST_CREATE_RESULT); } - $observer = $this->getMockBuilder(AbstractPlugin::class) - ->addMethods(['postCreateResult']) - ->getMock(); - /* @phpstan-ignore-next-line */ - $observer->expects($this->once()) - ->method('postCreateResult') - ->with($this->equalTo($expectedEvent)); + + $observer = new class() extends AbstractPlugin { + public PostCreateResultEvent $event; + + public function postCreateResult(PostCreateResultEvent $event): self + { + $this->event = $event; + + return $this; + } + }; $this->client->registerPlugin('testplugin', $observer); $this->client->getEventDispatcher()->addListener( @@ -656,6 +658,7 @@ public function testCreateResultPostPlugin() ); $this->client->createResult($query, $response); + $this->assertEquals($expectedEvent, $observer->event); } public function testCreateResultWithOverridingPlugin() @@ -751,13 +754,16 @@ public function testExecutePrePlugin() ->method('createResult') ->willReturn($result); - $observer = $this->getMockBuilder(AbstractPlugin::class) - ->addMethods(['preExecute']) - ->getMock(); - /* @phpstan-ignore-next-line */ - $observer->expects($this->once()) - ->method('preExecute') - ->with($this->equalTo($expectedEvent)); + $observer = new class() extends AbstractPlugin { + public PreExecuteEvent $event; + + public function preExecute(PreExecuteEvent $event): self + { + $this->event = $event; + + return $this; + } + }; $mock->getEventDispatcher()->addListener(Events::PRE_EXECUTE, [$observer, 'preExecute']); @@ -767,6 +773,7 @@ public function testExecutePrePlugin() } $mock->execute($query); + $this->assertEquals($expectedEvent, $observer->event); } public function testExecutePostPlugin() @@ -793,13 +800,16 @@ public function testExecutePostPlugin() ->method('createResult') ->willReturn($result); - $observer = $this->getMockBuilder(AbstractPlugin::class) - ->addMethods(['postExecute']) - ->getMock(); - /* @phpstan-ignore-next-line */ - $observer->expects($this->once()) - ->method('postExecute') - ->with($this->equalTo($expectedEvent)); + $observer = new class() extends AbstractPlugin { + public PostExecuteEvent $event; + + public function postExecute(PostExecuteEvent $event): self + { + $this->event = $event; + + return $this; + } + }; $mock->getEventDispatcher()->addListener(Events::POST_EXECUTE, [$observer, 'postExecute']); @@ -809,6 +819,7 @@ public function testExecutePostPlugin() } $mock->execute($query); + $this->assertEquals($expectedEvent, $observer->event); } public function testExecuteWithOverridingPlugin() @@ -881,19 +892,24 @@ public function testExecuteRequestPrePlugin() ->willReturn($response); $this->client->setAdapter($mockAdapter); - $observer = $this->getMockBuilder(AbstractPlugin::class) - ->addMethods(['preExecuteRequest']) - ->getMock(); - /* @phpstan-ignore-next-line */ - $observer->expects($this->once()) - ->method('preExecuteRequest') - ->with($this->equalTo($expectedEvent)); + $observer = new class() extends AbstractPlugin { + public PreExecuteRequestEvent $event; + + public function preExecuteRequest(PreExecuteRequestEvent $event): self + { + $this->event = $event; + + return $this; + } + }; $this->client->getEventDispatcher()->addListener( Events::PRE_EXECUTE_REQUEST, [$observer, 'preExecuteRequest'] ); + $this->client->executeRequest($request, $endpoint); + $this->assertEquals($expectedEvent, $observer->event); } public function testExecuteRequestPostPlugin() @@ -916,19 +932,24 @@ public function testExecuteRequestPostPlugin() ->willReturn($response); $this->client->setAdapter($mockAdapter); - $observer = $this->getMockBuilder(AbstractPlugin::class) - ->addMethods(['postExecuteRequest']) - ->getMock(); - /* @phpstan-ignore-next-line */ - $observer->expects($this->once()) - ->method('postExecuteRequest') - ->with($this->equalTo($expectedEvent)); + $observer = new class() extends AbstractPlugin { + public PostExecuteRequestEvent $event; + + public function postExecuteRequest(PostExecuteRequestEvent $event): self + { + $this->event = $event; + + return $this; + } + }; $this->client->getEventDispatcher()->addListener( Events::POST_EXECUTE_REQUEST, [$observer, 'postExecuteRequest'] ); + $this->client->executeRequest($request, $endpoint); + $this->assertEquals($expectedEvent, $observer->event); } public function testExecuteRequestWithOverridingPlugin() @@ -1189,7 +1210,7 @@ public function testCreateQuery() $query = $this->client->createQuery(Client::QUERY_SELECT, $options); // check class mapping - $this->assertThat($query, $this->isInstanceOf('Solarium\QueryType\Select\Query\Query')); + $this->assertInstanceOf(SelectQuery::class, $query); // check option forwarding $queryOptions = $query->getOptions(); @@ -1222,16 +1243,24 @@ public function testCreateQueryPrePlugin() $expectedEvent->setName(Events::PRE_CREATE_QUERY); } - $observer = $this->getMockBuilder(AbstractPlugin::class) - ->addMethods(['preCreateQuery']) - ->getMock(); - /* @phpstan-ignore-next-line */ - $observer->expects($this->once()) - ->method('preCreateQuery') - ->with($this->equalTo($expectedEvent)); + $observer = new class() extends AbstractPlugin { + public PreCreateQueryEvent $event; + + public function preCreateQuery(PreCreateQueryEvent $event): self + { + $this->event = $event; + + return $this; + } + }; + + $this->client->getEventDispatcher()->addListener( + Events::PRE_CREATE_QUERY, + [$observer, 'preCreateQuery'] + ); - $this->client->getEventDispatcher()->addListener(Events::PRE_CREATE_QUERY, [$observer, 'preCreateQuery']); $this->client->createQuery($type, $options); + $this->assertEquals($expectedEvent, $observer->event); } public function testCreateQueryWithOverridingPlugin() @@ -1274,13 +1303,16 @@ public function testCreateQueryPostPlugin() $expectedEvent->setName(Events::POST_CREATE_QUERY); } - $observer = $this->getMockBuilder(AbstractPlugin::class) - ->addMethods(['postCreateQuery']) - ->getMock(); - /* @phpstan-ignore-next-line */ - $observer->expects($this->once()) - ->method('postCreateQuery') - ->with($this->equalTo($expectedEvent)); + $observer = new class() extends AbstractPlugin { + public PostCreateQueryEvent $event; + + public function postCreateQuery(PostCreateQueryEvent $event): self + { + $this->event = $event; + + return $this; + } + }; $this->client->getEventDispatcher()->addListener( Events::POST_CREATE_QUERY, @@ -1288,6 +1320,7 @@ public function testCreateQueryPostPlugin() ); $this->client->createQuery($type, $options); + $this->assertEquals($expectedEvent, $observer->event); } public function testCreateSelect() diff --git a/tests/Core/Client/EndpointTest.php b/tests/Core/Client/EndpointTest.php index c5ee85f24..a9429e44b 100644 --- a/tests/Core/Client/EndpointTest.php +++ b/tests/Core/Client/EndpointTest.php @@ -264,15 +264,11 @@ public function testGetAndSetAuthentication() ); } + /** + * @requires PHP >= 8.2 + */ public function testSetAuthenticationSensitiveParameter() { - // #[\SensitiveParameter] was introduced in PHP 8.2 - if (!class_exists('\SensitiveParameter')) { - $this->expectNotToPerformAssertions(); - - return; - } - try { // trigger a \TypeError with the $user argument $this->endpoint->setAuthentication(null, 'S0M3p455'); @@ -300,15 +296,11 @@ public function testGetAndSetAuthorizationToken() ); } + /** + * @requires PHP >= 8.2 + */ public function testSetAuthorizationTokenSensitiveParameter() { - // #[\SensitiveParameter] was introduced in PHP 8.2 - if (!class_exists('\SensitiveParameter')) { - $this->expectNotToPerformAssertions(); - - return; - } - try { // trigger a \TypeError with the $tokenname argument $this->endpoint->setAuthorizationToken(null, '1234567890ABCDEFG'); diff --git a/tests/Core/Client/RequestTest.php b/tests/Core/Client/RequestTest.php index 85a5ccf1e..5fbd5e39e 100644 --- a/tests/Core/Client/RequestTest.php +++ b/tests/Core/Client/RequestTest.php @@ -543,15 +543,11 @@ public function testSetAndGetAuthentication() ); } + /** + * @requires PHP >= 8.2 + */ public function testSetAuthenticationSensitiveParameter() { - // #[\SensitiveParameter] was introduced in PHP 8.2 - if (!class_exists('\SensitiveParameter')) { - $this->expectNotToPerformAssertions(); - - return; - } - try { // trigger a \TypeError with the $user argument $this->request->setAuthentication(null, 'S0M3p455'); diff --git a/tests/Core/Query/HelperTest.php b/tests/Core/Query/HelperTest.php index ff9c53b24..2039075aa 100644 --- a/tests/Core/Query/HelperTest.php +++ b/tests/Core/Query/HelperTest.php @@ -412,7 +412,7 @@ public function testEscapeTerm(string $term, string $expected) /** * @see https://solr.apache.org/guide/the-standard-query-parser.html#escaping-special-characters */ - public function escapeTermProvider(): array + public static function escapeTermProvider(): array { return [ ' ' => ['a b', 'a\\ b'], @@ -468,7 +468,7 @@ public function testEscapePhrase(string $phrase, string $expected) ); } - public function escapePhraseProvider(): array + public static function escapePhraseProvider(): array { return [ '"' => ['a+"b', '"a+\\"b"'], @@ -495,7 +495,7 @@ public function testEscapeLocalParamValue(string $value, string $expected) ); } - public function escapeLocalParamValueProvider(): array + public static function escapeLocalParamValueProvider(): array { return [ 'space' => ['a b', "'a b'"], @@ -523,7 +523,7 @@ public function testEscapeLocalParamValuePreEscapedSeparator(string $value, stri ); } - public function escapeLocalParamValuePreEscapedSeparatorProvider(): array + public static function escapeLocalParamValuePreEscapedSeparatorProvider(): array { return [ 'no other escapes needed' => ['a\\,b', ',', 'a\\,b', 'a\\,b'], diff --git a/tests/Core/Query/QueryTest.php b/tests/Core/Query/QueryTest.php index 06ae34bf1..009f9189a 100644 --- a/tests/Core/Query/QueryTest.php +++ b/tests/Core/Query/QueryTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use Solarium\Core\Query\AbstractQuery; +use Solarium\Core\Query\Helper; use Solarium\Core\Query\RequestBuilderInterface; use Solarium\Core\Query\ResponseParserInterface; @@ -40,11 +41,7 @@ public function testGetHelper() { $query = new TestQuery(); $helper = $query->getHelper(); - - $this->assertSame( - 'Solarium\Core\Query\Helper', - get_class($helper) - ); + $this->assertInstanceOf(Helper::class, $helper); } public function testAddAndGetParams() diff --git a/tests/Core/Query/Result/ResultTest.php b/tests/Core/Query/Result/ResultTest.php index fa6baf9e6..9751cdeb6 100644 --- a/tests/Core/Query/Result/ResultTest.php +++ b/tests/Core/Query/Result/ResultTest.php @@ -137,8 +137,8 @@ public function testGetInvalidJsonData() public function testGetInvalidPhpsData() { set_error_handler(static function (int $errno, string $errstr): void { - // ignore E_NOTICE from unserialize() to check that we throw an exception - }, \E_NOTICE); + // ignore E_NOTICE or E_WARNING from unserialize() to check that we throw an exception + }, version_compare(PHP_VERSION, '8.3.0', '>=') ? \E_WARNING : \E_NOTICE); $this->query->setResponseWriter($this->query::WT_PHPS); diff --git a/tests/Integration/AbstractCloudTestCase.php b/tests/Integration/AbstractCloudTestCase.php index 7791649fa..59a84efa7 100644 --- a/tests/Integration/AbstractCloudTestCase.php +++ b/tests/Integration/AbstractCloudTestCase.php @@ -34,8 +34,7 @@ protected static function createTechproducts(): void ->setName('techproducts') ->setOverwrite(true); $configsetsQuery->setAction($action); - $response = self::$client->configsets($configsetsQuery); - static::assertTrue($response->getWasSuccessful()); + self::$client->configsets($configsetsQuery); // create collection with unique name using the techproducts configset $collectionsQuery = self::$client->createCollections(); @@ -48,31 +47,26 @@ protected static function createTechproducts(): void // for the integration tests which might be the reason. ->setNumShards(3); $collectionsQuery->setAction($createAction); - $response = self::$client->collections($collectionsQuery); - static::assertTrue($response->getWasSuccessful()); + self::$client->collections($collectionsQuery); } public static function tearDownAfterClass(): void { - $collectionsQuery = self::$client->createCollections(); - // now we delete the collection we created in setUpBeforeClass() + $collectionsQuery = self::$client->createCollections(); $deleteAction = $collectionsQuery->createDelete(); $deleteAction->setName(self::$name); $collectionsQuery->setAction($deleteAction); - $response = self::$client->collections($collectionsQuery); - static::assertTrue($response->getWasSuccessful()); + self::$client->collections($collectionsQuery); // now we delete the configsets we created in setUpBeforeClass() and during the tests $configsetsQuery = self::$client->createConfigsets(); $action = $configsetsQuery->createDelete(); $action->setName('copy_of_techproducts'); $configsetsQuery->setAction($action); - $result = self::$client->configsets($configsetsQuery); - static::assertTrue($result->getWasSuccessful()); + self::$client->configsets($configsetsQuery); $action->setName('techproducts'); - $result = self::$client->configsets($configsetsQuery); - static::assertTrue($result->getWasSuccessful()); + self::$client->configsets($configsetsQuery); } public function testConfigsetsApi() @@ -141,7 +135,7 @@ public function testClusterStatus() $result = self::$client->collections($collectionsQuery); $this->assertTrue($result->getWasSuccessful()); $clusterState = $result->getClusterState(); - $this->assertSame(ClusterState::class, get_class($clusterState)); + $this->assertInstanceOf(ClusterState::class, $clusterState); $this->assertCount(3, $clusterState->getLiveNodes()); $this->assertCount(1, $clusterState->getCollections()); $this->assertTrue($clusterState->collectionExists(self::$name)); diff --git a/tests/Integration/AbstractServerTestCase.php b/tests/Integration/AbstractServerTestCase.php index 9996fec63..968968a8e 100644 --- a/tests/Integration/AbstractServerTestCase.php +++ b/tests/Integration/AbstractServerTestCase.php @@ -28,8 +28,7 @@ protected static function createTechproducts(): void $createAction->setCore(self::$name) ->setConfigSet('solarium'); $coreAdminQuery->setAction($createAction); - $response = self::$client->coreAdmin($coreAdminQuery); - static::assertTrue($response->getWasSuccessful()); + self::$client->coreAdmin($coreAdminQuery); } public static function tearDownAfterClass(): void @@ -43,8 +42,7 @@ public static function tearDownAfterClass(): void ->setDeleteIndex(true) ->setDeleteInstanceDir(true); $coreAdminQuery->setAction($unloadAction); - $response = self::$client->coreAdmin($coreAdminQuery); - static::assertTrue($response->getWasSuccessful()); + self::$client->coreAdmin($coreAdminQuery); } public function testCanReloadCore() diff --git a/tests/Integration/AbstractTechproductsTestCase.php b/tests/Integration/AbstractTechproductsTestCase.php index 542b366e2..4ae7ed9ed 100644 --- a/tests/Integration/AbstractTechproductsTestCase.php +++ b/tests/Integration/AbstractTechproductsTestCase.php @@ -13,10 +13,10 @@ use Solarium\Component\Result\Grouping\Result as GroupingResult; use Solarium\Component\Result\Grouping\ValueGroup; use Solarium\Component\Result\Terms\Result as TermsResult; +use Solarium\Client; use Solarium\Core\Client\Adapter\ConnectionTimeoutAwareInterface; use Solarium\Core\Client\Adapter\Curl; use Solarium\Core\Client\Adapter\TimeoutAwareInterface; -use Solarium\Core\Client\ClientInterface; use Solarium\Core\Client\Request; use Solarium\Core\Client\Response; use Solarium\Core\Event\Events; @@ -28,20 +28,26 @@ use Solarium\Exception\HttpException; use Solarium\Exception\RuntimeException; use Solarium\Exception\UnexpectedValueException; +use Solarium\Plugin\BufferedAdd\BufferedAdd; +use Solarium\Plugin\BufferedAdd\BufferedAddLite; use Solarium\Plugin\BufferedAdd\Event\AddDocument as BufferedAddAddDocumentEvent; use Solarium\Plugin\BufferedAdd\Event\Events as BufferedAddEvents; use Solarium\Plugin\BufferedAdd\Event\PostCommit as BufferedAddPostCommitEvent; use Solarium\Plugin\BufferedAdd\Event\PostFlush as BufferedAddPostFlushEvent; use Solarium\Plugin\BufferedAdd\Event\PreCommit as BufferedAddPreCommitEvent; use Solarium\Plugin\BufferedAdd\Event\PreFlush as BufferedAddPreFlushEvent; +use Solarium\Plugin\BufferedDelete\BufferedDelete; +use Solarium\Plugin\BufferedDelete\BufferedDeleteLite; use Solarium\Plugin\BufferedDelete\Event\AddDeleteById as BufferedDeleteAddDeleteByIdEvent; use Solarium\Plugin\BufferedDelete\Event\AddDeleteQuery as BufferedDeleteAddDeleteQueryEvent; use Solarium\Plugin\BufferedDelete\Event\Events as BufferedDeleteEvents; use Solarium\Plugin\Loadbalancer\Event\EndpointFailure as LoadbalancerEndpointFailureEvent; use Solarium\Plugin\Loadbalancer\Event\Events as LoadbalancerEvents; use Solarium\Plugin\Loadbalancer\Loadbalancer; +use Solarium\Plugin\MinimumScoreFilter\MinimumScoreFilter; use Solarium\Plugin\ParallelExecution\ParallelExecution; use Solarium\Plugin\PrefetchIterator; +use Solarium\Plugin\PostBigExtractRequest; use Solarium\QueryType\Luke\Query as LukeQuery; use Solarium\QueryType\Luke\Result\Doc\DocFieldInfo as LukeDocFieldInfo; use Solarium\QueryType\Luke\Result\Doc\DocInfo as LukeDocInfo; @@ -67,36 +73,23 @@ abstract class AbstractTechproductsTestCase extends TestCase { - /** - * @var ClientInterface - */ - protected static $client; + protected static Client $client; - /** - * @var string - */ - protected static $name; + protected static string $name; - /** - * @var array - */ - protected static $config; + protected static array $config; /** * Major Solr version. - * - * @var int */ - protected static $solrVersion; + protected static int $solrVersion; /** * Solr running on Windows? * * SOLR-15895 has to be avoided when testing against Solr on Windows. - * - * @var bool */ - protected static $isSolrOnWindows; + protected static bool $isSolrOnWindows; /** * Asserts that a document contains exactly the expected fields. @@ -158,23 +151,6 @@ public static function setUpBeforeClass(): void ]); self::$client->execute($query); - // ensure correct config for update tests - $query = self::$client->createApi([ - 'version' => Request::API_V1, - 'handler' => self::$name.'/config/updateHandler', - ]); - $response = self::$client->execute($query); - $config = $response->getData()['config']; - static::assertEquals([ - 'maxDocs' => -1, - 'maxTime' => -1, - 'openSearcher' => true, - ], $config['updateHandler']['autoCommit']); - static::assertEquals([ - 'maxDocs' => -1, - 'maxTime' => -1, - ], $config['updateHandler']['autoSoftCommit']); - try { // index techproducts sample data $dataDir = __DIR__. @@ -197,29 +173,9 @@ public static function setUpBeforeClass(): void } $update = self::$client->createUpdate(); - $update->addCommit(true, true); + $update->addCommit(false, true); self::$client->update($update); - - // check that everything was indexed properly - $select = self::$client->createSelect(); - $select->setFields('id'); - $result = self::$client->select($select); - static::assertSame(32, $result->getNumFound()); - - $select->setQuery('êâîôû'); - $result = self::$client->select($select); - static::assertCount(1, $result); - static::assertDocumentHasFields([ - 'id' => 'UTF8TEST', - ], $result->getIterator()->current()); - - $select->setQuery('这是一个功能'); - $result = self::$client->select($select); - static::assertCount(1, $result); - static::assertDocumentHasFields([ - 'id' => 'GB18030TEST', - ], $result->getIterator()->current()); - } catch (\Exception $e) { + } catch (\Exception) { self::tearDownAfterClass(); static::markTestSkipped('Solr techproducts sample data not indexed properly.'); } @@ -229,7 +185,7 @@ public static function setUpBeforeClass(): void * This data provider can be used to test functional equivalence in parsing results * from the same queries with different response writers. */ - public function responseWriterProvider(): array + public static function responseWriterProvider(): array { return [ [AbstractQuery::WT_JSON], @@ -241,7 +197,7 @@ public function responseWriterProvider(): array * This data provider should be used by all UpdateQuery tests that don't test request * format specific Commands to ensure functional equivalence between the formats. */ - public function updateRequestFormatProvider(): array + public static function updateRequestFormatProvider(): array { return [ [UpdateQuery::REQUEST_FORMAT_XML], @@ -253,14 +209,61 @@ public function updateRequestFormatProvider(): array * This data provider crosses {@see updateRequestFormatProvider()} with * {@see responseWriterProvider()}. */ - public function crossRequestFormatResponseWriterProvider(): DataProvider + public static function crossRequestFormatResponseWriterProvider(): DataProvider { return DataProvider::cross( - $this->updateRequestFormatProvider(), - $this->responseWriterProvider(), + self::updateRequestFormatProvider(), + self::responseWriterProvider(), ); } + public function testUpdateHandlerConfiguredCorrectly() + { + $message = 'Solr update handler not configured correctly.'; + + $query = self::$client->createApi([ + 'version' => Request::API_V1, + 'handler' => self::$name.'/config/updateHandler', + ]); + $response = self::$client->execute($query); + $config = $response->getData()['config']; + + $this->assertEquals([ + 'maxDocs' => -1, + 'maxTime' => -1, + 'openSearcher' => true, + ], $config['updateHandler']['autoCommit'], $message); + + $this->assertEquals([ + 'maxDocs' => -1, + 'maxTime' => -1, + ], $config['updateHandler']['autoSoftCommit'], $message); + } + + public function testSampleDataIndexedProperly() + { + $message = 'Solr techproducts sample data not indexed properly.'; + + $select = self::$client->createSelect(); + $select->setFields('id'); + $result = self::$client->select($select); + $this->assertSame(32, $result->getNumFound(), $message); + + $select->setQuery('êâîôû'); + $result = self::$client->select($select); + $this->assertCount(1, $result, $message); + $this->assertDocumentHasFields([ + 'id' => 'UTF8TEST', + ], $result->getIterator()->current(), $message); + + $select->setQuery('这是一个功能'); + $result = self::$client->select($select); + $this->assertCount(1, $result, $message); + $this->assertDocumentHasFields([ + 'id' => 'GB18030TEST', + ], $result->getIterator()->current(), $message); + } + /** * @dataProvider responseWriterProvider */ @@ -834,7 +837,7 @@ public function testHighlightingComponentMethods(string $method, string $respons ); } - public function crossHighlightingMethodResponseWriterProvider(): DataProvider + public static function crossHighlightingMethodResponseWriterProvider(): DataProvider { $highlightingMethods = [ [Highlighting::METHOD_UNIFIED], @@ -844,7 +847,7 @@ public function crossHighlightingMethodResponseWriterProvider(): DataProvider return DataProvider::cross( $highlightingMethods, - $this->responseWriterProvider(), + self::responseWriterProvider(), ); } @@ -1738,6 +1741,7 @@ public function testUpdate(string $requestFormat, string $responseWriter) self::$client->update($update); $update = self::$client->createUpdate(); $update->setRequestFormat($requestFormat); + $update->setResponseWriter($responseWriter); $update->addRollback(); $update->addCommit(true, true); self::$client->update($update); @@ -3245,6 +3249,7 @@ public function testBufferedAdd() $bufferSize = 10; $totalDocs = 25; + /** @var BufferedAdd $buffer */ $buffer = self::$client->getPlugin('bufferedadd'); $buffer->setBufferSize($bufferSize); @@ -3419,6 +3424,7 @@ public function testBufferedDelete() { $bufferSize = 3; + /** @var BufferedDelete $buffer */ $buffer = self::$client->getPlugin('buffereddelete'); $buffer->setBufferSize($bufferSize); @@ -3496,10 +3502,12 @@ public function testBufferedAddAndDelete(string $requestFormat) { $bufferSize = 10; + /** @var BufferedAdd $addBuffer */ $addBuffer = self::$client->getPlugin('bufferedadd'); $addBuffer->setRequestFormat($requestFormat); $addBuffer->setBufferSize($bufferSize); + /** @var BufferedDelete $delBuffer */ $delBuffer = self::$client->getPlugin('buffereddelete'); $delBuffer->setRequestFormat($requestFormat); @@ -3628,6 +3636,7 @@ public function testBufferedAddLite(): int self::$client->getEventDispatcher()->addListener(BufferedAddEvents::PRE_COMMIT, $failListener); self::$client->getEventDispatcher()->addListener(BufferedAddEvents::POST_COMMIT, $failListener); + /** @var BufferedAddLite $buffer */ $buffer = self::$client->getPlugin('bufferedaddlite'); $buffer->setBufferSize($bufferSize); @@ -3723,6 +3732,7 @@ public function testBufferedDeleteLite(int $totalDocs) self::$client->getEventDispatcher()->addListener(BufferedDeleteEvents::PRE_COMMIT, $failListener); self::$client->getEventDispatcher()->addListener(BufferedDeleteEvents::POST_COMMIT, $failListener); + /** @var BufferedDeleteLite $buffer */ $buffer = self::$client->getPlugin('buffereddeletelite'); $buffer->setBufferSize($bufferSize); @@ -3757,10 +3767,12 @@ public function testBufferedAddAndDeleteLite(string $requestFormat) { $bufferSize = 10; + /** @var BufferedAddLite $addBuffer */ $addBuffer = self::$client->getPlugin('bufferedaddlite'); $addBuffer->setRequestFormat($requestFormat); $addBuffer->setBufferSize($bufferSize); + /** @var BufferedDeleteLite $delBuffer */ $delBuffer = self::$client->getPlugin('buffereddeletelite'); $delBuffer->setRequestFormat($requestFormat); @@ -3894,6 +3906,7 @@ public function testLoadbalancerFailover() */ public function testMinimumScoreFilterWithGrouping(string $responseWriter) { + /** @var MinimumScoreFilter $filter */ $filter = self::$client->getPlugin('minimumscorefilter'); $query = self::$client->createQuery($filter::QUERY_TYPE); $query->setResponseWriter($responseWriter); @@ -4179,6 +4192,7 @@ public function testPrefetchIteratorManualRewind() public function testExtractIntoDocument(bool $usePostBigExtractRequestPlugin) { if ($usePostBigExtractRequestPlugin) { + /** @var PostBigExtractRequest $postBigExtractRequest */ $postBigExtractRequest = self::$client->getPlugin('postbigextractrequest'); // make sure the GET parameters will be converted to POST $postBigExtractRequest->setMaxQueryStringLength(1); @@ -4283,6 +4297,7 @@ public function testExtractIntoDocument(bool $usePostBigExtractRequestPlugin) public function testExtractOnlyText(bool $usePostBigExtractRequestPlugin) { if ($usePostBigExtractRequestPlugin) { + /** @var PostBigExtractRequest $postBigExtractRequest */ $postBigExtractRequest = self::$client->getPlugin('postbigextractrequest'); // make sure the GET parameters will be converted to POST $postBigExtractRequest->setMaxQueryStringLength(1); @@ -4320,6 +4335,7 @@ public function testExtractOnlyText(bool $usePostBigExtractRequestPlugin) public function testExtractOnlyXml(bool $usePostBigExtractRequestPlugin) { if ($usePostBigExtractRequestPlugin) { + /** @var PostBigExtractRequest $postBigExtractRequest */ $postBigExtractRequest = self::$client->getPlugin('postbigextractrequest'); // make sure the GET parameters will be converted to POST $postBigExtractRequest->setMaxQueryStringLength(1); @@ -4370,6 +4386,7 @@ public function testExtractOnlyXml(bool $usePostBigExtractRequestPlugin) public function testExtractInputEncoding(bool $usePostBigExtractRequestPlugin) { if ($usePostBigExtractRequestPlugin) { + /** @var PostBigExtractRequest $postBigExtractRequest */ $postBigExtractRequest = self::$client->getPlugin('postbigextractrequest'); // make sure the GET parameters will be converted to POST $postBigExtractRequest->setMaxQueryStringLength(1); @@ -5311,6 +5328,7 @@ public function testEventDispatching() if (self::$client->getAdapter() instanceof Curl) { $eventTimer->reset(); + /** @var ParallelExecution $parallel */ $parallel = self::$client->getPlugin('parallelexecution'); $query = self::$client->createSelect(); $parallel->addQuery('query', $query); diff --git a/tests/Integration/ConnectionReuseTest.php b/tests/Integration/ConnectionReuseTest.php index 6ac88badb..0e27e6ca3 100644 --- a/tests/Integration/ConnectionReuseTest.php +++ b/tests/Integration/ConnectionReuseTest.php @@ -3,7 +3,7 @@ namespace Solarium\Tests\Integration; use PHPUnit\Framework\TestCase; -use Solarium\Core\Client\ClientInterface; +use Solarium\Client; use Solarium\Core\Client\Request; /** @@ -13,50 +13,34 @@ */ class ConnectionReuseTest extends TestCase { - /** - * @var ClientInterface - */ - protected static $client; + protected static Client $client; - /** - * @var array - */ - protected static $config; + protected static array $config; /** * Are we running against the new v2 logging API that was tweaked for Solr 9.3 (SOLR-16458)? - * - * @var bool */ - protected static $isNewLoggingApi; + protected static bool $isNewLoggingApi; /** * Are we running against a v2 logging API with a known bug (SOLR-17176l)? - * - * @var bool */ - protected static $isBuggyLoggingApi; + protected static bool $isBuggyLoggingApi; /** * Original org.eclipse.jetty.io.AbstractConnection log level to restore after the testcase. - * - * @var string */ - protected static $origLogLevel; + protected static string $origLogLevel; /** * Original watcher threshold to restore after the testcase. - * - * @var string */ - protected static $origThreshold; + protected static string $origThreshold; /** * Keep track of the last retrieved logging timestamp. - * - * @var int */ - protected static $since = 0; + protected static int $since = 0; public static function setUpBeforeClass(): void { @@ -118,7 +102,10 @@ function (array $logger): bool { ] )); $result = self::$client->execute($query); - self::assertTrue($result->getWasSuccessful()); + + if (!$result->getWasSuccessful()) { + return; + } } else { $query = self::$client->createApi([ 'version' => Request::API_V2, @@ -126,7 +113,10 @@ function (array $logger): bool { ]); $query->addParam('set', 'org.eclipse.jetty.io.AbstractConnection:DEBUG'); $result = self::$client->execute($query); - self::assertTrue($result->getWasSuccessful()); + + if (!$result->getWasSuccessful()) { + return; + } } // get the current watcher threshold to restore afterwards @@ -151,7 +141,11 @@ function (array $logger): bool { 'level' => 'DEBUG', ] )); - self::$client->execute($query); + $result = self::$client->execute($query); + + if (!$result->getWasSuccessful()) { + return; + } } else { $query = self::$client->createApi([ 'version' => Request::API_V2, @@ -159,7 +153,11 @@ function (array $logger): bool { ]); $query->addParam('since', self::$since); $query->addParam('threshold', 'DEBUG'); - self::$client->execute($query); + $result = self::$client->execute($query); + + if (!$result->getWasSuccessful()) { + return; + } } // get the initial timestamp to use for retrieving the logging history @@ -190,8 +188,7 @@ public static function tearDownAfterClass(): void ], ] )); - $result = self::$client->execute($query); - self::assertTrue($result->getWasSuccessful()); + self::$client->execute($query); $query = self::$client->createApi([ 'version' => Request::API_V2, @@ -204,8 +201,7 @@ public static function tearDownAfterClass(): void 'level' => self::$origThreshold, ] )); - $result = self::$client->execute($query); - self::assertTrue($result->getWasSuccessful()); + self::$client->execute($query); } else { $query = self::$client->createApi([ 'version' => Request::API_V2, @@ -213,11 +209,18 @@ public static function tearDownAfterClass(): void ]); $query->addParam('set', sprintf('org.eclipse.jetty.io.AbstractConnection:%s', self::$origLogLevel)); $query->addParam('threshold', self::$origThreshold); - $result = self::$client->execute($query); - self::assertTrue($result->getWasSuccessful()); + self::$client->execute($query); } } + /** + * Check that the last logging timestamp was retrieved successfully before running tests. + */ + public function assertPreConditions(): void + { + $this->assertGreaterThan(0, self::$since); + } + /** * @dataProvider createAdapterProvider */ @@ -265,7 +268,7 @@ public function testConnectionReuse(string $createFunction, int $expectedCount) $this->assertContains(\count($connections), [$expectedCount, $expectedCount + 1]); } - public function createAdapterProvider(): array + public static function createAdapterProvider(): array { return [ 'without reuse' => ['createWithCurlAdapter', 5], diff --git a/tests/Integration/Proxy/AbstractProxyTestCase.php b/tests/Integration/Proxy/AbstractProxyTestCase.php index 156fadf42..19f8ebee5 100644 --- a/tests/Integration/Proxy/AbstractProxyTestCase.php +++ b/tests/Integration/Proxy/AbstractProxyTestCase.php @@ -3,7 +3,7 @@ namespace Solarium\Tests\Integration\Proxy; use PHPUnit\Framework\TestCase; -use Solarium\Core\Client\ClientInterface; +use Solarium\Client; use Solarium\Core\Client\Request; /** @@ -14,25 +14,13 @@ */ abstract class AbstractProxyTestCase extends TestCase { - /** - * @var ClientInterface - */ - protected static $client; + protected static Client $client; - /** - * @var array - */ - protected static $config; + protected static array $config; - /** - * @var string - */ - protected static $proxy_server; + protected static string $proxy_server; - /** - * @var int - */ - protected static $proxy_port; + protected static int $proxy_port; abstract protected static function createClient(): void; @@ -56,8 +44,11 @@ public static function setUpBeforeClass(): void static::createClient(); static::setProxy(); + } - self::assertNotNull( + public function assertPreConditions(): void + { + $this->assertNotNull( self::$client->getAdapter()->getProxy(), 'Proxy test must set a proxy on the Client adapter!' ); diff --git a/tests/Integration/Query/CustomQueryClassTest.php b/tests/Integration/Query/CustomQueryClassTest.php index 3595daecc..d5aa7e516 100644 --- a/tests/Integration/Query/CustomQueryClassTest.php +++ b/tests/Integration/Query/CustomQueryClassTest.php @@ -24,7 +24,7 @@ public function testCustomQueryClassSetQueryReturnType(string $queryClass) $this->assertInstanceOf(QueryInterface::class, $query->setQuery('*:*')); } - public function customQueryClassProvider(): array + public static function customQueryClassProvider(): array { return [ [CustomStaticQuery::class], diff --git a/tests/Integration/SolrCloud/CurlTest.php b/tests/Integration/SolrCloud/CurlTest.php index c1e1dbdc0..fd4ff6d9e 100644 --- a/tests/Integration/SolrCloud/CurlTest.php +++ b/tests/Integration/SolrCloud/CurlTest.php @@ -6,6 +6,8 @@ use Solarium\Tests\Integration\AbstractCloudTestCase; /** + * @requires extension curl + * * @group integration * @group skip_for_solr_server */ @@ -13,10 +15,6 @@ class CurlTest extends AbstractCloudTestCase { public function setUp(): void { - if (!\function_exists('curl_init')) { - $this->markTestSkipped('cURL not available, skipping cURL adapter tests.'); - } - parent::setUp(); // The default timeout of Solarium of 5s seems to be too aggressive on Travis and causes random test failures. $adapter = new Curl(); diff --git a/tests/Integration/SolrServer/CurlTest.php b/tests/Integration/SolrServer/CurlTest.php index dfdcc0657..95cc9b5d1 100644 --- a/tests/Integration/SolrServer/CurlTest.php +++ b/tests/Integration/SolrServer/CurlTest.php @@ -6,6 +6,8 @@ use Solarium\Tests\Integration\AbstractServerTestCase; /** + * @requires extension curl + * * @group integration * @group skip_for_solr_cloud */ @@ -13,10 +15,6 @@ class CurlTest extends AbstractServerTestCase { public function setUp(): void { - if (!\function_exists('curl_init')) { - $this->markTestSkipped('cURL not available, skipping cURL adapter tests.'); - } - parent::setUp(); // The default timeout of Solarium of 5s seems to be too aggressive on Travis and causes random test failures. $adapter = new Curl(); diff --git a/tests/Plugin/BufferedDelete/BufferedDeleteLiteTest.php b/tests/Plugin/BufferedDelete/BufferedDeleteLiteTest.php index 0fc555b54..a43ff989a 100644 --- a/tests/Plugin/BufferedDelete/BufferedDeleteLiteTest.php +++ b/tests/Plugin/BufferedDelete/BufferedDeleteLiteTest.php @@ -450,7 +450,7 @@ protected function getClient(?EventDispatcherInterface $dispatcher = null): Clie class BufferedDeleteDummy extends BufferedDeleteLite { - public function addUnknownDeleteType() + public function addUnknownDeleteType(): void { $this->buffer[] = new DeleteDummy(); } diff --git a/tests/Plugin/CustomizeRequest/CustomizeRequestTest.php b/tests/Plugin/CustomizeRequest/CustomizeRequestTest.php index c4256841a..0d438ae16 100644 --- a/tests/Plugin/CustomizeRequest/CustomizeRequestTest.php +++ b/tests/Plugin/CustomizeRequest/CustomizeRequestTest.php @@ -52,14 +52,14 @@ public function testConfigMode() $auth = $this->plugin->getCustomization('auth'); $id = $this->plugin->getCustomization('id'); - $this->assertThat($auth, $this->isInstanceOf('Solarium\Plugin\CustomizeRequest\Customization')); + $this->assertInstanceOf(Customization::class, $auth); $this->assertSame('auth', $auth->getKey()); $this->assertSame('header', $auth->getType()); $this->assertSame('X-my-auth', $auth->getName()); $this->assertSame('mypassword', $auth->getValue()); $this->assertTrue($auth->getPersistent()); - $this->assertThat($id, $this->isInstanceOf('Solarium\Plugin\CustomizeRequest\Customization')); + $this->assertInstanceOf(Customization::class, $id); $this->assertSame('id', $id->getKey()); $this->assertSame('param', $id->getType()); $this->assertSame('id', $id->getName()); diff --git a/tests/Plugin/MinimumScoreFilter/ResultTest.php b/tests/Plugin/MinimumScoreFilter/ResultTest.php index ace7c1aac..f19c0cd0e 100644 --- a/tests/Plugin/MinimumScoreFilter/ResultTest.php +++ b/tests/Plugin/MinimumScoreFilter/ResultTest.php @@ -22,7 +22,7 @@ public function setUp(): void new Document(['id' => 4, 'title' => 'doc4', 'score' => 0.08]), ]; - $this->result = new FilterResultDummy(1, 12, $this->numFound, $this->maxScore, $this->docs, $this->components, Query::FILTER_MODE_MARK); + $this->result = new FilterResultDummy(1, 12, $this->numFound, $this->maxScore, $this->nextCursorMark, $this->docs, $this->components, Query::FILTER_MODE_MARK); } public function testIterator() @@ -36,12 +36,12 @@ public function testIterator() public function testGetDocuments() { - $this->assertCount(count($this->docs), $this->result->getDocuments()); + $this->assertSameSize($this->docs, $this->result->getDocuments()); } public function testIteratorWithRemoveFilter() { - $result = new FilterResultDummy(1, 12, $this->numFound, $this->maxScore, $this->docs, $this->components, Query::FILTER_MODE_REMOVE); + $result = new FilterResultDummy(1, 12, $this->numFound, $this->maxScore, $this->nextCursorMark, $this->docs, $this->components, Query::FILTER_MODE_REMOVE); $docs = []; foreach ($result as $key => $doc) { $docs[$key] = $doc; @@ -55,7 +55,7 @@ public function testIteratorWithRemoveFilter() public function testGetDocumentsWithRemoveFilter() { - $result = new FilterResultDummy(1, 12, $this->numFound, $this->maxScore, $this->docs, $this->components, Query::FILTER_MODE_REMOVE); + $result = new FilterResultDummy(1, 12, $this->numFound, $this->maxScore, $this->nextCursorMark, $this->docs, $this->components, Query::FILTER_MODE_REMOVE); $docs = $result->getDocuments(); $this->assertCount(3, $docs); @@ -67,7 +67,7 @@ public function testGetDocumentsWithRemoveFilter() public function testFilterWithInvalidMode() { $this->expectException(OutOfBoundsException::class); - $result = new FilterResultDummy(1, 12, $this->numFound, $this->maxScore, $this->docs, $this->components, 'invalid_filter_name'); + $result = new FilterResultDummy(1, 12, $this->numFound, $this->maxScore, $this->nextCursorMark, $this->docs, $this->components, 'invalid_filter_name'); } } @@ -75,10 +75,11 @@ class FilterResultDummy extends Result { protected $parsed = true; - public function __construct($status, $queryTime, $numfound, $maxscore, $docs, $components, $mode) + public function __construct($status, $queryTime, $numfound, $maxscore, $nextcursormark, $docs, $components, $mode) { $this->numfound = $numfound; $this->maxscore = $maxscore; + $this->nextcursormark = $nextcursormark; $this->documents = $docs; $this->components = $components; $this->responseHeader = ['status' => $status, 'QTime' => $queryTime]; diff --git a/tests/QueryType/Analysis/ResponseParser/DocumentTest.php b/tests/QueryType/Analysis/ResponseParser/DocumentTest.php index bd7343b2d..b0ac6928e 100644 --- a/tests/QueryType/Analysis/ResponseParser/DocumentTest.php +++ b/tests/QueryType/Analysis/ResponseParser/DocumentTest.php @@ -35,7 +35,7 @@ public function testParse() $result = $parserStub->parse($resultStub); - $this->assertCount(count($data['analysis']), $result['items']); + $this->assertSameSize($data['analysis'], $result['items']); $this->assertSame('key2', $result['items'][1]->getName()); } } diff --git a/tests/QueryType/Analysis/Result/DocumentTest.php b/tests/QueryType/Analysis/Result/DocumentTest.php index 4aa8c7207..ef4e111b8 100644 --- a/tests/QueryType/Analysis/Result/DocumentTest.php +++ b/tests/QueryType/Analysis/Result/DocumentTest.php @@ -32,7 +32,7 @@ public function testGetDocuments() public function testCount() { - $this->assertCount(count($this->items), $this->result); + $this->assertSameSize($this->items, $this->result); } public function testIterator() diff --git a/tests/QueryType/Analysis/Result/FieldTest.php b/tests/QueryType/Analysis/Result/FieldTest.php index b66847633..f752e7269 100644 --- a/tests/QueryType/Analysis/Result/FieldTest.php +++ b/tests/QueryType/Analysis/Result/FieldTest.php @@ -27,7 +27,7 @@ public function testGetLists() public function testCount() { - $this->assertCount(count($this->items), $this->result); + $this->assertSameSize($this->items, $this->result); } public function testIterator() diff --git a/tests/QueryType/Analysis/Result/ResultListTest.php b/tests/QueryType/Analysis/Result/ResultListTest.php index 96ac3f877..c7ba7a730 100644 --- a/tests/QueryType/Analysis/Result/ResultListTest.php +++ b/tests/QueryType/Analysis/Result/ResultListTest.php @@ -30,7 +30,7 @@ public function testGetItems() public function testCount() { - $this->assertCount(count($this->items), $this->result); + $this->assertSameSize($this->items, $this->result); } public function testIterator() diff --git a/tests/QueryType/Analysis/Result/TypesTest.php b/tests/QueryType/Analysis/Result/TypesTest.php index e4383243b..9b69c9dd2 100644 --- a/tests/QueryType/Analysis/Result/TypesTest.php +++ b/tests/QueryType/Analysis/Result/TypesTest.php @@ -34,7 +34,7 @@ public function testGetItems() public function testCount() { - $this->assertCount(count($this->items), $this->result); + $this->assertSameSize($this->items, $this->result); } public function testIterator() diff --git a/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php b/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php index f266c42f6..85d723fbf 100644 --- a/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php +++ b/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php @@ -40,7 +40,7 @@ public function testParse() $result = $parser->parse($resultStub); - $this->assertCount(count($data['managedResources']), $result['items']); + $this->assertSameSize($data['managedResources'], $result['items']); $this->assertSame('/schema/analysis/stopwords/dutch', $result['items'][0]->getResourceId()); $this->assertSame(1, $result['items'][0]->getNumObservers()); $this->assertSame('org.apache.solr.rest.schema.analysis.ManagedWordSetResource', $result['items'][0]->getClass()); diff --git a/tests/QueryType/MoreLikeThis/QueryTest.php b/tests/QueryType/MoreLikeThis/QueryTest.php index 422f90df2..48a724a58 100644 --- a/tests/QueryType/MoreLikeThis/QueryTest.php +++ b/tests/QueryType/MoreLikeThis/QueryTest.php @@ -3,7 +3,15 @@ namespace Solarium\Tests\QueryType\MoreLikeThis; use PHPUnit\Framework\TestCase; +use Solarium\Component\Debug; +use Solarium\Component\DisMax; +use Solarium\Component\DistributedSearch; +use Solarium\Component\FacetSet; +use Solarium\Component\Grouping; +use Solarium\Component\Highlighting\Highlighting; use Solarium\Component\MoreLikeThis; +use Solarium\Component\Spellcheck; +use Solarium\Component\Stats\Stats; use Solarium\Core\Client\Client; use Solarium\Exception\DomainException; use Solarium\Exception\InvalidArgumentException; @@ -451,10 +459,7 @@ public function testConfigMode() $components = $query->getComponents(); $this->assertCount(1, $components); - $this->assertThat( - array_pop($components), - $this->isInstanceOf('Solarium\Component\FacetSet') - ); + $this->assertInstanceOf(FacetSet::class, array_pop($components)); } public function testSetAndGetComponents() @@ -530,41 +535,33 @@ public function testRemoveComponentWithObjectInput() public function testGetMoreLikeThis() { - $mlt = $this->query->getMoreLikeThis(); - - $this->assertSame( - 'Solarium\Component\MoreLikeThis', - \get_class($mlt) + $this->assertInstanceOf( + MoreLikeThis::class, + $this->query->getMoreLikeThis() ); } public function testGetDisMax() { - $dismax = $this->query->getDisMax(); - - $this->assertSame( - 'Solarium\Component\DisMax', - \get_class($dismax) + $this->assertInstanceOf( + DisMax::class, + $this->query->getDisMax() ); } public function testGetHighlighting() { - $hlt = $this->query->getHighlighting(); - - $this->assertSame( - 'Solarium\Component\Highlighting\Highlighting', - \get_class($hlt) + $this->assertInstanceOf( + Highlighting::class, + $this->query->getHighlighting() ); } public function testGetGrouping() { - $grouping = $this->query->getGrouping(); - - $this->assertSame( - 'Solarium\Component\Grouping', - \get_class($grouping) + $this->assertInstanceOf( + Grouping::class, + $this->query->getGrouping() ); } @@ -587,7 +584,7 @@ public function testCreateFilterQuery() $fq = $this->query->createFilterQuery($options); // check class - $this->assertThat($fq, $this->isInstanceOf('Solarium\QueryType\Select\Query\FilterQuery')); + $this->assertInstanceOf(FilterQuery::class, $fq); // check option forwarding $fqOptions = $fq->getOptions(); @@ -599,41 +596,33 @@ public function testCreateFilterQuery() public function testGetSpellcheck() { - $spellcheck = $this->query->getSpellcheck(); - - $this->assertSame( - 'Solarium\Component\Spellcheck', - \get_class($spellcheck) + $this->assertInstanceOf( + Spellcheck::class, + $this->query->getSpellcheck() ); } public function testGetDistributedSearch() { - $spellcheck = $this->query->getDistributedSearch(); - - $this->assertSame( - 'Solarium\Component\DistributedSearch', - \get_class($spellcheck) + $this->assertInstanceOf( + DistributedSearch::class, + $this->query->getDistributedSearch() ); } public function testGetStats() { - $stats = $this->query->getStats(); - - $this->assertSame( - 'Solarium\Component\Stats\Stats', - \get_class($stats) + $this->assertInstanceOf( + Stats::class, + $this->query->getStats() ); } public function testGetDebug() { - $stats = $this->query->getDebug(); - - $this->assertSame( - 'Solarium\Component\Debug', - \get_class($stats) + $this->assertInstanceOf( + Debug::class, + $this->query->getDebug() ); } diff --git a/tests/QueryType/Select/Query/AbstractQueryTestCase.php b/tests/QueryType/Select/Query/AbstractQueryTestCase.php index a26a9344d..ab503ba6d 100644 --- a/tests/QueryType/Select/Query/AbstractQueryTestCase.php +++ b/tests/QueryType/Select/Query/AbstractQueryTestCase.php @@ -4,7 +4,20 @@ use PHPUnit\Framework\TestCase; use Solarium\Component\Analytics\Analytics; +use Solarium\Component\Debug; +use Solarium\Component\DisMax; +use Solarium\Component\DistributedSearch; +use Solarium\Component\FacetSet; +use Solarium\Component\Grouping; +use Solarium\Component\Highlighting\Highlighting; use Solarium\Component\MoreLikeThis; +use Solarium\Component\QueryElevation; +use Solarium\Component\ReRankQuery; +use Solarium\Component\Spatial; +use Solarium\Component\Spellcheck; +use Solarium\Component\Stats\Stats; +use Solarium\Component\Suggester; +use Solarium\Component\TermVector; use Solarium\Core\Client\Client; use Solarium\Exception\InvalidArgumentException; use Solarium\Exception\OutOfBoundsException; @@ -480,10 +493,7 @@ public function testConfigMode() $components = $query->getComponents(); $this->assertCount(1, $components); - $this->assertThat( - array_pop($components), - $this->isInstanceOf('Solarium\Component\FacetSet') - ); + $this->assertInstanceOf(FacetSet::class, array_pop($components)); $this->assertSame(['t1', 't2'], $query->getLocalParameters()->getTags()); } @@ -577,51 +587,41 @@ public function testRemoveComponentWithObjectInput() public function testGetMoreLikeThis() { - $mlt = $this->query->getMoreLikeThis(); - - $this->assertSame( - 'Solarium\Component\MoreLikeThis', - \get_class($mlt) + $this->assertInstanceOf( + MoreLikeThis::class, + $this->query->getMoreLikeThis() ); } public function testGetDisMax() { - $dismax = $this->query->getDisMax(); - - $this->assertSame( - 'Solarium\Component\DisMax', - \get_class($dismax) + $this->assertInstanceOf( + DisMax::class, + $this->query->getDisMax() ); } public function testGetHighlighting() { - $hlt = $this->query->getHighlighting(); - - $this->assertSame( - 'Solarium\Component\Highlighting\Highlighting', - \get_class($hlt) + $this->assertInstanceOf( + Highlighting::class, + $this->query->getHighlighting() ); } public function testGetGrouping() { - $grouping = $this->query->getGrouping(); - - $this->assertSame( - 'Solarium\Component\Grouping', - \get_class($grouping) + $this->assertInstanceOf( + Grouping::class, + $this->query->getGrouping() ); } public function testGetQueryElevation() { - $queryelevation = $this->query->getQueryElevation(); - - $this->assertSame( - 'Solarium\Component\QueryElevation', - \get_class($queryelevation) + $this->assertInstanceOf( + QueryElevation::class, + $this->query->getQueryElevation() ); } @@ -644,7 +644,7 @@ public function testCreateFilterQuery() $fq = $this->query->createFilterQuery($options); // check class - $this->assertThat($fq, $this->isInstanceOf('Solarium\QueryType\Select\Query\FilterQuery')); + $this->assertInstanceOf(FilterQuery::class, $fq); // check option forwarding $fqOptions = $fq->getOptions(); @@ -656,87 +656,74 @@ public function testCreateFilterQuery() public function testGetSpellcheck() { - $spellcheck = $this->query->getSpellcheck(); - - $this->assertSame( - 'Solarium\Component\Spellcheck', - \get_class($spellcheck) + $this->assertInstanceOf( + Spellcheck::class, + $this->query->getSpellcheck() ); } public function testGetSuggester() { - $suggester = $this->query->getSuggester(); - - $this->assertSame( - 'Solarium\Component\Suggester', - \get_class($suggester) + $this->assertInstanceOf( + Suggester::class, + $this->query->getSuggester() ); } public function testGetTermVector() { - $termVector = $this->query->getTermVector(); - - $this->assertSame( - 'Solarium\Component\TermVector', - \get_class($termVector) + $this->assertInstanceOf( + TermVector::class, + $this->query->getTermVector() ); } public function testGetDistributedSearch() { - $spellcheck = $this->query->getDistributedSearch(); - - $this->assertSame( - 'Solarium\Component\DistributedSearch', - \get_class($spellcheck) + $this->assertInstanceOf( + DistributedSearch::class, + $this->query->getDistributedSearch() ); } public function testGetStats() { - $stats = $this->query->getStats(); - - $this->assertSame( - 'Solarium\Component\Stats\Stats', - \get_class($stats) + $this->assertInstanceOf( + Stats::class, + $this->query->getStats() ); } public function testGetDebug() { - $stats = $this->query->getDebug(); - - $this->assertSame( - 'Solarium\Component\Debug', - \get_class($stats) + $this->assertInstanceOf( + Debug::class, + $this->query->getDebug() ); } public function testGetSpatial() { - $spatial = $this->query->getSpatial(); - - $this->assertSame( - 'Solarium\Component\Spatial', - \get_class($spatial) + $this->assertInstanceOf( + Spatial::class, + $this->query->getSpatial() ); } public function testGetReRankQuery() { - $reRankQuery = $this->query->getReRankQuery(); - - $this->assertSame( - 'Solarium\Component\ReRankQuery', - \get_class($reRankQuery) + $this->assertInstanceOf( + ReRankQuery::class, + $this->query->getReRankQuery() ); } public function testGetAnalytics(): void { - $this->assertInstanceOf(Analytics::class, $this->query->getAnalytics()); + $this->assertInstanceOf( + Analytics::class, + $this->query->getAnalytics() + ); } public function testAddTag() diff --git a/tests/QueryType/Select/Result/AbstractDocumentTestCase.php b/tests/QueryType/Select/Result/AbstractDocumentTestCase.php index 82c444ec0..bcf8eed77 100644 --- a/tests/QueryType/Select/Result/AbstractDocumentTestCase.php +++ b/tests/QueryType/Select/Result/AbstractDocumentTestCase.php @@ -113,7 +113,7 @@ public function testArrayUnset() public function testCount() { - $this->assertCount(count($this->fields), $this->doc); + $this->assertSameSize($this->fields, $this->doc); } public function testJsonSerialize() diff --git a/tests/QueryType/Select/Result/AbstractResultTestCase.php b/tests/QueryType/Select/Result/AbstractResultTestCase.php index b8025396a..0f0b30f0b 100644 --- a/tests/QueryType/Select/Result/AbstractResultTestCase.php +++ b/tests/QueryType/Select/Result/AbstractResultTestCase.php @@ -18,6 +18,8 @@ abstract class AbstractResultTestCase extends TestCase protected $maxScore; + protected $nextCursorMark; + protected $docs; protected $components; @@ -46,6 +48,7 @@ public function setUp(): void { $this->numFound = 11; $this->maxScore = 0.91; + $this->nextCursorMark = 'AoEjR0JQ'; $this->docs = [ new Document(['id' => 1, 'title' => 'doc1']), @@ -77,7 +80,7 @@ public function setUp(): void ComponentAwareQueryInterface::COMPONENT_TERMVECTOR => $this->termVector, ]; - $this->result = new SelectDummy(1, 12, $this->numFound, $this->maxScore, $this->docs, $this->components); + $this->result = new SelectDummy(1, 12, $this->numFound, $this->maxScore, $this->nextCursorMark, $this->docs, $this->components); } public function testGetNumFound() @@ -90,6 +93,11 @@ public function testGetMaxScore() $this->assertSame($this->maxScore, $this->result->getMaxScore()); } + public function testGetNextCursorMark() + { + $this->assertSame($this->nextCursorMark, $this->result->getNextCursorMark()); + } + public function testGetDocuments() { $this->assertSame($this->docs, $this->result->getDocuments()); @@ -102,7 +110,7 @@ public function testGetFacetSet() public function testCount() { - $this->assertCount(\count($this->docs), $this->result); + $this->assertSameSize($this->docs, $this->result); } public function testGetComponents() @@ -236,7 +244,7 @@ public function testNoPartialResults() public function testGetAndIsPartialResults() { - $result = new SelectPartialResultsDummy(0, 5, 0, null, [], []); + $result = new SelectPartialResultsDummy(0, 5, 0, null, null, [], []); $this->assertTrue( $result->getPartialResults() @@ -260,7 +268,7 @@ public function testNoSegmentTerminatedEarly() public function testGetSegmentTerminatedEarly() { - $result = new SelectSegmentTerminatedEarlyDummy(0, 5, 0, null, [], []); + $result = new SelectSegmentTerminatedEarlyDummy(0, 5, 0, null, null, [], []); $this->assertTrue( $result->getSegmentTerminatedEarly() @@ -276,10 +284,11 @@ class SelectDummy extends Result { protected $parsed = true; - public function __construct($status, $queryTime, $numfound, $maxscore, $docs, $components) + public function __construct($status, $queryTime, $numfound, $maxscore, $nextcursormark, $docs, $components) { $this->numfound = $numfound; $this->maxscore = $maxscore; + $this->nextcursormark = $nextcursormark; $this->documents = $docs; $this->components = $components; $this->responseHeader = ['status' => $status, 'QTime' => $queryTime]; @@ -288,9 +297,9 @@ public function __construct($status, $queryTime, $numfound, $maxscore, $docs, $c class SelectPartialResultsDummy extends SelectDummy { - public function __construct($status, $queryTime, $numfound, $maxscore, $docs, $components) + public function __construct($status, $queryTime, $numfound, $maxscore, $nextcursormark, $docs, $components) { - parent::__construct($status, $queryTime, $numfound, $maxscore, $docs, $components); + parent::__construct($status, $queryTime, $numfound, $maxscore, $nextcursormark, $docs, $components); $this->responseHeader['partialResults'] = true; } @@ -298,9 +307,9 @@ public function __construct($status, $queryTime, $numfound, $maxscore, $docs, $c class SelectSegmentTerminatedEarlyDummy extends SelectDummy { - public function __construct($status, $queryTime, $numfound, $maxscore, $docs, $components) + public function __construct($status, $queryTime, $numfound, $maxscore, $nextcursormark, $docs, $components) { - parent::__construct($status, $queryTime, $numfound, $maxscore, $docs, $components); + parent::__construct($status, $queryTime, $numfound, $maxscore, $nextcursormark, $docs, $components); $this->responseHeader['segmentTerminatedEarly'] = true; } diff --git a/tests/QueryType/Select/Result/Facet/FieldTest.php b/tests/QueryType/Select/Result/Facet/FieldTest.php index a26264ac8..fc74863b8 100644 --- a/tests/QueryType/Select/Result/Facet/FieldTest.php +++ b/tests/QueryType/Select/Result/Facet/FieldTest.php @@ -28,7 +28,7 @@ public function testGetValues() public function testCount() { - $this->assertCount(count($this->values), $this->facet); + $this->assertSameSize($this->values, $this->facet); } public function testIterator() diff --git a/tests/QueryType/Select/Result/Facet/MultiQueryTest.php b/tests/QueryType/Select/Result/Facet/MultiQueryTest.php index a096ab88f..871b93d9b 100644 --- a/tests/QueryType/Select/Result/Facet/MultiQueryTest.php +++ b/tests/QueryType/Select/Result/Facet/MultiQueryTest.php @@ -28,7 +28,7 @@ public function testGetValues() public function testCount() { - $this->assertCount(count($this->values), $this->facet); + $this->assertSameSize($this->values, $this->facet); } public function testIterator() diff --git a/tests/QueryType/Select/Result/Facet/Pivot/PivotItemTest.php b/tests/QueryType/Select/Result/Facet/Pivot/PivotItemTest.php index 6c35cecd0..a2ad8eca5 100644 --- a/tests/QueryType/Select/Result/Facet/Pivot/PivotItemTest.php +++ b/tests/QueryType/Select/Result/Facet/Pivot/PivotItemTest.php @@ -45,6 +45,6 @@ public function testGetCount() public function testCount() { - $this->assertCount(count($this->values['pivot']), $this->pivotItem); + $this->assertSameSize($this->values['pivot'], $this->pivotItem); } } diff --git a/tests/QueryType/Select/Result/Facet/Pivot/PivotTest.php b/tests/QueryType/Select/Result/Facet/Pivot/PivotTest.php index 0773f328b..9527c88fb 100644 --- a/tests/QueryType/Select/Result/Facet/Pivot/PivotTest.php +++ b/tests/QueryType/Select/Result/Facet/Pivot/PivotTest.php @@ -36,6 +36,6 @@ public function testGetPivot() public function testCount() { - $this->assertCount(count($this->values), $this->facet); + $this->assertSameSize($this->values, $this->facet); } } diff --git a/tests/QueryType/Select/Result/Facet/RangeTest.php b/tests/QueryType/Select/Result/Facet/RangeTest.php index 6cc04a953..31ba67912 100644 --- a/tests/QueryType/Select/Result/Facet/RangeTest.php +++ b/tests/QueryType/Select/Result/Facet/RangeTest.php @@ -59,7 +59,7 @@ public function testGetValues() public function testCount() { - $this->assertCount(count($this->values), $this->facet); + $this->assertSameSize($this->values, $this->facet); } public function testIterator() diff --git a/tests/QueryType/Select/Result/FacetSetTest.php b/tests/QueryType/Select/Result/FacetSetTest.php index 4ff2d17ba..3c66b53f0 100644 --- a/tests/QueryType/Select/Result/FacetSetTest.php +++ b/tests/QueryType/Select/Result/FacetSetTest.php @@ -58,7 +58,7 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->facets), $this->result); + $this->assertSameSize($this->facets, $this->result); } } diff --git a/tests/QueryType/Select/Result/Grouping/FieldGroupTest.php b/tests/QueryType/Select/Result/Grouping/FieldGroupTest.php index c4a34a5e7..ba7b22758 100644 --- a/tests/QueryType/Select/Result/Grouping/FieldGroupTest.php +++ b/tests/QueryType/Select/Result/Grouping/FieldGroupTest.php @@ -59,6 +59,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->items), $this->group); + $this->assertSameSize($this->items, $this->group); } } diff --git a/tests/QueryType/Select/Result/Grouping/GroupingTest.php b/tests/QueryType/Select/Result/Grouping/GroupingTest.php index 5e06a3ec3..5f15bd619 100644 --- a/tests/QueryType/Select/Result/Grouping/GroupingTest.php +++ b/tests/QueryType/Select/Result/Grouping/GroupingTest.php @@ -51,6 +51,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->items), $this->grouping); + $this->assertSameSize($this->items, $this->grouping); } } diff --git a/tests/QueryType/Select/Result/Grouping/QueryGroupTest.php b/tests/QueryType/Select/Result/Grouping/QueryGroupTest.php index e3949e5e2..6a6023d63 100644 --- a/tests/QueryType/Select/Result/Grouping/QueryGroupTest.php +++ b/tests/QueryType/Select/Result/Grouping/QueryGroupTest.php @@ -74,6 +74,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->items), $this->group); + $this->assertSameSize($this->items, $this->group); } } diff --git a/tests/QueryType/Select/Result/Grouping/ValueGroupTest.php b/tests/QueryType/Select/Result/Grouping/ValueGroupTest.php index b8d8e2dcc..ec7ee5cfe 100644 --- a/tests/QueryType/Select/Result/Grouping/ValueGroupTest.php +++ b/tests/QueryType/Select/Result/Grouping/ValueGroupTest.php @@ -66,6 +66,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->items), $this->group); + $this->assertSameSize($this->items, $this->group); } } diff --git a/tests/QueryType/Select/Result/Highlighting/HighlightingTest.php b/tests/QueryType/Select/Result/Highlighting/HighlightingTest.php index 452a590e1..4ea00c679 100644 --- a/tests/QueryType/Select/Result/Highlighting/HighlightingTest.php +++ b/tests/QueryType/Select/Result/Highlighting/HighlightingTest.php @@ -57,6 +57,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->items), $this->result); + $this->assertSameSize($this->items, $this->result); } } diff --git a/tests/QueryType/Select/Result/Highlighting/ResultTest.php b/tests/QueryType/Select/Result/Highlighting/ResultTest.php index 0e5a490fa..0472d913d 100644 --- a/tests/QueryType/Select/Result/Highlighting/ResultTest.php +++ b/tests/QueryType/Select/Result/Highlighting/ResultTest.php @@ -57,6 +57,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->fields), $this->result); + $this->assertSameSize($this->fields, $this->result); } } diff --git a/tests/QueryType/Select/Result/Stats/StatsTest.php b/tests/QueryType/Select/Result/Stats/StatsTest.php index cdf156879..2d3368bd4 100644 --- a/tests/QueryType/Select/Result/Stats/StatsTest.php +++ b/tests/QueryType/Select/Result/Stats/StatsTest.php @@ -66,6 +66,6 @@ public function testIterator() public function testCount() { - $this->assertCount(count($this->data), $this->stats); + $this->assertSameSize($this->data, $this->stats); } } diff --git a/tests/QueryType/Spellcheck/Result/ResultTest.php b/tests/QueryType/Spellcheck/Result/ResultTest.php index a8d9a8a64..d1d8c3b49 100644 --- a/tests/QueryType/Spellcheck/Result/ResultTest.php +++ b/tests/QueryType/Spellcheck/Result/ResultTest.php @@ -77,7 +77,7 @@ public function testGetTermsWithInvalidFieldName() public function testCount() { - $this->assertCount(count($this->data), $this->result); + $this->assertSameSize($this->data, $this->result); } public function testIterator() diff --git a/tests/QueryType/Spellcheck/Result/TermTest.php b/tests/QueryType/Spellcheck/Result/TermTest.php index 29c2ce2f8..09607ea75 100644 --- a/tests/QueryType/Spellcheck/Result/TermTest.php +++ b/tests/QueryType/Spellcheck/Result/TermTest.php @@ -79,7 +79,7 @@ public function testGetSuggestions() public function testCount() { - $this->assertCount(count($this->suggestions), $this->result); + $this->assertSameSize($this->suggestions, $this->result); } public function testIterator() diff --git a/tests/QueryType/Suggester/Result/DictionaryTest.php b/tests/QueryType/Suggester/Result/DictionaryTest.php index 6e7ec9319..b7972254c 100644 --- a/tests/QueryType/Suggester/Result/DictionaryTest.php +++ b/tests/QueryType/Suggester/Result/DictionaryTest.php @@ -45,7 +45,7 @@ public function testGetTermWithUnknownKey() public function testCount() { - $this->assertCount(count($this->terms), $this->dictionary); + $this->assertSameSize($this->terms, $this->dictionary); } public function testIterator() diff --git a/tests/QueryType/Suggester/Result/ResultTest.php b/tests/QueryType/Suggester/Result/ResultTest.php index 07b4fda3a..b0c6c0b98 100644 --- a/tests/QueryType/Suggester/Result/ResultTest.php +++ b/tests/QueryType/Suggester/Result/ResultTest.php @@ -83,7 +83,7 @@ public function testGetDictionaryWithInvalidFieldName() public function testCount() { - $this->assertCount(count($this->data), $this->result); + $this->assertSameSize($this->data, $this->result); } public function testIterator() diff --git a/tests/QueryType/Suggester/Result/TermTest.php b/tests/QueryType/Suggester/Result/TermTest.php index 459c9a1b9..42e86334a 100644 --- a/tests/QueryType/Suggester/Result/TermTest.php +++ b/tests/QueryType/Suggester/Result/TermTest.php @@ -51,7 +51,7 @@ public function testGetSuggestions() public function testCount() { - $this->assertCount(count($this->suggestions), $this->result); + $this->assertSameSize($this->suggestions, $this->result); } public function testIterator() diff --git a/tests/QueryType/Terms/ResultTest.php b/tests/QueryType/Terms/ResultTest.php index 02defff11..826b42cfa 100644 --- a/tests/QueryType/Terms/ResultTest.php +++ b/tests/QueryType/Terms/ResultTest.php @@ -72,7 +72,7 @@ public function testGetTermsWithInvalidFieldName() public function testCount() { - $this->assertCount(count($this->data), $this->result); + $this->assertSameSize($this->data, $this->result); } public function testIterator() diff --git a/tests/QueryType/Update/Query/QueryTest.php b/tests/QueryType/Update/Query/QueryTest.php index 679f1c988..9862a7540 100644 --- a/tests/QueryType/Update/Query/QueryTest.php +++ b/tests/QueryType/Update/Query/QueryTest.php @@ -146,9 +146,9 @@ public function testConfigMode() ); $rollback = $commands['key4']; - $this->assertSame( + $this->assertInstanceOf( Rollback::class, - get_class($rollback) + $rollback ); } @@ -522,7 +522,7 @@ public function testSetAndGetDocumentClass() public function testCreateDocument() { $doc = $this->query->createDocument(); - $this->assertThat($doc, $this->isInstanceOf($this->query->getDocumentClass())); + $this->assertInstanceOf($this->query->getDocumentClass(), $doc); } public function testCreateDocumentWithCustomClass() @@ -530,7 +530,7 @@ public function testCreateDocumentWithCustomClass() $this->query->setDocumentClass(__NAMESPACE__.'\\MyCustomDoc'); $doc = $this->query->createDocument(); - $this->assertThat($doc, $this->isInstanceOf(__NAMESPACE__.'\\MyCustomDoc')); + $this->assertInstanceOf(__NAMESPACE__.'\\MyCustomDoc', $doc); } public function testCreateDocumentWithFieldsAndBoostsAndModifiers() @@ -542,7 +542,7 @@ public function testCreateDocumentWithFieldsAndBoostsAndModifiers() $doc = $this->query->createDocument($fields, $boosts, $modifiers); $doc->setKey('id'); - $this->assertThat($doc, $this->isInstanceOf($this->query->getDocumentClass())); + $this->assertInstanceOf($this->query->getDocumentClass(), $doc); $this->assertSame( $fields, diff --git a/tests/Support/DataFixtures/FixtureLoaderTest.php b/tests/Support/DataFixtures/FixtureLoaderTest.php index 3441dab0a..d3f9d9c90 100644 --- a/tests/Support/DataFixtures/FixtureLoaderTest.php +++ b/tests/Support/DataFixtures/FixtureLoaderTest.php @@ -54,12 +54,10 @@ private function mockLoader() $loader->expects($this->once()) ->method('getFixtures') - ->will( - $this->returnValue( - [ - $this->getMockFixture(), - ] - ) + ->willReturn( + [ + $this->getMockFixture(), + ] ); return $loader; diff --git a/tests/Support/UtilityTest.php b/tests/Support/UtilityTest.php index 5c4f1b17f..fb5987d10 100644 --- a/tests/Support/UtilityTest.php +++ b/tests/Support/UtilityTest.php @@ -159,7 +159,7 @@ public function testRecursiveKeySort(array $array, array $expected) $this->assertSame($expected, $array); } - public function recursiveKeySortProvider(): array + public static function recursiveKeySortProvider(): array { return [ [