Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPUnit 9 → 10 #1144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
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 || ^7.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"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnPhpunitDeprecations="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
8 changes: 1 addition & 7 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class ClientTest extends TestCase
{
/**
* @var string
*/
protected static $installedVersion;
protected static string $installedVersion;

public static function setUpBeforeClass(): void
{
Expand All @@ -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()
Expand Down
39 changes: 16 additions & 23 deletions tests/Component/Analytics/Facet/ObjectTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand All @@ -34,21 +41,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 +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, []));
}

/**
Expand All @@ -68,31 +68,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']);
}
}
68 changes: 68 additions & 0 deletions tests/Component/DisMaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public function testSetAndGetBoostQuery()
);
}

public function testGetBoostQueryWithNonExistentKey()
{
$this->assertNull($this->disMax->getBoostQuery('foobar'));
}

public function testAddBoostQueryWithArray()
{
$query = 'cat:1^3';
Expand Down Expand Up @@ -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';
Expand Down
35 changes: 24 additions & 11 deletions tests/Component/Facet/PivotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,39 +145,52 @@ 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());
}

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());
}
}
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
Loading
Loading