Skip to content

Commit 0878557

Browse files
PHPUnit 9 → 10 (#1144)
* PHPUnit 9 → 10 * Additional test coverage --------- Co-authored-by: Markus Kalkbrenner <git@kalki.de>
1 parent 6adbd6d commit 0878557

75 files changed

Lines changed: 613 additions & 526 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
- name: Run tests
8181
run: |
8282
vendor/bin/phpstan analyze src/ tests/ --level=1 --memory-limit=1G
83-
vendor/bin/phpunit -c phpunit.xml --exclude-group skip_for_solr_${{ matrix.mode }} -v --coverage-clover build/logs/clover.xml
83+
vendor/bin/phpunit -c phpunit.xml --exclude-group skip_for_solr_${{ matrix.mode }} --coverage-clover build/logs/clover.xml
8484
8585
- name: Execute examples
8686
run: |

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/lucene-solr
44
/vendor
55
.idea
6-
/.phpunit.result.cache
6+
/.phpunit.cache
77
/.php_cs.cache
88
/.phpcs-cache
99
.DS_Store

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"phpstan/phpstan": "^1.0",
3232
"phpstan/phpstan-deprecation-rules": "^1.0",
3333
"phpstan/phpstan-phpunit": "^1.0",
34-
"phpunit/phpunit": "^9.6",
34+
"phpunit/phpunit": "^10.5",
3535
"rawr/phpunit-data-provider": "^3.3",
3636
"roave/security-advisories": "dev-master",
3737
"symfony/event-dispatcher": "^5.0 || ^6.0 || ^7.0"

phpunit.xml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
55
backupGlobals="false"
6-
backupStaticAttributes="false"
6+
backupStaticProperties="false"
7+
cacheDirectory=".phpunit.cache"
78
colors="true"
8-
convertDeprecationsToExceptions="true"
9+
displayDetailsOnTestsThatTriggerDeprecations="true"
10+
displayDetailsOnPhpunitDeprecations="true"
11+
displayDetailsOnTestsThatTriggerErrors="true"
12+
displayDetailsOnTestsThatTriggerNotices="true"
13+
displayDetailsOnTestsThatTriggerWarnings="true"
914
>
1015
<coverage>
11-
<include>
12-
<directory suffix=".php">src</directory>
13-
</include>
1416
<report>
1517
<clover outputFile="build/logs/clover.xml"/>
1618
<html outputDirectory="build/coverage" lowUpperBound="35" highLowerBound="70"/>
@@ -21,6 +23,11 @@
2123
<directory suffix="Test.php">tests</directory>
2224
</testsuite>
2325
</testsuites>
26+
<source>
27+
<include>
28+
<directory suffix=".php">src</directory>
29+
</include>
30+
</source>
2431
<logging>
2532
<junit outputFile="build/logs/junit.xml"/>
2633
</logging>

tests/ClientTest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
class ClientTest extends TestCase
1010
{
11-
/**
12-
* @var string
13-
*/
14-
protected static $installedVersion;
11+
protected static string $installedVersion;
1512

1613
public static function setUpBeforeClass(): void
1714
{
@@ -23,11 +20,8 @@ public static function setUpBeforeClass(): void
2320
;
2421

2522
if (!preg_match($semverRegex, self::$installedVersion)) {
26-
self::assertSame(self::$installedVersion, Client::getVersion());
2723
self::markTestSkipped(sprintf('Skipping tests against non-semantic version string %s.', self::$installedVersion));
2824
}
29-
30-
parent::setUpBeforeClass();
3125
}
3226

3327
public function testGetVersion()

tests/Component/Analytics/Facet/ObjectTraitTest.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@
1818
*/
1919
class ObjectTraitTest extends TestCase
2020
{
21+
protected object $objectTrait;
22+
23+
public function setUp(): void
24+
{
25+
$this->objectTrait = new class() {
26+
use ObjectTrait;
27+
};
28+
}
29+
2130
/**
2231
* @throws \PHPUnit\Framework\ExpectationFailedException
2332
*/
2433
public function testNullReturn(): void
2534
{
26-
$mock = $this->getMockForTrait(ObjectTrait::class);
27-
28-
$this->assertNull($mock->ensureObject(AbstractFacet::class, null));
35+
$this->assertNull($this->objectTrait->ensureObject(AbstractFacet::class, null));
2936
}
3037

3138
/**
@@ -34,21 +41,16 @@ public function testNullReturn(): void
3441
*/
3542
public function testReturnVariable(): void
3643
{
37-
$mock = $this->getMockForTrait(ObjectTrait::class);
38-
39-
$this->assertInstanceOf(PivotFacet::class, $mock->ensureObject(AbstractFacet::class, new PivotFacet()));
44+
$this->assertInstanceOf(PivotFacet::class, $this->objectTrait->ensureObject(AbstractFacet::class, new PivotFacet()));
4045
}
4146

4247
/**
4348
* Test non existing class.
4449
*/
4550
public function testNonExistingClass(): void
4651
{
47-
$mock = $this->getMockForTrait(ObjectTrait::class);
48-
4952
$this->expectException(InvalidArgumentException::class);
50-
51-
$mock->ensureObject('Foo\Bar', new PivotFacet());
53+
$this->objectTrait->ensureObject('Foo\Bar', new PivotFacet());
5254
}
5355

5456
/**
@@ -57,9 +59,7 @@ public function testNonExistingClass(): void
5759
*/
5860
public function testFromArray(): void
5961
{
60-
$mock = $this->getMockForTrait(ObjectTrait::class);
61-
62-
$this->assertInstanceOf(Sort::class, $mock->ensureObject(Sort::class, []));
62+
$this->assertInstanceOf(Sort::class, $this->objectTrait->ensureObject(Sort::class, []));
6363
}
6464

6565
/**
@@ -68,31 +68,24 @@ public function testFromArray(): void
6868
*/
6969
public function testFromClassMap(): void
7070
{
71-
$mock = $this->getMockForTrait(ObjectTrait::class);
72-
73-
$this->assertInstanceOf(PivotFacet::class, $mock->ensureObject(AbstractFacet::class, ['type' => AbstractFacet::TYPE_PIVOT]));
71+
$this->assertInstanceOf(PivotFacet::class, $this->objectTrait->ensureObject(AbstractFacet::class, ['type' => AbstractFacet::TYPE_PIVOT]));
7472
}
7573

7674
/**
7775
* Test invalid variable type.
7876
*/
7977
public function testInvalidVariableType(): void
8078
{
81-
$mock = $this->getMockForTrait(ObjectTrait::class);
82-
8379
$this->expectException(InvalidArgumentException::class);
84-
85-
$mock->ensureObject(PivotFacet::class, true);
80+
$this->objectTrait->ensureObject(PivotFacet::class, true);
8681
}
8782

8883
/**
8984
* Test invalid mapping type.
9085
*/
9186
public function testInvalidMappingType(): void
9287
{
93-
$mock = $this->getMockForTrait(ObjectTrait::class);
94-
9588
$this->expectException(InvalidArgumentException::class);
96-
$mock->ensureObject(AbstractFacet::class, ['type' => 'foo']);
89+
$this->objectTrait->ensureObject(AbstractFacet::class, ['type' => 'foo']);
9790
}
9891
}

tests/Component/DisMaxTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ public function testSetAndGetBoostQuery()
157157
);
158158
}
159159

