Skip to content

Commit 5888c6d

Browse files
Merge v1.x into v2.x (#1469)
2 parents ea818c8 + 23c033e commit 5888c6d

File tree

110 files changed

+609
-626
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
-626
lines changed

.evergreen/run-tests.sh

+1-1
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

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ jobs:
7777
php-ini-values: "zend.assertions=1"
7878

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

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
},
2121
"require-dev": {
2222
"doctrine/coding-standard": "^12.0",
23-
"phpunit/phpunit": "^9.6.11",
24-
"rector/rector": "^1.1",
23+
"phpunit/phpunit": "^10.5.35",
24+
"rector/rector": "^1.2",
2525
"squizlabs/php_codesniffer": "^3.7",
2626
"vimeo/psalm": "^5.13"
2727
},

rector.php

+7-1
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

+2-2
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

+3-2
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

+4-6
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

+5-10
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

+5-10
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

+2-1
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();

tests/ClientTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use MongoDB\Driver\ReadPreference;
1111
use MongoDB\Driver\WriteConcern;
1212
use MongoDB\Exception\InvalidArgumentException;
13+
use PHPUnit\Framework\Attributes\DataProvider;
14+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
1315

1416
/**
1517
* Unit tests for the Client class.
@@ -23,7 +25,7 @@ public function testConstructorDefaultUri(): void
2325
$this->assertEquals('mongodb://127.0.0.1/', (string) $client);
2426
}
2527

26-
/** @doesNotPerformAssertions */
28+
#[DoesNotPerformAssertions]
2729
public function testConstructorAutoEncryptionOpts(): void
2830
{
2931
$autoEncryptionOpts = [
@@ -35,7 +37,7 @@ public function testConstructorAutoEncryptionOpts(): void
3537
new Client(static::getUri(), [], ['autoEncryption' => $autoEncryptionOpts]);
3638
}
3739

38-
/** @dataProvider provideInvalidConstructorDriverOptions */
40+
#[DataProvider('provideInvalidConstructorDriverOptions')]
3941
public function testConstructorDriverOptionTypeChecks(array $driverOptions, string $exception = InvalidArgumentException::class): void
4042
{
4143
$this->expectException($exception);

tests/Collection/CodecCollectionFunctionalTest.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use MongoDB\Operation\FindOneAndReplace;
1313
use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec;
1414
use MongoDB\Tests\Fixtures\Document\TestObject;
15+
use PHPUnit\Framework\Attributes\DataProvider;
1516

1617
class CodecCollectionFunctionalTest extends FunctionalTestCase
1718
{
@@ -54,7 +55,7 @@ public static function provideAggregateOptions(): Generator
5455
];
5556
}
5657

57-
/** @dataProvider provideAggregateOptions */
58+
#[DataProvider('provideAggregateOptions')]
5859
public function testAggregate($expected, $options): void
5960
{
6061
$this->createFixtures(3);
@@ -114,7 +115,7 @@ public static function provideBulkWriteOptions(): Generator
114115
];
115116
}
116117

117-
/** @dataProvider provideBulkWriteOptions */
118+
#[DataProvider('provideBulkWriteOptions')]
118119
public function testBulkWrite($expected, $options): void
119120
{
120121
$this->createFixtures(3);
@@ -169,7 +170,7 @@ public static function provideFindOneAndModifyOptions(): Generator
169170
];
170171
}
171172

172-
/** @dataProvider provideFindOneAndModifyOptions */
173+
#[DataProvider('provideFindOneAndModifyOptions')]
173174
public function testFindOneAndDelete($expected, $options): void
174175
{
175176
$this->createFixtures(1);
@@ -190,7 +191,7 @@ public function testFindOneAndDeleteWithCodecAndTypemap(): void
190191
$this->collection->findOneAndDelete(['_id' => 1], $options);
191192
}
192193

193-
/** @dataProvider provideFindOneAndModifyOptions */
194+
#[DataProvider('provideFindOneAndModifyOptions')]
194195
public function testFindOneAndUpdate($expected, $options): void
195196
{
196197
$this->createFixtures(1);
@@ -235,7 +236,7 @@ public static function provideFindOneAndReplaceOptions(): Generator
235236
];
236237
}
237238

238-
/** @dataProvider provideFindOneAndReplaceOptions */
239+
#[DataProvider('provideFindOneAndReplaceOptions')]
239240
public function testFindOneAndReplace($expected, $options): void
240241
{
241242
$this->createFixtures(1);
@@ -293,7 +294,7 @@ public static function provideFindOptions(): Generator
293294
];
294295
}
295296

296-
/** @dataProvider provideFindOptions */
297+
#[DataProvider('provideFindOptions')]
297298
public function testFind($expected, $options): void
298299
{
299300
$this->createFixtures(3);
@@ -332,7 +333,7 @@ public static function provideFindOneOptions(): Generator
332333
];
333334
}
334335

335-
/** @dataProvider provideFindOneOptions */
336+
#[DataProvider('provideFindOneOptions')]
336337
public function testFindOne($expected, $options): void
337338
{
338339
$this->createFixtures(1);
@@ -383,7 +384,7 @@ public static function provideInsertManyOptions(): Generator
383384
];
384385
}
385386

386-
/** @dataProvider provideInsertManyOptions */
387+
#[DataProvider('provideInsertManyOptions')]
387388
public function testInsertMany($expected, $options): void
388389
{
389390
$documents = [
@@ -430,7 +431,7 @@ public static function provideInsertOneOptions(): Generator
430431
];
431432
}
432433

433-
/** @dataProvider provideInsertOneOptions */
434+
#[DataProvider('provideInsertOneOptions')]
434435
public function testInsertOne($expected, $options): void
435436
{
436437
$result = $this->collection->insertOne(TestObject::createForFixture(1), $options);
@@ -475,7 +476,7 @@ public static function provideReplaceOneOptions(): Generator
475476
];
476477
}
477478

478-
/** @dataProvider provideReplaceOneOptions */
479+
#[DataProvider('provideReplaceOneOptions')]
479480
public function testReplaceOne($expected, $options): void
480481
{
481482
$this->createFixtures(1);

0 commit comments

Comments
 (0)