Skip to content

Commit cb33c1c

Browse files
authored
PHPLIB-1369 Upgrade to PHPUnit 10 (#1412)
* Migration from @annotations to #[Attributes] * Replace hasFailed with the method onNotSuccessfulTest in FunctionalTestCase * User createStub in getInvalidDocumentCodecValues * Update custom constraints (TestCase::exporter() is deprecated and ComparisonFailure 5th argument was removed) * Use xxh faster algorithm for temp collection name
1 parent 2186d4f commit cb33c1c

File tree

110 files changed

+609
-627
lines changed

Some content is hidden

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

110 files changed

+609
-627
lines changed

.evergreen/run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ if [ "${IS_MATRIX_TESTING}" = "true" ]; then
4343
fi
4444

4545
# Enable verbose output to see skipped and incomplete tests
46-
PHPUNIT_OPTS="${PHPUNIT_OPTS} -v --configuration phpunit.evergreen.xml"
46+
PHPUNIT_OPTS="${PHPUNIT_OPTS} --configuration phpunit.evergreen.xml"
4747

4848
if [ "$SSL" = "yes" ]; then
4949
SSL_OPTS="ssl=true&sslallowinvalidcertificates=true"

.github/workflows/tests.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ jobs:
7575
php-ini-values: "zend.assertions=1"
7676

7777
- name: "Run PHPUnit"
78-
run: "vendor/bin/phpunit -v"
78+
run: "vendor/bin/phpunit"
7979
env:
80-
SYMFONY_DEPRECATIONS_HELPER: 999999
8180
MONGODB_URI: ${{ steps.setup-mongodb.outputs.cluster-uri }}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
},
2222
"require-dev": {
2323
"doctrine/coding-standard": "^12.0",
24-
"phpunit/phpunit": "^9.6.11",
25-
"rector/rector": "^1.1",
24+
"phpunit/phpunit": "^10.5.35",
25+
"rector/rector": "^1.2",
2626
"squizlabs/php_codesniffer": "^3.7",
2727
"vimeo/psalm": "^5.13"
2828
},

rector.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
use Rector\Config\RectorConfig;
44
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;
55
use Rector\Php70\Rector\StmtsAwareInterface\IfIssetToCoalescingRector;
6+
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
67
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
78
use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector;
9+
use Rector\PHPUnit\Set\PHPUnitSetList;
810
use Rector\Set\ValueObject\LevelSetList;
911

1012
return static function (RectorConfig $rectorConfig): void {
@@ -16,13 +18,17 @@
1618
]);
1719

1820
// Modernize code
19-
$rectorConfig->sets([LevelSetList::UP_TO_PHP_74]);
21+
$rectorConfig->sets([
22+
LevelSetList::UP_TO_PHP_74,
23+
PHPUnitSetList::PHPUNIT_100,
24+
]);
2025

2126
$rectorConfig->rule(ChangeSwitchToMatchRector::class);
2227
$rectorConfig->rule(StaticDataProviderClassMethodRector::class);
2328