160+
public function testGetBoostQueryWithNonExistentKey()
161+
{
162+
$this->assertNull($this->disMax->getBoostQuery('foobar'));
163+
}
164+
160165
public function testAddBoostQueryWithArray()
161166
{
162167
$query = 'cat:1^3';
@@ -249,6 +254,69 @@ public function testAddBoostQueriesWithOuterKeys()
249254
$this->assertEquals($bqs2, $this->disMax->getBoostQueries());
250255
}
251256

257+
public function testRemoveBoostQueryByKey()
258+
{
259+
$bqs = [
260+
'key1' => ['query' => 'cat:1'],
261+
'key2' => ['query' => 'cat:2'],
262+
];
263+
264+
$this->disMax->addBoostQueries($bqs);
265+
$this->disMax->removeBoostQuery('key1');
266+
267+
$this->assertNull($this->disMax->getBoostQuery('key1'));
268+
$this->assertNotNull($this->disMax->getBoostQuery('key2'));
269+
}
270+
271+
public function testRemoveBoostQueryByObject()
272+
{
273+
$bq1 = new BoostQuery();
274+
$bq1->setKey('key1')->setQuery('cat:1');
275+
276+
$bq2 = new BoostQuery();
277+
$bq2->setKey('key2')->setQuery('cat:2');
278+
279+
$this->disMax->addBoostQueries([$bq1, $bq2]);
280+
$this->disMax->removeBoostQuery($bq1);
281+
282+
$this->assertNull($this->disMax->getBoostQuery('key1'));
283+
$this->assertNotNull($this->disMax->getBoostQuery('key2'));
284+
}
285+
286+
public function testClearBoostQueries()
287+
{
288+
$bqs = [
289+
'key1' => ['query' => 'cat:1'],
290+
'key2' => ['query' => 'cat:2'],
291+
];
292+
293+
$this->disMax->addBoostQueries($bqs);
294+
$this->disMax->clearBoostQueries();
295+
296+
$this->assertCount(0, $this->disMax->getBoostQueries());
297+
}
298+
299+
public function testSetBoostQueries()
300+
{
301+
$bqs1 = [
302+
'key1' => (new BoostQuery())->setKey('key1')->setQuery('cat:1'),
303+
'key2' => (new BoostQuery())->setKey('key2')->setQuery('cat:2'),
304+
];
305+
306+
$this->disMax->setBoostQueries($bqs1);
307+
308+
$this->assertSame($bqs1, $this->disMax->getBoostQueries());
309+
310+
$bqs2 = [
311+
'key3' => (new BoostQuery())->setKey('key3')->setQuery('cat:3'),
312+
'key4' => (new BoostQuery())->setKey('key4')->setQuery('cat:4'),
313+
];
314+
315+
$this->disMax->setBoostQueries($bqs2);
316+
317+
$this->assertSame($bqs2, $this->disMax->getBoostQueries());
318+
}
319+
252320
public function testSetAndGetBoostFunctions()
253321
{
254322
$value = 'funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2';

tests/Component/Facet/PivotTest.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,39 +145,52 @@ public function testAddStat()
145145
{
146146
$expectedStats = $this->facet->getLocalParameters()->getStats();
147147
$expectedStats[] = 'newstat';
148-
$this->facet->getLocalParameters()->setStat('newstat');
148+
$this->facet->addStat('newstat');
149+
$this->assertSame($expectedStats, $this->facet->getStats());
149150
$this->assertSame($expectedStats, $this->facet->getLocalParameters()->getStats());
150151
}
151152

152153
public function testClearStats()
153154
{
154-
$this->facet->getLocalParameters()->setStat('newstat');
155-
$this->facet->getLocalParameters()->clearStats();
155+
$this->facet->addStat('newstat');
156+
$this->facet->clearStats();
157+
$this->assertSame([], $this->facet->getStats());
156158
$this->assertSame([], $this->facet->getLocalParameters()->getStats());
157159
}
158160

159161
public function testAddStats()
160162
{
161163
$stats = ['stat1', 'stat2'];
162164

163-
$this->facet->getLocalParameters()->clearStats();
164-
$this->facet->getLocalParameters()->addStats($stats);
165+
$this->facet->clearStats();
166+
$this->facet->addStats($stats);
167+
$this->assertSame($stats, $this->facet->getStats());
165168
$this->assertSame($stats, $this->facet->getLocalParameters()->getStats());
166169
}
167170

171+
public function testAddStatsAsString()
172+
{
173+
$this->facet->clearStats();
174+
$this->facet->addStats('stat1, stat2');
175+
$this->assertSame(['stat1', 'stat2'], $this->facet->getStats());
176+
$this->assertSame(['stat1', 'stat2'], $this->facet->getLocalParameters()->getStats());
177+
}
178+
168179
public function testRemoveStat()
169180
{
170-
$this->facet->getLocalParameters()->clearStats();
171-
$this->facet->getLocalParameters()->addStats(['stat1', 'stat2']);
172-
$this->facet->getLocalParameters()->removeStat('stat1');
181+
$this->facet->clearStats();
182+
$this->facet->addStats(['stat1', 'stat2']);
183+
$this->facet->removeStat('stat1');
184+
$this->assertSame(['stat2'], $this->facet->getStats());
173185
$this->assertSame(['stat2'], $this->facet->getLocalParameters()->getStats());
174186
}
175187

176188
public function testSetStats()
177189
{
178-
$this->facet->getLocalParameters()->clearStats();
179-
$this->facet->getLocalParameters()->setStats(['stat1', 'stat2']);
180-
$this->facet->getLocalParameters()->setStats(['stat3', 'stat4']);
190+
$this->facet->clearStats();
191+
$this->facet->setStats(['stat1', 'stat2']);
192+
$this->facet->setStats(['stat3', 'stat4']);
181193
$this->assertSame(['stat3', 'stat4'], $this->facet->getStats());
194+
$this->assertSame(['stat3', 'stat4'], $this->facet->getLocalParameters()->getStats());
182195
}
183196
}

