From df90eda762b2eeb158ff067397b0ccedbfe7830d Mon Sep 17 00:00:00 2001 From: thomascorthals Date: Mon, 30 Dec 2024 21:55:37 +0100 Subject: [PATCH] PHPUnit 10 --- .github/workflows/run-tests.yml | 6 +- .gitignore | 2 +- composer.json | 2 +- phpunit.xml | 19 +- tests/ClientTest.php | 8 +- .../Analytics/Facet/ObjectTraitTest.php | 39 ++-- tests/Component/FacetSetTest.php | 2 +- .../ResponseParser/AnalyticsTest.php | 8 +- .../ResponseParser/SpellcheckTest.php | 6 +- .../ResponseParser/SuggesterTest.php | 2 +- .../ResponseParser/TermVectorTest.php | 8 +- tests/Component/Result/Debug/DebugTest.php | 2 +- .../Result/Debug/DocumentSetTest.php | 2 +- tests/Component/Result/Debug/DocumentTest.php | 2 +- .../Result/Debug/TimingPhaseTest.php | 2 +- tests/Component/Result/Debug/TimingTest.php | 2 +- .../Result/MoreLikeThis/MoreLikeThisTest.php | 2 +- .../Result/MoreLikeThis/ResultTest.php | 2 +- .../Result/Spellcheck/CollationTest.php | 2 +- .../Result/Spellcheck/SpellcheckTest.php | 2 +- .../Component/Result/Suggester/ResultTest.php | 2 +- tests/Core/Client/Adapter/CurlTest.php | 9 +- tests/Core/Client/ClientTest.php | 189 +++++++++++------- tests/Core/Client/EndpointTest.php | 20 +- tests/Core/Client/RequestTest.php | 10 +- tests/Core/Query/HelperTest.php | 8 +- tests/Core/Query/Result/ResultTest.php | 4 +- tests/Integration/AbstractCloudTestCase.php | 9 +- tests/Integration/AbstractServerTestCase.php | 3 +- .../AbstractTechproductsTestCase.php | 131 ++++++------ tests/Integration/ConnectionReuseTest.php | 73 +++---- .../Proxy/AbstractProxyTestCase.php | 27 +-- .../Query/CustomQueryClassTest.php | 2 +- tests/Integration/SolrCloud/CurlTest.php | 6 +- tests/Integration/SolrServer/CurlTest.php | 6 +- .../BufferedDelete/BufferedDeleteLiteTest.php | 2 +- .../Plugin/MinimumScoreFilter/ResultTest.php | 2 +- .../Analysis/ResponseParser/DocumentTest.php | 2 +- .../Analysis/Result/DocumentTest.php | 2 +- tests/QueryType/Analysis/Result/FieldTest.php | 2 +- .../Analysis/Result/ResultListTest.php | 2 +- tests/QueryType/Analysis/Result/TypesTest.php | 2 +- .../ResponseParser/ResourcesTest.php | 2 +- .../Result/AbstractDocumentTestCase.php | 2 +- .../Select/Result/AbstractResultTestCase.php | 2 +- .../Select/Result/Facet/FieldTest.php | 2 +- .../Select/Result/Facet/MultiQueryTest.php | 2 +- .../Result/Facet/Pivot/PivotItemTest.php | 2 +- .../Select/Result/Facet/Pivot/PivotTest.php | 2 +- .../Select/Result/Facet/RangeTest.php | 2 +- .../QueryType/Select/Result/FacetSetTest.php | 2 +- .../Select/Result/Grouping/FieldGroupTest.php | 2 +- .../Select/Result/Grouping/GroupingTest.php | 2 +- .../Select/Result/Grouping/QueryGroupTest.php | 2 +- .../Select/Result/Grouping/ValueGroupTest.php | 2 +- .../Result/Highlighting/HighlightingTest.php | 2 +- .../Select/Result/Highlighting/ResultTest.php | 2 +- .../Select/Result/Stats/StatsTest.php | 2 +- .../Spellcheck/Result/ResultTest.php | 2 +- .../QueryType/Spellcheck/Result/TermTest.php | 2 +- .../Suggester/Result/DictionaryTest.php | 2 +- .../QueryType/Suggester/Result/ResultTest.php | 2 +- tests/QueryType/Suggester/Result/TermTest.php | 2 +- tests/QueryType/Terms/ResultTest.php | 2 +- .../DataFixtures/FixtureLoaderTest.php | 10 +- tests/Support/UtilityTest.php | 2 +- 66 files changed, 352 insertions(+), 337 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 03c100040..0b849fbd3 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -15,8 +15,8 @@ jobs: strategy: matrix: php: [8.1, 8.2, 8.3, 8.4] - solr: [7, 8, 9] - mode: [cloud, server] + solr: [8, 9] + mode: [server] name: PHP ${{ matrix.php }}, Solr ${{ matrix.solr }} ${{ matrix.mode }} @@ -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/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/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..9ee61ebab 100644 --- a/tests/Core/Client/ClientTest.php +++ b/tests/Core/Client/ClientTest.php @@ -519,13 +519,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 +537,7 @@ public function testCreateRequestPrePlugin() ); $this->client->createRequest($query); + $this->assertEquals($expectedEvent, $observer->event); } public function testCreateRequestPostPlugin() @@ -546,13 +550,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 +568,7 @@ public function testCreateRequestPostPlugin() ); $this->client->createRequest($query); + $this->assertEquals($expectedEvent, $observer->event); } public function testCreateRequestWithOverridingPlugin() @@ -614,13 +622,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 +640,7 @@ public function testCreateResultPrePlugin() ); $this->client->createResult($query, $response); + $this->assertEquals($expectedEvent, $observer->event); } public function testCreateResultPostPlugin() @@ -641,13 +653,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 +672,7 @@ public function testCreateResultPostPlugin() ); $this->client->createResult($query, $response); + $this->assertEquals($expectedEvent, $observer->event); } public function testCreateResultWithOverridingPlugin() @@ -751,13 +768,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 +787,7 @@ public function testExecutePrePlugin() } $mock->execute($query); + $this->assertEquals($expectedEvent, $observer->event); } public function testExecutePostPlugin() @@ -793,13 +814,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 +833,7 @@ public function testExecutePostPlugin() } $mock->execute($query); + $this->assertEquals($expectedEvent, $observer->event); } public function testExecuteWithOverridingPlugin() @@ -881,19 +906,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 +946,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() @@ -1222,16 +1257,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 +1317,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 +1334,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/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..fde41d600 100644 --- a/tests/Integration/AbstractCloudTestCase.php +++ b/tests/Integration/AbstractCloudTestCase.php @@ -60,19 +60,16 @@ public static function tearDownAfterClass(): void $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() diff --git a/tests/Integration/AbstractServerTestCase.php b/tests/Integration/AbstractServerTestCase.php index 9996fec63..26c389f53 100644 --- a/tests/Integration/AbstractServerTestCase.php +++ b/tests/Integration/AbstractServerTestCase.php @@ -43,8 +43,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..04e2cfc54 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; @@ -67,36 +67,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 +145,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__. @@ -199,27 +169,7 @@ public static function setUpBeforeClass(): void $update = self::$client->createUpdate(); $update->addCommit(true, 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 +179,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 +191,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 +203,67 @@ 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(), ); } + /** + * Test that the techproducts sample data was indexed correctly. + */ + public function testSampleData() + { + $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); + } + + /** + * Test that update handler was configured correctly for our update tests. + */ + public function testUpdateConfig() + { + $message = '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); + } + /** * @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(), ); } 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/MinimumScoreFilter/ResultTest.php b/tests/Plugin/MinimumScoreFilter/ResultTest.php index ace7c1aac..e0137a9d1 100644 --- a/tests/Plugin/MinimumScoreFilter/ResultTest.php +++ b/tests/Plugin/MinimumScoreFilter/ResultTest.php @@ -36,7 +36,7 @@ public function testIterator() public function testGetDocuments() { - $this->assertCount(count($this->docs), $this->result->getDocuments()); + $this->assertSameSize($this->docs, $this->result->getDocuments()); } public function testIteratorWithRemoveFilter() 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/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..fb202c50e 100644 --- a/tests/QueryType/Select/Result/AbstractResultTestCase.php +++ b/tests/QueryType/Select/Result/AbstractResultTestCase.php @@ -102,7 +102,7 @@ public function testGetFacetSet() public function testCount() { - $this->assertCount(\count($this->docs), $this->result); + $this->assertSameSize($this->docs, $this->result); } public function testGetComponents() 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/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 [ [