2429
// phpcs:disable Squiz.Arrays.ArrayDeclaration.KeySpecified
2530
$rectorConfig->skip([
31+
RemoveExtraParametersRector::class,
2632
// Do not use ternaries extensively
2733
IfIssetToCoalescingRector::class,
2834
ChangeSwitchToMatchRector::class => [

tests/Builder/BuilderEncoderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use MongoDB\Builder\Stage;
1515
use MongoDB\Builder\Type\Sort;
1616
use MongoDB\Builder\Variable;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1718
use PHPUnit\Framework\TestCase;
1819

1920
use function array_merge;
@@ -153,9 +154,8 @@ public function testPerformCount(): void
153154
*
154155
* @param list<int> $limit
155156
* @param array<string, int> $expectedLimit
156-
*
157-
* @dataProvider provideExpressionFilterLimit
158157
*/
158+
#[DataProvider('provideExpressionFilterLimit')]
159159
public function testExpressionFilter(array $limit, array $expectedLimit): void
160160
{
161161
$pipeline = new Pipeline(

tests/Builder/FieldPathTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
use MongoDB\Builder\Expression;
99
use MongoDB\Builder\Type\FieldPathInterface;
1010
use MongoDB\Exception\InvalidArgumentException;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1112
use PHPUnit\Framework\TestCase;
1213

1314
use function is_subclass_of;
1415
use function sprintf;
1516

1617
class FieldPathTest extends TestCase
1718
{
18-
/** @dataProvider provideFieldPath */
19+
#[DataProvider('provideFieldPath')]
1920
public function testFieldPath(string $fieldPathClass, string $resolveClass): void
2021
{
2122
$fieldPath = Expression::{$fieldPathClass}('foo');
@@ -27,7 +28,7 @@ public function testFieldPath(string $fieldPathClass, string $resolveClass): voi
2728
$this->assertTrue(is_subclass_of(Expression\FieldPath::class, $resolveClass), sprintf('%s instanceof %s', Expression\FieldPath::class, $resolveClass));
2829
}
2930

30-
/** @dataProvider provideFieldPath */
31+
#[DataProvider('provideFieldPath')]
3132
public function testRejectDollarPrefix(string $fieldPathClass): void
3233
{
3334
$this->expectException(InvalidArgumentException::class);

tests/Builder/Type/CombinedFieldQueryTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use MongoDB\Builder\Query\GtOperator;
1010
use MongoDB\Builder\Type\CombinedFieldQuery;
1111
use MongoDB\Exception\InvalidArgumentException;
12+
use PHPUnit\Framework\Attributes\DataProvider;
1213
use PHPUnit\Framework\TestCase;
1314

1415
class CombinedFieldQueryTest extends TestCase
@@ -47,7 +48,7 @@ public function testFlattenCombinedFieldQueries(): void
4748
$this->assertCount(3, $fieldQueries->fieldQueries);
4849
}
4950

50-
/** @dataProvider provideInvalidFieldQuery */
51+
#[DataProvider('provideInvalidFieldQuery')]
5152
public function testRejectInvalidFieldQueries(mixed $invalidQuery, string $message = '-'): void
5253
{
5354
$this->expectException(InvalidArgumentException::class);
@@ -71,11 +72,8 @@ public static function provideInvalidFieldQuery(): Generator
7172
yield 'object key without $' => [(object) ['eq' => 1], 'Operator must contain exactly one key starting with $, "eq" given'];
7273
}
7374

74-
/**
75-
* @param array<mixed> $fieldQueries
76-
*
77-
* @dataProvider provideDuplicateOperator
78-
*/
75+
/** @param array<mixed> $fieldQueries */
76+
#[DataProvider('provideDuplicateOperator')]
7977
public function testRejectDuplicateOperator(array $fieldQueries): void
8078
{
8179
$this->expectException(InvalidArgumentException::class);

tests/Builder/Type/OutputWindowTest.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use MongoDB\Builder\Type\TimeUnit;
1111
use MongoDB\Builder\Type\WindowInterface;
1212
use MongoDB\Exception\InvalidArgumentException;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314
use PHPUnit\Framework\TestCase;
1415

1516
class OutputWindowTest extends TestCase
@@ -57,11 +58,8 @@ public function testWithUnit(): void
5758
$this->assertEquals((object) ['unit' => TimeUnit::Day], $outputWindow->window);
5859
}
5960

60-
/**
61-
* @param array<mixed> $documents
62-
*
63-
* @dataProvider provideInvalidDocuments
64-
*/
61+
/** @param array<mixed> $documents */
62+
#[DataProvider('provideInvalidDocuments')]
6563
public function testRejectInvalidDocuments(array $documents): void
6664
{
6765
$this->expectException(InvalidArgumentException::class);
@@ -82,11 +80,8 @@ public static function provideInvalidDocuments(): Generator
8280
yield 'not a list' => [['foo' => 1, 'bar' => 2]];
8381
}
8482

85-
/**
86-
* @param array<mixed> $range
87-
*
88-
* @dataProvider provideInvalidRange
89-
*/
83+
/** @param array<mixed> $range */
84+
#[DataProvider('provideInvalidRange')]
9085
public function testRejectInvalidRange(array $range): void
9186
{
9287
$this->expectException(InvalidArgumentException::class);

tests/Builder/Type/QueryObjectTest.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use MongoDB\Builder\Type\CombinedFieldQuery;
1414
use MongoDB\Builder\Type\QueryInterface;
1515
use MongoDB\Builder\Type\QueryObject;
16+
use PHPUnit\Framework\Attributes\DataProvider;
1617
use PHPUnit\Framework\TestCase;
1718

1819
class QueryObjectTest extends TestCase
@@ -32,23 +33,17 @@ public function testShortCutQueryObject(): void
3233
$this->assertSame($query, $queryObject);
3334
}
3435

35-
/**
36-
* @param array<array-key, mixed> $value
37-
*
38-
* @dataProvider provideQueryObjectValue
39-
*/
36+
/** @param array<array-key, mixed> $value */
37+
#[DataProvider('provideQueryObjectValue')]
4038
public function testCreateQueryObject(array $value, int $expectedCount = 1): void
4139
{
4240
$queryObject = QueryObject::create($value);
4341

4442
$this->assertCount($expectedCount, $queryObject->queries);
4543
}
4644

47-
/**
48-
* @param array<array-key, mixed> $value
49-
*
50-
* @dataProvider provideQueryObjectValue
51-
*/
45+
/** @param array<array-key, mixed> $value */
46+
#[DataProvider('provideQueryObjectValue')]
5247
public function testCreateQueryObjectFromArray(array $value, int $expectedCount = 1): void
5348
{
5449
// $value is wrapped in an array as if the user used an array instead of variadic arguments

tests/Builder/VariableTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use MongoDB\Builder\Expression;
99
use MongoDB\Builder\Variable;
1010
use MongoDB\Exception\InvalidArgumentException;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1112
use PHPUnit\Framework\TestCase;
1213

1314
class VariableTest extends TestCase
@@ -27,7 +28,7 @@ public function testVariableRejectDollarPrefix(): void
2728
new Expression\Variable('$$foo');
2829
}
2930

30-
/** @dataProvider provideVariableBuilders */
31+
#[DataProvider('provideVariableBuilders')]
3132
public function testSystemVariables($factory): void
3233
{
3334
$variable = $factory();

0 commit comments

Comments
 (0)