tests/Component/FacetSetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public function testCreateFacetWithInvalidType()
427427
$this->facetSet->createFacet('invalidtype');
428428
}
429429

430-
public function createFacetAddProvider()
430+
public static function createFacetAddProvider(): array
431431
{
432432
return [
433433
[true],

tests/Component/ResponseParser/AnalyticsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ public function testParseData(): void
102102
$parser = new ResponseParser();
103103
$result = $parser->parse(null, $component, $data);
104104

105-
$this->assertCount(\count($result->getResults()), $result);
106-
$this->assertCount(\count($result->getIterator()), $result);
105+
$this->assertSameSize($result->getResults(), $result);
106+
$this->assertSameSize($result->getIterator(), $result);
107107
$this->assertArrayHasKey('geo_sales', $result->getGroupings());
108108

109109
$this->assertInstanceOf(AnalyticsResult::class, $result);
@@ -123,8 +123,8 @@ public function testParseData(): void
123123
$this->assertSame('country', $facets[0]->getPivot());
124124
$this->assertSame('usa', $facets[0]->getValue());
125125

126-
$this->assertCount(\count($facets[0]->getResults()), $facets[0]);
127-
$this->assertCount(\count($facets[0]->getIterator()), $facets[0]);
126+
$this->assertSameSize($facets[0]->getResults(), $facets[0]);
127+
$this->assertSameSize($facets[0]->getIterator(), $facets[0]);
128128

129129
$this->assertCount(1, $facets[0]->getChildren());
130130
$this->assertCount(1, $facets[0]->getChildren()[0]->getChildren());

0 commit comments

Comments
 (0)