Skip to content

Commit

Permalink
PHPUnit 9 → 10
Browse files Browse the repository at this point in the history
  • Loading branch information
thomascorthals committed Nov 11, 2024
1 parent 1955d16 commit b5f9101
Show file tree
Hide file tree
Showing 60 changed files with 240 additions and 209 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
php: [8.0, 8.1, 8.2, 8.3, 8.4]
php: [8.1, 8.2, 8.3, 8.4]
solr: [7, 8, 9]
mode: [cloud, server]

Expand Down Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/lucene-solr
/vendor
.idea
/.phpunit.result.cache
/.phpunit.cache
/.php_cs.cache
/.phpcs-cache
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 13 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
backupStaticProperties="false"
cacheDirectory=".phpunit.cache"
colors="true"
convertDeprecationsToExceptions="true"
displayDetailsOnPhpunitDeprecations="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage" lowUpperBound="35" highLowerBound="70"/>
Expand All @@ -21,6 +23,11 @@
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
<logging>
<junit outputFile="build/logs/junit.xml"/>
</logging>
Expand Down
42 changes: 19 additions & 23 deletions tests/Component/Analytics/Facet/ObjectTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@
*/
class ObjectTraitTest extends TestCase
{
/**
* @var ObjectTrait
*/
protected $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));
}

/**
Expand All @@ -34,21 +44,16 @@ 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()));
}

/**
* Test non existing class.
*/
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());
}

/**
Expand All @@ -57,9 +62,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, []));
}

/**
Expand All @@ -68,31 +71,24 @@ 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]));
}

/**
* Test invalid variable type.
*/
public function testInvalidVariableType(): void
{
$mock = $this->getMockForTrait(ObjectTrait::class);

$this->expectException(InvalidArgumentException::class);

$mock->ensureObject(PivotFacet::class, true);
$this->objectTrait->ensureObject(PivotFacet::class, true);
}

/**
* Test invalid mapping type.
*/
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']);
}
}
2 changes: 1 addition & 1 deletion tests/Component/FacetSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public function testCreateFacetWithInvalidType()
$this->facetSet->createFacet('invalidtype');
}

public function createFacetAddProvider()
public static function createFacetAddProvider(): array
{
return [
[true],
Expand Down
8 changes: 4 additions & 4 deletions tests/Component/ResponseParser/AnalyticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions tests/Component/ResponseParser/SpellcheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testParseExtended($data)
);
}

public function providerParseExtended()
public static function providerParseExtended(): array
{
return [
'solr4' => [
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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' => [
Expand Down
2 changes: 1 addition & 1 deletion tests/Component/ResponseParser/SuggesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testParse($data)
$this->assertEquals($allExpected, $result->getAll());
}

public function providerParse()
public static function providerParse(): array
{
return [
0 => [
Expand Down
8 changes: 4 additions & 4 deletions tests/Component/ResponseParser/TermVectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down Expand Up @@ -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(
[
Expand Down Expand Up @@ -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(
[
Expand Down Expand Up @@ -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(
[],
Expand Down
2 changes: 1 addition & 1 deletion tests/Component/Result/Debug/DebugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ public function testIterator()

public function testCount()
{
$this->assertCount(count($this->explain), $this->result);
$this->assertSameSize($this->explain, $this->result);
}
}
2 changes: 1 addition & 1 deletion tests/Component/Result/Debug/DocumentSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public function testIterator()

public function testCount()
{
$this->assertCount(count($this->docs), $this->result);
$this->assertSameSize($this->docs, $this->result);
}
}
2 changes: 1 addition & 1 deletion tests/Component/Result/Debug/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/Component/Result/Debug/TimingPhaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ public function testIterator()

public function testCount()
{
$this->assertCount(count($this->timings), $this->result);
$this->assertSameSize($this->timings, $this->result);
}
}
2 changes: 1 addition & 1 deletion tests/Component/Result/Debug/TimingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public function testIterator()

public function testCount()
{
$this->assertCount(count($this->phases), $this->result);
$this->assertSameSize($this->phases, $this->result);
}
}
2 changes: 1 addition & 1 deletion tests/Component/Result/MoreLikeThis/MoreLikeThisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ public function testIterator()

public function testCount()
{
$this->assertCount(count($this->results), $this->mlt);
$this->assertSameSize($this->results, $this->mlt);
}
}
2 changes: 1 addition & 1 deletion tests/Component/Result/MoreLikeThis/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ public function testIterator()

public function testCount()
{
$this->assertCount(count($this->docs), $this->mltResult);
$this->assertSameSize($this->docs, $this->mltResult);
}
}
2 changes: 1 addition & 1 deletion tests/Component/Result/Spellcheck/CollationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public function testIterator()

public function testCount()
{
$this->assertCount(count($this->corrections), $this->result);
$this->assertSameSize($this->corrections, $this->result);
}
}
2 changes: 1 addition & 1 deletion tests/Component/Result/Spellcheck/SpellcheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ public function testIterator()

public function testCount()
{
$this->assertCount(count($this->suggestions), $this->result);
$this->assertSameSize($this->suggestions, $this->result);
}
}
2 changes: 1 addition & 1 deletion tests/Component/Result/Suggester/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public function testIterator()

public function testCount()
{
$this->assertCount(count($this->docs), $this->result);
$this->assertSameSize($this->docs, $this->result);
}
}
9 changes: 4 additions & 5 deletions tests/Core/Client/Adapter/CurlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Solarium\Exception\HttpException;
use Solarium\Exception\InvalidArgumentException;

/**
* @requires extension curl
*/
class CurlTest extends TestCase
{
use TimeoutAwareTestTrait;
Expand All @@ -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();
}

Expand Down Expand Up @@ -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],
Expand Down
Loading

0 comments on commit b5f9101

Please sign in to comment.