From cb33c1c92b5d5cead5f18996db5825cc6064e81f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 27 Sep 2024 09:07:17 +0200 Subject: [PATCH] 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 --- .evergreen/run-tests.sh | 2 +- .github/workflows/tests.yml | 3 +- composer.json | 4 +- rector.php | 8 +- tests/Builder/BuilderEncoderTest.php | 4 +- tests/Builder/FieldPathTest.php | 5 +- tests/Builder/Type/CombinedFieldQueryTest.php | 10 +- tests/Builder/Type/OutputWindowTest.php | 15 +-- tests/Builder/Type/QueryObjectTest.php | 15 +-- tests/Builder/VariableTest.php | 3 +- tests/ClientTest.php | 6 +- .../CodecCollectionFunctionalTest.php | 21 ++-- tests/Collection/CollectionFunctionalTest.php | 26 ++--- tests/Command/ListCollectionsTest.php | 3 +- tests/Command/ListDatabasesTest.php | 3 +- tests/Comparator/Int64Comparator.php | 10 +- tests/Comparator/Int64ComparatorTest.php | 12 +-- tests/Comparator/ServerComparator.php | 3 +- tests/Database/DatabaseFunctionalTest.php | 16 +-- tests/DocumentationExamplesTest.php | 8 +- tests/ExamplesTest.php | 10 +- .../InvalidArgumentExceptionTest.php | 3 +- tests/FunctionalTestCase.php | 12 ++- .../Functions/SelectServerFunctionalTest.php | 3 +- tests/FunctionsTest.php | 23 ++-- tests/GridFS/BucketFunctionalTest.php | 32 +++--- tests/GridFS/FunctionalTestCase.php | 7 +- tests/GridFS/ReadableStreamFunctionalTest.php | 13 +-- tests/GridFS/StreamWrapperFunctionalTest.php | 3 +- tests/GridFS/WritableStreamFunctionalTest.php | 8 +- tests/LogNonGenuineHostTest.php | 7 +- tests/Model/BSONIteratorTest.php | 3 +- tests/Model/CallbackIteratorTest.php | 3 +- tests/Model/ChangeStreamIteratorTest.php | 7 +- tests/Model/CodecCursorFunctionalTest.php | 6 +- tests/Model/IndexInfoFunctionalTest.php | 9 +- tests/Model/IndexInputTest.php | 9 +- tests/Model/SearchIndexInputTest.php | 7 +- tests/Operation/AggregateFunctionalTest.php | 3 +- tests/Operation/AggregateTest.php | 3 +- tests/Operation/BulkWriteFunctionalTest.php | 32 +++--- tests/Operation/BulkWriteTest.php | 84 +++++++-------- .../CountDocumentsFunctionalTest.php | 3 +- tests/Operation/CountDocumentsTest.php | 5 +- tests/Operation/CountFunctionalTest.php | 3 +- tests/Operation/CountTest.php | 5 +- tests/Operation/CreateCollectionTest.php | 3 +- ...reateEncryptedCollectionFunctionalTest.php | 9 +- .../CreateEncryptedCollectionTest.php | 3 +- .../Operation/CreateIndexesFunctionalTest.php | 3 +- tests/Operation/CreateIndexesTest.php | 11 +- tests/Operation/CreateSearchIndexesTest.php | 9 +- .../DatabaseCommandFunctionalTest.php | 3 +- tests/Operation/DatabaseCommandTest.php | 5 +- tests/Operation/DeleteFunctionalTest.php | 6 +- tests/Operation/DeleteTest.php | 9 +- tests/Operation/DistinctFunctionalTest.php | 5 +- tests/Operation/DistinctTest.php | 5 +- .../DropCollectionFunctionalTest.php | 3 +- tests/Operation/DropCollectionTest.php | 3 +- .../Operation/DropDatabaseFunctionalTest.php | 3 +- tests/Operation/DropDatabaseTest.php | 3 +- .../Operation/DropEncryptedCollectionTest.php | 3 +- tests/Operation/DropIndexesTest.php | 3 +- .../Operation/EstimatedDocumentCountTest.php | 3 +- tests/Operation/ExplainFunctionalTest.php | 31 +++--- tests/Operation/ExplainTest.php | 3 +- .../Operation/FindAndModifyFunctionalTest.php | 15 ++- tests/Operation/FindAndModifyTest.php | 3 +- tests/Operation/FindFunctionalTest.php | 13 ++- tests/Operation/FindOneAndDeleteTest.php | 5 +- tests/Operation/FindOneAndReplaceTest.php | 24 ++--- tests/Operation/FindOneAndUpdateTest.php | 15 ++- tests/Operation/FindOneFunctionalTest.php | 3 +- tests/Operation/FindTest.php | 7 +- tests/Operation/InsertManyFunctionalTest.php | 5 +- tests/Operation/InsertManyTest.php | 5 +- tests/Operation/InsertOneFunctionalTest.php | 16 +-- tests/Operation/InsertOneTest.php | 5 +- .../ListCollectionsFunctionalTest.php | 11 +- tests/Operation/ListIndexesTest.php | 3 +- tests/Operation/ListSearchIndexesTest.php | 3 +- tests/Operation/MapReduceFunctionalTest.php | 16 +-- tests/Operation/MapReduceTest.php | 7 +- .../ModifyCollectionFunctionalTest.php | 9 +- tests/Operation/ModifyCollectionTest.php | 3 +- tests/Operation/RenameCollectionTest.php | 3 +- tests/Operation/ReplaceOneTest.php | 22 ++-- tests/Operation/UpdateFunctionalTest.php | 22 ++-- tests/Operation/UpdateManyTest.php | 20 ++-- tests/Operation/UpdateOneTest.php | 20 ++-- tests/Operation/UpdateSearchIndexTest.php | 3 +- tests/Operation/UpdateTest.php | 13 ++- tests/Operation/WatchFunctionalTest.php | 29 +++-- tests/Operation/WatchTest.php | 3 +- tests/PedantryTest.php | 3 +- tests/PsrLogAdapterTest.php | 7 +- tests/SpecTests/AtlasDataLakeSpecTest.php | 3 +- ...rose21_AutomaticDataEncryptionKeysTest.php | 30 +++--- .../Prose22_RangeExplicitEncryptionTest.php | 54 ++++------ .../ClientSideEncryptionSpecTest.php | 39 +++---- tests/SpecTests/DocumentsMatchConstraint.php | 15 ++- .../DocumentsMatchConstraintTest.php | 5 +- .../Prose3_ReturnOriginalErrorTest.php | 3 +- tests/SpecTests/SearchIndexSpecTest.php | 3 +- tests/TestCase.php | 42 ++------ .../Constraint/IsBsonTypeTest.php | 5 +- tests/UnifiedSpecTests/Constraint/Matches.php | 13 +-- .../Constraint/MatchesTest.php | 5 +- tests/UnifiedSpecTests/UnifiedSpecTest.php | 100 +++++++----------- 110 files changed, 609 insertions(+), 627 deletions(-) diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index abf6aacb1..d5344791e 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -43,7 +43,7 @@ if [ "${IS_MATRIX_TESTING}" = "true" ]; then fi # Enable verbose output to see skipped and incomplete tests -PHPUNIT_OPTS="${PHPUNIT_OPTS} -v --configuration phpunit.evergreen.xml" +PHPUNIT_OPTS="${PHPUNIT_OPTS} --configuration phpunit.evergreen.xml" if [ "$SSL" = "yes" ]; then SSL_OPTS="ssl=true&sslallowinvalidcertificates=true" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 825c975b8..343a7f6d5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -75,7 +75,6 @@ jobs: php-ini-values: "zend.assertions=1" - name: "Run PHPUnit" - run: "vendor/bin/phpunit -v" + run: "vendor/bin/phpunit" env: - SYMFONY_DEPRECATIONS_HELPER: 999999 MONGODB_URI: ${{ steps.setup-mongodb.outputs.cluster-uri }} diff --git a/composer.json b/composer.json index e7d51e61e..73327dcbb 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ }, "require-dev": { "doctrine/coding-standard": "^12.0", - "phpunit/phpunit": "^9.6.11", - "rector/rector": "^1.1", + "phpunit/phpunit": "^10.5.35", + "rector/rector": "^1.2", "squizlabs/php_codesniffer": "^3.7", "vimeo/psalm": "^5.13" }, diff --git a/rector.php b/rector.php index 31f1f56f6..edfe66f14 100644 --- a/rector.php +++ b/rector.php @@ -3,8 +3,10 @@ use Rector\Config\RectorConfig; use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector; use Rector\Php70\Rector\StmtsAwareInterface\IfIssetToCoalescingRector; +use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector; use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector; +use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Set\ValueObject\LevelSetList; return static function (RectorConfig $rectorConfig): void { @@ -16,13 +18,17 @@ ]); // Modernize code - $rectorConfig->sets([LevelSetList::UP_TO_PHP_74]); + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_74, + PHPUnitSetList::PHPUNIT_100, + ]); $rectorConfig->rule(ChangeSwitchToMatchRector::class); $rectorConfig->rule(StaticDataProviderClassMethodRector::class); // phpcs:disable Squiz.Arrays.ArrayDeclaration.KeySpecified $rectorConfig->skip([ + RemoveExtraParametersRector::class, // Do not use ternaries extensively IfIssetToCoalescingRector::class, ChangeSwitchToMatchRector::class => [ diff --git a/tests/Builder/BuilderEncoderTest.php b/tests/Builder/BuilderEncoderTest.php index 9d3292bb2..4e9cd76f2 100644 --- a/tests/Builder/BuilderEncoderTest.php +++ b/tests/Builder/BuilderEncoderTest.php @@ -14,6 +14,7 @@ use MongoDB\Builder\Stage; use MongoDB\Builder\Type\Sort; use MongoDB\Builder\Variable; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function array_merge; @@ -153,9 +154,8 @@ public function testPerformCount(): void * * @param list $limit * @param array $expectedLimit - * - * @dataProvider provideExpressionFilterLimit */ + #[DataProvider('provideExpressionFilterLimit')] public function testExpressionFilter(array $limit, array $expectedLimit): void { $pipeline = new Pipeline( diff --git a/tests/Builder/FieldPathTest.php b/tests/Builder/FieldPathTest.php index f8bd3a309..afd1a15de 100644 --- a/tests/Builder/FieldPathTest.php +++ b/tests/Builder/FieldPathTest.php @@ -8,6 +8,7 @@ use MongoDB\Builder\Expression; use MongoDB\Builder\Type\FieldPathInterface; use MongoDB\Exception\InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function is_subclass_of; @@ -15,7 +16,7 @@ class FieldPathTest extends TestCase { - /** @dataProvider provideFieldPath */ + #[DataProvider('provideFieldPath')] public function testFieldPath(string $fieldPathClass, string $resolveClass): void { $fieldPath = Expression::{$fieldPathClass}('foo'); @@ -27,7 +28,7 @@ public function testFieldPath(string $fieldPathClass, string $resolveClass): voi $this->assertTrue(is_subclass_of(Expression\FieldPath::class, $resolveClass), sprintf('%s instanceof %s', Expression\FieldPath::class, $resolveClass)); } - /** @dataProvider provideFieldPath */ + #[DataProvider('provideFieldPath')] public function testRejectDollarPrefix(string $fieldPathClass): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Builder/Type/CombinedFieldQueryTest.php b/tests/Builder/Type/CombinedFieldQueryTest.php index ab326afd5..e37f61630 100644 --- a/tests/Builder/Type/CombinedFieldQueryTest.php +++ b/tests/Builder/Type/CombinedFieldQueryTest.php @@ -9,6 +9,7 @@ use MongoDB\Builder\Query\GtOperator; use MongoDB\Builder\Type\CombinedFieldQuery; use MongoDB\Exception\InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class CombinedFieldQueryTest extends TestCase @@ -47,7 +48,7 @@ public function testFlattenCombinedFieldQueries(): void $this->assertCount(3, $fieldQueries->fieldQueries); } - /** @dataProvider provideInvalidFieldQuery */ + #[DataProvider('provideInvalidFieldQuery')] public function testRejectInvalidFieldQueries(mixed $invalidQuery, string $message = '-'): void { $this->expectException(InvalidArgumentException::class); @@ -71,11 +72,8 @@ public static function provideInvalidFieldQuery(): Generator yield 'object key without $' => [(object) ['eq' => 1], 'Operator must contain exactly one key starting with $, "eq" given']; } - /** - * @param array $fieldQueries - * - * @dataProvider provideDuplicateOperator - */ + /** @param array $fieldQueries */ + #[DataProvider('provideDuplicateOperator')] public function testRejectDuplicateOperator(array $fieldQueries): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Builder/Type/OutputWindowTest.php b/tests/Builder/Type/OutputWindowTest.php index 1527a1826..0a60f3635 100644 --- a/tests/Builder/Type/OutputWindowTest.php +++ b/tests/Builder/Type/OutputWindowTest.php @@ -10,6 +10,7 @@ use MongoDB\Builder\Type\TimeUnit; use MongoDB\Builder\Type\WindowInterface; use MongoDB\Exception\InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class OutputWindowTest extends TestCase @@ -57,11 +58,8 @@ public function testWithUnit(): void $this->assertEquals((object) ['unit' => TimeUnit::Day], $outputWindow->window); } - /** - * @param array $documents - * - * @dataProvider provideInvalidDocuments - */ + /** @param array $documents */ + #[DataProvider('provideInvalidDocuments')] public function testRejectInvalidDocuments(array $documents): void { $this->expectException(InvalidArgumentException::class); @@ -82,11 +80,8 @@ public static function provideInvalidDocuments(): Generator yield 'not a list' => [['foo' => 1, 'bar' => 2]]; } - /** - * @param array $range - * - * @dataProvider provideInvalidRange - */ + /** @param array $range */ + #[DataProvider('provideInvalidRange')] public function testRejectInvalidRange(array $range): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Builder/Type/QueryObjectTest.php b/tests/Builder/Type/QueryObjectTest.php index cf5b67fde..819495805 100644 --- a/tests/Builder/Type/QueryObjectTest.php +++ b/tests/Builder/Type/QueryObjectTest.php @@ -13,6 +13,7 @@ use MongoDB\Builder\Type\CombinedFieldQuery; use MongoDB\Builder\Type\QueryInterface; use MongoDB\Builder\Type\QueryObject; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class QueryObjectTest extends TestCase @@ -32,11 +33,8 @@ public function testShortCutQueryObject(): void $this->assertSame($query, $queryObject); } - /** - * @param array $value - * - * @dataProvider provideQueryObjectValue - */ + /** @param array $value */ + #[DataProvider('provideQueryObjectValue')] public function testCreateQueryObject(array $value, int $expectedCount = 1): void { $queryObject = QueryObject::create($value); @@ -44,11 +42,8 @@ public function testCreateQueryObject(array $value, int $expectedCount = 1): voi $this->assertCount($expectedCount, $queryObject->queries); } - /** - * @param array $value - * - * @dataProvider provideQueryObjectValue - */ + /** @param array $value */ + #[DataProvider('provideQueryObjectValue')] public function testCreateQueryObjectFromArray(array $value, int $expectedCount = 1): void { // $value is wrapped in an array as if the user used an array instead of variadic arguments diff --git a/tests/Builder/VariableTest.php b/tests/Builder/VariableTest.php index dc30134a5..14137b3aa 100644 --- a/tests/Builder/VariableTest.php +++ b/tests/Builder/VariableTest.php @@ -8,6 +8,7 @@ use MongoDB\Builder\Expression; use MongoDB\Builder\Variable; use MongoDB\Exception\InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class VariableTest extends TestCase @@ -27,7 +28,7 @@ public function testVariableRejectDollarPrefix(): void new Expression\Variable('$$foo'); } - /** @dataProvider provideVariableBuilders */ + #[DataProvider('provideVariableBuilders')] public function testSystemVariables($factory): void { $variable = $factory(); diff --git a/tests/ClientTest.php b/tests/ClientTest.php index b830556d8..a2fc917ae 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -10,6 +10,8 @@ use MongoDB\Driver\ReadPreference; use MongoDB\Driver\WriteConcern; use MongoDB\Exception\InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; /** * Unit tests for the Client class. @@ -23,7 +25,7 @@ public function testConstructorDefaultUri(): void $this->assertEquals('mongodb://127.0.0.1/', (string) $client); } - /** @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testConstructorAutoEncryptionOpts(): void { $autoEncryptionOpts = [ @@ -35,7 +37,7 @@ public function testConstructorAutoEncryptionOpts(): void new Client(static::getUri(), [], ['autoEncryption' => $autoEncryptionOpts]); } - /** @dataProvider provideInvalidConstructorDriverOptions */ + #[DataProvider('provideInvalidConstructorDriverOptions')] public function testConstructorDriverOptionTypeChecks(array $driverOptions, string $exception = InvalidArgumentException::class): void { $this->expectException($exception); diff --git a/tests/Collection/CodecCollectionFunctionalTest.php b/tests/Collection/CodecCollectionFunctionalTest.php index d0d33522c..2447243d0 100644 --- a/tests/Collection/CodecCollectionFunctionalTest.php +++ b/tests/Collection/CodecCollectionFunctionalTest.php @@ -12,6 +12,7 @@ use MongoDB\Operation\FindOneAndReplace; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; use MongoDB\Tests\Fixtures\Document\TestObject; +use PHPUnit\Framework\Attributes\DataProvider; class CodecCollectionFunctionalTest extends FunctionalTestCase { @@ -54,7 +55,7 @@ public static function provideAggregateOptions(): Generator ]; } - /** @dataProvider provideAggregateOptions */ + #[DataProvider('provideAggregateOptions')] public function testAggregate($expected, $options): void { $this->createFixtures(3); @@ -114,7 +115,7 @@ public static function provideBulkWriteOptions(): Generator ]; } - /** @dataProvider provideBulkWriteOptions */ + #[DataProvider('provideBulkWriteOptions')] public function testBulkWrite($expected, $options): void { $this->createFixtures(3); @@ -169,7 +170,7 @@ public static function provideFindOneAndModifyOptions(): Generator ]; } - /** @dataProvider provideFindOneAndModifyOptions */ + #[DataProvider('provideFindOneAndModifyOptions')] public function testFindOneAndDelete($expected, $options): void { $this->createFixtures(1); @@ -190,7 +191,7 @@ public function testFindOneAndDeleteWithCodecAndTypemap(): void $this->collection->findOneAndDelete(['_id' => 1], $options); } - /** @dataProvider provideFindOneAndModifyOptions */ + #[DataProvider('provideFindOneAndModifyOptions')] public function testFindOneAndUpdate($expected, $options): void { $this->createFixtures(1); @@ -235,7 +236,7 @@ public static function provideFindOneAndReplaceOptions(): Generator ]; } - /** @dataProvider provideFindOneAndReplaceOptions */ + #[DataProvider('provideFindOneAndReplaceOptions')] public function testFindOneAndReplace($expected, $options): void { $this->createFixtures(1); @@ -293,7 +294,7 @@ public static function provideFindOptions(): Generator ]; } - /** @dataProvider provideFindOptions */ + #[DataProvider('provideFindOptions')] public function testFind($expected, $options): void { $this->createFixtures(3); @@ -332,7 +333,7 @@ public static function provideFindOneOptions(): Generator ]; } - /** @dataProvider provideFindOneOptions */ + #[DataProvider('provideFindOneOptions')] public function testFindOne($expected, $options): void { $this->createFixtures(1); @@ -383,7 +384,7 @@ public static function provideInsertManyOptions(): Generator ]; } - /** @dataProvider provideInsertManyOptions */ + #[DataProvider('provideInsertManyOptions')] public function testInsertMany($expected, $options): void { $documents = [ @@ -430,7 +431,7 @@ public static function provideInsertOneOptions(): Generator ]; } - /** @dataProvider provideInsertOneOptions */ + #[DataProvider('provideInsertOneOptions')] public function testInsertOne($expected, $options): void { $result = $this->collection->insertOne(TestObject::createForFixture(1), $options); @@ -475,7 +476,7 @@ public static function provideReplaceOneOptions(): Generator ]; } - /** @dataProvider provideReplaceOneOptions */ + #[DataProvider('provideReplaceOneOptions')] public function testReplaceOne($expected, $options): void { $this->createFixtures(1); diff --git a/tests/Collection/CollectionFunctionalTest.php b/tests/Collection/CollectionFunctionalTest.php index d63140ca4..a919e38d2 100644 --- a/tests/Collection/CollectionFunctionalTest.php +++ b/tests/Collection/CollectionFunctionalTest.php @@ -16,6 +16,8 @@ use MongoDB\MapReduceResult; use MongoDB\Operation\Count; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use TypeError; use function array_filter; @@ -33,7 +35,7 @@ */ class CollectionFunctionalTest extends FunctionalTestCase { - /** @dataProvider provideInvalidDatabaseAndCollectionNames */ + #[DataProvider('provideInvalidDatabaseAndCollectionNames')] public function testConstructorDatabaseNameArgument($databaseName, string $expectedExceptionClass): void { $this->expectException($expectedExceptionClass); @@ -41,7 +43,7 @@ public function testConstructorDatabaseNameArgument($databaseName, string $expec new Collection($this->manager, $databaseName, $this->getCollectionName()); } - /** @dataProvider provideInvalidDatabaseAndCollectionNames */ + #[DataProvider('provideInvalidDatabaseAndCollectionNames')] public function testConstructorCollectionNameArgument($collectionName, string $expectedExceptionClass): void { $this->expectException($expectedExceptionClass); @@ -57,7 +59,7 @@ public static function provideInvalidDatabaseAndCollectionNames() ]; } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); @@ -168,7 +170,7 @@ function (array $event): void { ); } - /** @dataProvider provideTypeMapOptionsAndExpectedDocuments */ + #[DataProvider('provideTypeMapOptionsAndExpectedDocuments')] public function testDistinctWithTypeMap(array $typeMap, array $expectedDocuments): void { $bulkWrite = new BulkWrite(['ordered' => true]); @@ -419,12 +421,10 @@ public function testWithOptionsPassesOptions(): void $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); } - /** - * @group matrix-testing-exclude-server-4.4-driver-4.0 - * @group matrix-testing-exclude-server-4.4-driver-4.2 - * @group matrix-testing-exclude-server-5.0-driver-4.0 - * @group matrix-testing-exclude-server-5.0-driver-4.2 - */ + #[Group('matrix-testing-exclude-server-4.4-driver-4.0')] + #[Group('matrix-testing-exclude-server-4.4-driver-4.2')] + #[Group('matrix-testing-exclude-server-5.0-driver-4.0')] + #[Group('matrix-testing-exclude-server-5.0-driver-4.2')] public function testMapReduce(): void { $this->createFixtures(3); @@ -734,7 +734,7 @@ public static function collectionWriteMethodClosures(): array ); } - /** @dataProvider collectionMethodClosures */ + #[DataProvider('collectionMethodClosures')] public function testMethodDoesNotInheritReadWriteConcernInTransaction(Closure $method): void { $this->skipIfTransactionsAreNotSupported(); @@ -760,7 +760,7 @@ function (array $event): void { ); } - /** @dataProvider collectionWriteMethodClosures */ + #[DataProvider('collectionWriteMethodClosures')] public function testMethodInTransactionWithWriteConcernOption($method): void { $this->skipIfTransactionsAreNotSupported(); @@ -780,7 +780,7 @@ public function testMethodInTransactionWithWriteConcernOption($method): void } } - /** @dataProvider collectionReadMethodClosures */ + #[DataProvider('collectionReadMethodClosures')] public function testMethodInTransactionWithReadConcernOption($method): void { $this->skipIfTransactionsAreNotSupported(); diff --git a/tests/Command/ListCollectionsTest.php b/tests/Command/ListCollectionsTest.php index b1d4b0535..54ab1bbe3 100644 --- a/tests/Command/ListCollectionsTest.php +++ b/tests/Command/ListCollectionsTest.php @@ -5,10 +5,11 @@ use MongoDB\Command\ListCollections; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Tests\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ListCollectionsTest extends TestCase { - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Command/ListDatabasesTest.php b/tests/Command/ListDatabasesTest.php index 4043826cb..f436bdb0d 100644 --- a/tests/Command/ListDatabasesTest.php +++ b/tests/Command/ListDatabasesTest.php @@ -5,10 +5,11 @@ use MongoDB\Command\ListDatabases; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Tests\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; class ListDatabasesTest extends TestCase { - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Comparator/Int64Comparator.php b/tests/Comparator/Int64Comparator.php index c786aa919..83cc6621e 100644 --- a/tests/Comparator/Int64Comparator.php +++ b/tests/Comparator/Int64Comparator.php @@ -5,13 +5,14 @@ use MongoDB\BSON\Int64; use SebastianBergmann\Comparator\Comparator; use SebastianBergmann\Comparator\ComparisonFailure; +use SebastianBergmann\Exporter\Exporter; use function is_numeric; use function sprintf; class Int64Comparator extends Comparator { - public function accepts($expected, $actual) + public function accepts($expected, $actual): bool { // Only compare if either value is an Int64 and the other value is numeric return ($expected instanceof Int64 && $this->isComparable($actual)) @@ -24,16 +25,17 @@ public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = f return; } + $exporter = new Exporter(); + throw new ComparisonFailure( $expected, $actual, '', '', - false, sprintf( 'Failed asserting that %s matches expected %s.', - $this->exporter->export($actual), - $this->exporter->export($expected), + $exporter->export($actual), + $exporter->export($expected), ), ); } diff --git a/tests/Comparator/Int64ComparatorTest.php b/tests/Comparator/Int64ComparatorTest.php index 9e85964c2..308b9cec7 100644 --- a/tests/Comparator/Int64ComparatorTest.php +++ b/tests/Comparator/Int64ComparatorTest.php @@ -4,12 +4,14 @@ use Generator; use MongoDB\BSON\Int64; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; use SebastianBergmann\Comparator\ComparisonFailure; class Int64ComparatorTest extends TestCase { - /** @dataProvider provideAcceptsValues */ + #[DataProvider('provideAcceptsValues')] public function testAccepts(bool $expectedResult, $expectedValue, $actualValue): void { $this->assertSame($expectedResult, (new Int64Comparator())->accepts($expectedValue, $actualValue)); @@ -96,10 +98,8 @@ public static function provideAcceptsValues(): Generator ]; } - /** - * @dataProvider provideMatchingAssertions - * @doesNotPerformAssertions - */ + #[DataProvider('provideMatchingAssertions')] + #[DoesNotPerformAssertions] public function testMatchingAssertions($expected, $actual): void { (new Int64Comparator())->assertEquals($expected, $actual); @@ -153,7 +153,7 @@ public static function provideMatchingAssertions(): Generator ]; } - /** @dataProvider provideFailingValues */ + #[DataProvider('provideFailingValues')] public function testFailingAssertions($expected, $actual): void { $this->expectException(ComparisonFailure::class); diff --git a/tests/Comparator/ServerComparator.php b/tests/Comparator/ServerComparator.php index 54b109795..28c958593 100644 --- a/tests/Comparator/ServerComparator.php +++ b/tests/Comparator/ServerComparator.php @@ -10,7 +10,7 @@ class ServerComparator extends Comparator { - public function accepts($expected, $actual) + public function accepts($expected, $actual): bool { return $expected instanceof Server && $actual instanceof Server; } @@ -26,7 +26,6 @@ public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = f $actual, '', '', - false, sprintf( 'Failed asserting that Server("%s:%d") matches expected Server("%s:%d").', $actual->getHost(), diff --git a/tests/Database/DatabaseFunctionalTest.php b/tests/Database/DatabaseFunctionalTest.php index 2647f9f8b..d6e3ff5b7 100644 --- a/tests/Database/DatabaseFunctionalTest.php +++ b/tests/Database/DatabaseFunctionalTest.php @@ -12,6 +12,8 @@ use MongoDB\Driver\WriteConcern; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\CreateIndexes; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use TypeError; use function array_key_exists; @@ -22,7 +24,7 @@ */ class DatabaseFunctionalTest extends FunctionalTestCase { - /** @dataProvider provideInvalidDatabaseNames */ + #[DataProvider('provideInvalidDatabaseNames')] public function testConstructorDatabaseNameArgument($databaseName, string $expectedExceptionClass): void { $this->expectException($expectedExceptionClass); @@ -38,7 +40,7 @@ public static function provideInvalidDatabaseNames() ]; } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); @@ -122,7 +124,7 @@ public function testCommandAppliesTypeMapToCursor(): void $this->assertSame(1, (int) $commandResult['ok']); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testCommandCommandArgumentTypeCheck($command): void { $this->expectException($command instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); @@ -170,11 +172,9 @@ public function testGetSelectsCollectionAndInheritsOptions(): void $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); } - /** - * @group matrix-testing-exclude-server-4.2-driver-4.0-topology-sharded_cluster - * @group matrix-testing-exclude-server-4.4-driver-4.0-topology-sharded_cluster - * @group matrix-testing-exclude-server-5.0-driver-4.0-topology-sharded_cluster - */ + #[Group('matrix-testing-exclude-server-4.2-driver-4.0-topology-sharded_cluster')] + #[Group('matrix-testing-exclude-server-4.4-driver-4.0-topology-sharded_cluster')] + #[Group('matrix-testing-exclude-server-5.0-driver-4.0-topology-sharded_cluster')] public function testModifyCollection(): void { $this->database->createCollection($this->getCollectionName()); diff --git a/tests/DocumentationExamplesTest.php b/tests/DocumentationExamplesTest.php index a8adedffe..c5876bebe 100644 --- a/tests/DocumentationExamplesTest.php +++ b/tests/DocumentationExamplesTest.php @@ -12,6 +12,8 @@ use MongoDB\Driver\Exception\Exception; use MongoDB\Driver\ReadPreference; use MongoDB\Tests\SpecTests\ClientSideEncryptionSpecTest; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; +use PHPUnit\Framework\Attributes\Group; use function base64_decode; use function in_array; @@ -1009,7 +1011,7 @@ public function testExample_55_58(): void $this->assertInventoryCount(0); } - /** @group matrix-testing-exclude-server-5.0-driver-4.0-topology-sharded_cluster */ + #[Group('matrix-testing-exclude-server-5.0-driver-4.0-topology-sharded_cluster')] public function testChangeStreamExample_1_4(): void { $this->skipIfChangeStreamIsNotSupported(); @@ -1715,7 +1717,7 @@ public function testSnapshotQueries(): void $this->assertSame(1, $totalDailySales); } - /** @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testVersionedApi(): void { $uriString = static::getUri(true); @@ -1800,7 +1802,7 @@ public function testVersionedApiMigration(): void // phpcs:enable } - /** @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testWithTransactionExample(): void { $this->skipIfTransactionsAreNotSupported(); diff --git a/tests/ExamplesTest.php b/tests/ExamplesTest.php index 7946622f4..6f26a5f46 100644 --- a/tests/ExamplesTest.php +++ b/tests/ExamplesTest.php @@ -3,6 +3,9 @@ namespace MongoDB\Tests; use Generator; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; use function bin2hex; use function getenv; @@ -10,7 +13,7 @@ use function random_bytes; use function sprintf; -/** @runTestsInSeparateProcesses */ +#[RunTestsInSeparateProcesses] final class ExamplesTest extends FunctionalTestCase { public function setUp(): void @@ -26,7 +29,7 @@ public function setUp(): void } } - /** @dataProvider provideExamples */ + #[DataProvider('provideExamples')] public function testExamples(string $file, string $expectedOutput): void { $this->assertExampleOutput($file, $expectedOutput); @@ -223,9 +226,8 @@ public static function provideExamples(): Generator /** * MongoDB Atlas Search example requires a MongoDB Atlas M10+ cluster with MongoDB 7.0+ * Tips for insiders: if using a cloud-dev server, append ".mongodb.net" to the MONGODB_URI. - * - * @group atlas */ + #[Group('atlas')] public function testAtlasSearch(): void { $uri = getenv('MONGODB_URI') ?? ''; diff --git a/tests/Exception/InvalidArgumentExceptionTest.php b/tests/Exception/InvalidArgumentExceptionTest.php index a7a13d40a..95ce89061 100644 --- a/tests/Exception/InvalidArgumentExceptionTest.php +++ b/tests/Exception/InvalidArgumentExceptionTest.php @@ -5,10 +5,11 @@ use AssertionError; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Tests\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; class InvalidArgumentExceptionTest extends TestCase { - /** @dataProvider provideExpectedTypes */ + #[DataProvider('provideExpectedTypes')] public function testExpectedTypeFormatting($expectedType, $typeString): void { $e = InvalidArgumentException::invalidType('$arg', null, $expectedType); diff --git a/tests/FunctionalTestCase.php b/tests/FunctionalTestCase.php index cdff7ca48..07c03e45e 100644 --- a/tests/FunctionalTestCase.php +++ b/tests/FunctionalTestCase.php @@ -17,6 +17,7 @@ use MongoDB\Operation\DatabaseCommand; use MongoDB\Operation\ListCollections; use stdClass; +use Throwable; use UnexpectedValueException; use function array_intersect_key; @@ -69,12 +70,15 @@ public function setUp(): void $this->configuredFailPoints = []; } - public function tearDown(): void + protected function onNotSuccessfulTest(Throwable $t): never { - if (! $this->hasFailed()) { - $this->cleanupCollections(); - } + $this->cleanupCollections(); + + throw $t; + } + public function tearDown(): void + { $this->disableFailPoints(); parent::tearDown(); diff --git a/tests/Functions/SelectServerFunctionalTest.php b/tests/Functions/SelectServerFunctionalTest.php index 0a3b82a6d..980541b35 100644 --- a/tests/Functions/SelectServerFunctionalTest.php +++ b/tests/Functions/SelectServerFunctionalTest.php @@ -5,12 +5,13 @@ use MongoDB\Driver\ReadPreference; use MongoDB\Driver\Server; use MongoDB\Tests\FunctionalTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function MongoDB\select_server; class SelectServerFunctionalTest extends FunctionalTestCase { - /** @dataProvider providePinnedOptions */ + #[DataProvider('providePinnedOptions')] public function testSelectServerPrefersPinnedServer(array $options): void { $this->skipIfTransactionsAreNotSupported(); diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index cab0b529a..999c33247 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -9,6 +9,7 @@ use MongoDB\Driver\WriteConcern; use MongoDB\Model\BSONArray; use MongoDB\Model\BSONDocument; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; use function MongoDB\apply_type_map_to_document; @@ -26,7 +27,7 @@ */ class FunctionsTest extends TestCase { - /** @dataProvider provideDocumentAndTypeMap */ + #[DataProvider('provideDocumentAndTypeMap')] public function testApplyTypeMapToDocument($document, array $typeMap, $expectedDocument): void { $this->assertEquals($expectedDocument, apply_type_map_to_document($document, $typeMap)); @@ -96,7 +97,7 @@ public static function provideDocumentAndTypeMap() ]; } - /** @dataProvider provideDocumentsAndExpectedArrays */ + #[DataProvider('provideDocumentsAndExpectedArrays')] public function testDocumentToArray($document, array $expectedArray): void { $this->assertSame($expectedArray, document_to_array($document)); @@ -115,7 +116,7 @@ public static function provideDocumentsAndExpectedArrays(): array ]; } - /** @dataProvider provideInvalidDocumentValuesForChecks */ + #[DataProvider('provideInvalidDocumentValuesForChecks')] public function testDocumentToArrayArgumentTypeCheck($document): void { $this->expectException(TypeError::class); @@ -142,7 +143,7 @@ public static function provideDocumentCasts(): array // phpcs:enable } - /** @dataProvider provideDocumentCasts */ + #[DataProvider('provideDocumentCasts')] public function testIsFirstKeyOperator(callable $cast): void { $this->assertFalse(is_first_key_operator($cast(['y' => 1]))); @@ -153,14 +154,14 @@ public function testIsFirstKeyOperator(callable $cast): void $this->assertFalse(is_first_key_operator($cast(['foo']))); } - /** @dataProvider provideInvalidDocumentValuesForChecks */ + #[DataProvider('provideInvalidDocumentValuesForChecks')] public function testIsFirstKeyOperatorArgumentTypeCheck($document): void { $this->expectException(TypeError::class); is_first_key_operator($document); } - /** @dataProvider provideDocumentCasts */ + #[DataProvider('provideDocumentCasts')] public function testIsMapReduceOutputInlineWithDocumentValues(callable $cast): void { $this->assertTrue(is_mapreduce_output_inline($cast(['inline' => 1]))); @@ -174,7 +175,7 @@ public function testIsMapReduceOutputInlineWithStringValue(): void $this->assertFalse(is_mapreduce_output_inline('collectionName')); } - /** @dataProvider provideTypeMapValues */ + #[DataProvider('provideTypeMapValues')] public function testCreateFieldPathTypeMap(array $expected, array $typeMap, $fieldPath = 'field'): void { $this->assertEquals($expected, create_field_path_type_map($typeMap, $fieldPath)); @@ -234,7 +235,7 @@ public static function provideTypeMapValues() ]; } - /** @dataProvider provideDocumentCasts */ + #[DataProvider('provideDocumentCasts')] public function testIsLastPipelineOperatorWrite(callable $cast): void { $match = ['$match' => ['x' => 1]]; @@ -250,7 +251,7 @@ public function testIsLastPipelineOperatorWrite(callable $cast): void $this->assertFalse(is_last_pipeline_operator_write([$cast($out), $cast($match)])); } - /** @dataProvider providePipelines */ + #[DataProvider('providePipelines')] public function testIsPipeline($expected, $pipeline, $allowEmpty = false): void { $this->assertSame($expected, is_pipeline($pipeline, $allowEmpty)); @@ -314,7 +315,7 @@ public static function providePipelines(): array ]; } - /** @dataProvider provideStagePipelines */ + #[DataProvider('provideStagePipelines')] public function testIsBuilderPipeline($expected, $pipeline): void { $this->assertSame($expected, is_builder_pipeline($pipeline)); @@ -329,7 +330,7 @@ public static function provideStagePipelines(): iterable yield 'stages and operators' => [true, [new MatchStage([]), ['$limit' => 1]]]; } - /** @dataProvider provideWriteConcerns */ + #[DataProvider('provideWriteConcerns')] public function testIsWriteConcernAcknowledged($expected, WriteConcern $writeConcern): void { $this->assertSame($expected, is_write_concern_acknowledged($writeConcern)); diff --git a/tests/GridFS/BucketFunctionalTest.php b/tests/GridFS/BucketFunctionalTest.php index 163c458c2..1c239873c 100644 --- a/tests/GridFS/BucketFunctionalTest.php +++ b/tests/GridFS/BucketFunctionalTest.php @@ -20,6 +20,8 @@ use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; use MongoDB\Tests\Fixtures\Codec\TestFileCodec; use MongoDB\Tests\Fixtures\Document\TestFile; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use ReflectionMethod; use stdClass; @@ -51,7 +53,7 @@ */ class BucketFunctionalTest extends FunctionalTestCase { - /** @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testValidConstructorOptions(): void { new Bucket($this->manager, $this->getDatabaseName(), [ @@ -64,7 +66,7 @@ public function testValidConstructorOptions(): void ]); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); @@ -103,7 +105,7 @@ public function testConstructorWithCodecAndTypeMapOptions(): void new Bucket($this->manager, $this->getDatabaseName(), $options); } - /** @dataProvider provideInputDataAndExpectedChunks */ + #[DataProvider('provideInputDataAndExpectedChunks')] public function testDelete($input, $expectedChunks): void { $id = $this->bucket->uploadFromStream('filename', self::createStream($input)); @@ -139,7 +141,7 @@ public function testDeleteShouldRequireFileToExist(): void $this->bucket->delete('nonexistent-id'); } - /** @dataProvider provideInputDataAndExpectedChunks */ + #[DataProvider('provideInputDataAndExpectedChunks')] public function testDeleteStillRemovesChunksIfFileDoesNotExist($input, $expectedChunks): void { $id = $this->bucket->uploadFromStream('filename', self::createStream($input)); @@ -197,7 +199,7 @@ public function testDownloadingFileWithUnexpectedChunkSize(): void stream_get_contents($this->bucket->openDownloadStream($id)); } - /** @dataProvider provideInputDataAndExpectedChunks */ + #[DataProvider('provideInputDataAndExpectedChunks')] public function testDownloadToStream($input): void { $id = $this->bucket->uploadFromStream('filename', self::createStream($input)); @@ -207,7 +209,7 @@ public function testDownloadToStream($input): void $this->assertStreamContents($input, $destination); } - /** @dataProvider provideInvalidStreamValues */ + #[DataProvider('provideInvalidStreamValues')] public function testDownloadToStreamShouldRequireDestinationStream($destination): void { $this->expectException(InvalidArgumentException::class); @@ -260,14 +262,14 @@ public function testDownloadToStreamByName(): void $this->assertStreamContents('baz', $destination); } - /** @dataProvider provideInvalidStreamValues */ + #[DataProvider('provideInvalidStreamValues')] public function testDownloadToStreamByNameShouldRequireDestinationStream($destination): void { $this->expectException(InvalidArgumentException::class); $this->bucket->downloadToStreamByName('filename', $destination); } - /** @dataProvider provideNonexistentFilenameAndRevision */ + #[DataProvider('provideNonexistentFilenameAndRevision')] public function testDownloadToStreamByNameShouldRequireFilenameAndRevisionToExist($filename, $revision): void { $this->bucket->uploadFromStream('filename', self::createStream('foo')); @@ -543,7 +545,7 @@ public function testGetFileDocumentForStreamWithWritableStream(): void $this->assertSameDocument($metadata, $fileDocument->metadata); } - /** @dataProvider provideInvalidGridFSStreamValues */ + #[DataProvider('provideInvalidGridFSStreamValues')] public function testGetFileDocumentForStreamShouldRequireGridFSStreamResource($stream): void { $this->expectException(InvalidArgumentException::class); @@ -580,7 +582,7 @@ public function testGetFileIdForStreamWithWritableStream(): void $this->assertEquals(1, $this->bucket->getFileIdForStream($stream)); } - /** @dataProvider provideInvalidGridFSStreamValues */ + #[DataProvider('provideInvalidGridFSStreamValues')] public function testGetFileIdForStreamShouldRequireGridFSStreamResource($stream): void { $this->expectException(InvalidArgumentException::class); @@ -595,7 +597,7 @@ public function testGetFilesCollection(): void $this->assertEquals('fs.files', $filesCollection->getCollectionName()); } - /** @dataProvider provideInputDataAndExpectedChunks */ + #[DataProvider('provideInputDataAndExpectedChunks')] public function testOpenDownloadStream($input): void { $id = $this->bucket->uploadFromStream('filename', self::createStream($input)); @@ -603,7 +605,7 @@ public function testOpenDownloadStream($input): void $this->assertStreamContents($input, $this->bucket->openDownloadStream($id)); } - /** @dataProvider provideInputDataAndExpectedChunks */ + #[DataProvider('provideInputDataAndExpectedChunks')] public function testOpenDownloadStreamAndMultipleReadOperations($input): void { $id = $this->bucket->uploadFromStream('filename', self::createStream($input)); @@ -649,7 +651,7 @@ public function testOpenDownloadStreamByName(): void $this->assertStreamContents('baz', $this->bucket->openDownloadStreamByName('filename', ['revision' => 2])); } - /** @dataProvider provideNonexistentFilenameAndRevision */ + #[DataProvider('provideNonexistentFilenameAndRevision')] public function testOpenDownloadStreamByNameShouldRequireFilenameAndRevisionToExist($filename, $revision): void { $this->bucket->uploadFromStream('filename', self::createStream('foo')); @@ -669,7 +671,7 @@ public function testOpenUploadStream(): void $this->assertStreamContents('foobar', $this->bucket->openDownloadStreamByName('filename')); } - /** @dataProvider provideInputDataAndExpectedChunks */ + #[DataProvider('provideInputDataAndExpectedChunks')] public function testOpenUploadStreamAndMultipleWriteOperations($input): void { $stream = $this->bucket->openUploadStream('filename'); @@ -740,7 +742,7 @@ public function testUploadFromStream(): void $this->assertSameDocument(['foo' => 'bar'], $fileDocument['metadata']); } - /** @dataProvider provideInvalidStreamValues */ + #[DataProvider('provideInvalidStreamValues')] public function testUploadFromStreamShouldRequireSourceStream($source): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/GridFS/FunctionalTestCase.php b/tests/GridFS/FunctionalTestCase.php index 785e1c909..ad2ca614a 100644 --- a/tests/GridFS/FunctionalTestCase.php +++ b/tests/GridFS/FunctionalTestCase.php @@ -6,6 +6,8 @@ use MongoDB\GridFS\Bucket; use MongoDB\Operation\DropCollection; use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase; +use PHPUnit\Framework\Attributes\AfterClass; +use PHPUnit\Framework\Attributes\BeforeClass; use function fopen; use function fwrite; @@ -46,10 +48,9 @@ public function tearDown(): void * The bucket's collections are created by the first test that runs and * kept for all subsequent tests. This is done to avoid creating the * collections and their indexes for each test, which would be slow. - * - * @beforeClass - * @afterClass */ + #[BeforeClass] + #[AfterClass] public static function dropCollectionsBeforeAfterClass(): void { $manager = static::createTestManager(); diff --git a/tests/GridFS/ReadableStreamFunctionalTest.php b/tests/GridFS/ReadableStreamFunctionalTest.php index 600181fbb..3a14af698 100644 --- a/tests/GridFS/ReadableStreamFunctionalTest.php +++ b/tests/GridFS/ReadableStreamFunctionalTest.php @@ -8,6 +8,7 @@ use MongoDB\GridFS\Exception\CorruptFileException; use MongoDB\GridFS\ReadableStream; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\DataProvider; use function array_filter; @@ -50,7 +51,7 @@ public function testGetFile(): void $this->assertSame($fileDocument, $stream->getFile()); } - /** @dataProvider provideInvalidConstructorFileDocuments */ + #[DataProvider('provideInvalidConstructorFileDocuments')] public function testConstructorFileDocumentChecks($file): void { $this->expectException(CorruptFileException::class); @@ -76,7 +77,7 @@ public static function provideInvalidConstructorFileDocuments() return $options; } - /** @dataProvider provideFileIdAndExpectedBytes */ + #[DataProvider('provideFileIdAndExpectedBytes')] public function testReadBytes($fileId, $length, $expectedBytes): void { $fileDocument = $this->collectionWrapper->findFileById($fileId); @@ -119,7 +120,7 @@ public static function provideFilteredFileIdAndExpectedBytes() ); } - /** @dataProvider provideFilteredFileIdAndExpectedBytes */ + #[DataProvider('provideFilteredFileIdAndExpectedBytes')] public function testReadBytesCalledMultipleTimes($fileId, $length, $expectedBytes): void { $fileDocument = $this->collectionWrapper->findFileById($fileId); @@ -197,7 +198,7 @@ public function testSeekOutOfRange(): void $stream->seek(11); } - /** @dataProvider providePreviousChunkSeekOffsetAndBytes */ + #[DataProvider('providePreviousChunkSeekOffsetAndBytes')] public function testSeekPreviousChunk($offset, $length, $expectedBytes): void { $fileDocument = $this->collectionWrapper->findFileById('length-10'); @@ -231,7 +232,7 @@ public static function providePreviousChunkSeekOffsetAndBytes() ]; } - /** @dataProvider provideSameChunkSeekOffsetAndBytes */ + #[DataProvider('provideSameChunkSeekOffsetAndBytes')] public function testSeekSameChunk($offset, $length, $expectedBytes): void { $fileDocument = $this->collectionWrapper->findFileById('length-10'); @@ -263,7 +264,7 @@ public static function provideSameChunkSeekOffsetAndBytes() ]; } - /** @dataProvider provideSubsequentChunkSeekOffsetAndBytes */ + #[DataProvider('provideSubsequentChunkSeekOffsetAndBytes')] public function testSeekSubsequentChunk($offset, $length, $expectedBytes): void { $fileDocument = $this->collectionWrapper->findFileById('length-10'); diff --git a/tests/GridFS/StreamWrapperFunctionalTest.php b/tests/GridFS/StreamWrapperFunctionalTest.php index fc8c45523..1960e5518 100644 --- a/tests/GridFS/StreamWrapperFunctionalTest.php +++ b/tests/GridFS/StreamWrapperFunctionalTest.php @@ -7,6 +7,7 @@ use MongoDB\GridFS\Exception\FileNotFoundException; use MongoDB\GridFS\Exception\LogicException; use MongoDB\GridFS\StreamWrapper; +use PHPUnit\Framework\Attributes\DataProvider; use function copy; use function fclose; @@ -232,7 +233,7 @@ public function testWritableStreamWrite(): void $this->assertSame(6, fwrite($stream, 'foobar')); } - /** @dataProvider provideUrl */ + #[DataProvider('provideUrl')] public function testStreamWithContextResolver(string $url, string $expectedFilename): void { $this->bucket->registerGlobalStreamWrapperAlias('bucket'); diff --git a/tests/GridFS/WritableStreamFunctionalTest.php b/tests/GridFS/WritableStreamFunctionalTest.php index a46741fae..98b654b8a 100644 --- a/tests/GridFS/WritableStreamFunctionalTest.php +++ b/tests/GridFS/WritableStreamFunctionalTest.php @@ -5,6 +5,8 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\GridFS\CollectionWrapper; use MongoDB\GridFS\WritableStream; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use function str_repeat; @@ -22,7 +24,7 @@ public function setUp(): void $this->collectionWrapper = new CollectionWrapper($this->manager, $this->getDatabaseName(), 'fs'); } - /** @doesNotPerformAssertions */ + #[DoesNotPerformAssertions] public function testValidConstructorOptions(): void { new WritableStream($this->collectionWrapper, 'filename', [ @@ -32,7 +34,7 @@ public function testValidConstructorOptions(): void ]); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); @@ -71,7 +73,7 @@ public function testWriteBytesAlwaysUpdatesFileSize(): void $this->assertSame(1536, $stream->getSize()); } - /** @dataProvider provideInputDataAndExpectedMD5 */ + #[DataProvider('provideInputDataAndExpectedMD5')] public function testWriteBytesCalculatesMD5($input, $expectedMD5): void { $stream = new WritableStream($this->collectionWrapper, 'filename'); diff --git a/tests/LogNonGenuineHostTest.php b/tests/LogNonGenuineHostTest.php index 4991b2339..2de5e2d95 100644 --- a/tests/LogNonGenuineHostTest.php +++ b/tests/LogNonGenuineHostTest.php @@ -4,6 +4,7 @@ use MongoDB\Client; use MongoDB\Driver\Exception\InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; use Psr\Log\AbstractLogger; use Psr\Log\LoggerInterface; @@ -28,7 +29,7 @@ public function tearDown(): void remove_logger($this->logger); } - /** @dataProvider provideCosmosUris */ + #[DataProvider('provideCosmosUris')] public function testCosmosUriLogsInfoMessage(string $uri): void { $this->createClientAndIgnoreSrvLookupError($uri); @@ -54,7 +55,7 @@ public static function provideCosmosUris(): array ]; } - /** @dataProvider provideDocumentDbUris */ + #[DataProvider('provideDocumentDbUris')] public function testDocumentDbUriLogsInfoMessage(string $uri): void { $this->createClientAndIgnoreSrvLookupError($uri); @@ -83,7 +84,7 @@ public static function provideDocumentDbUris(): array ]; } - /** @dataProvider provideGenuineUris */ + #[DataProvider('provideGenuineUris')] public function testGenuineUriDoesNotLog(string $uri): void { $this->createClientAndIgnoreSrvLookupError($uri); diff --git a/tests/Model/BSONIteratorTest.php b/tests/Model/BSONIteratorTest.php index 3ec945e39..749194c5d 100644 --- a/tests/Model/BSONIteratorTest.php +++ b/tests/Model/BSONIteratorTest.php @@ -7,6 +7,7 @@ use MongoDB\Exception\UnexpectedValueException; use MongoDB\Model\BSONIterator; use MongoDB\Tests\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function array_map; use function implode; @@ -15,7 +16,7 @@ class BSONIteratorTest extends TestCase { - /** @dataProvider provideTypeMapOptionsAndExpectedDocuments */ + #[DataProvider('provideTypeMapOptionsAndExpectedDocuments')] public function testValidValues(?array $typeMap, array $expectedDocuments): void { $binaryString = implode(array_map( diff --git a/tests/Model/CallbackIteratorTest.php b/tests/Model/CallbackIteratorTest.php index 9f71415f7..e38a26c4f 100644 --- a/tests/Model/CallbackIteratorTest.php +++ b/tests/Model/CallbackIteratorTest.php @@ -8,12 +8,13 @@ use IteratorAggregate; use MongoDB\Model\CallbackIterator; use MongoDB\Tests\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use function iterator_to_array; class CallbackIteratorTest extends TestCase { - /** @dataProvider provideTests */ + #[DataProvider('provideTests')] public function testIteration($expected, $source, $callback): void { $callbackIterator = new CallbackIterator($source, $callback); diff --git a/tests/Model/ChangeStreamIteratorTest.php b/tests/Model/ChangeStreamIteratorTest.php index caba4726c..84b4390fb 100644 --- a/tests/Model/ChangeStreamIteratorTest.php +++ b/tests/Model/ChangeStreamIteratorTest.php @@ -15,6 +15,7 @@ use MongoDB\Operation\Find; use MongoDB\Tests\CommandObserver; use MongoDB\Tests\FunctionalTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; use function sprintf; @@ -31,7 +32,7 @@ public function setUp(): void $this->collection = $this->createCollection($this->getDatabaseName(), $this->getCollectionName(), ['capped' => true, 'size' => 8192]); } - /** @dataProvider provideInvalidIntegerValues */ + #[DataProvider('provideInvalidIntegerValues')] public function testFirstBatchArgumentTypeCheck($firstBatchSize): void { $this->expectException(TypeError::class); @@ -50,14 +51,14 @@ public function testInitialResumeToken(): void $this->assertSameDocument((object) ['resumeToken' => 2], $iterator->getResumeToken()); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testInitialResumeTokenArgumentTypeCheck($initialResumeToken): void { $this->expectException($initialResumeToken instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new ChangeStreamIterator($this->collection->find(), 0, $initialResumeToken, null); } - /** @dataProvider provideInvalidObjectValues */ + #[DataProvider('provideInvalidObjectValues')] public function testPostBatchResumeTokenArgumentTypeCheck($postBatchResumeToken): void { $this->expectException(TypeError::class); diff --git a/tests/Model/CodecCursorFunctionalTest.php b/tests/Model/CodecCursorFunctionalTest.php index 432d71732..d2662a138 100644 --- a/tests/Model/CodecCursorFunctionalTest.php +++ b/tests/Model/CodecCursorFunctionalTest.php @@ -13,6 +13,7 @@ use const E_DEPRECATED; use const E_USER_DEPRECATED; +use const E_USER_WARNING; class CodecCursorFunctionalTest extends FunctionalTestCase { @@ -30,10 +31,7 @@ public function testSetTypeMap(): void $codecCursor = CodecCursor::fromCursor($cursor, $this->createMock(DocumentCodec::class)); - $this->expectWarning(); - $this->expectWarningMessage('Discarding type map for MongoDB\Model\CodecCursor::setTypeMap'); - - $codecCursor->setTypeMap(['root' => 'array']); + $this->assertError(E_USER_WARNING, fn () => $codecCursor->setTypeMap(['root' => 'array'])); } public function testGetIdReturnTypeWithoutArgument(): void diff --git a/tests/Model/IndexInfoFunctionalTest.php b/tests/Model/IndexInfoFunctionalTest.php index 65d22259a..33537382f 100644 --- a/tests/Model/IndexInfoFunctionalTest.php +++ b/tests/Model/IndexInfoFunctionalTest.php @@ -4,6 +4,7 @@ use MongoDB\Collection; use MongoDB\Tests\FunctionalTestCase; +use PHPUnit\Framework\Attributes\Group; class IndexInfoFunctionalTest extends FunctionalTestCase { @@ -32,11 +33,9 @@ public function testIs2dSphere(): void $this->assertEquals(3, $index['2dsphereIndexVersion']); } - /** - * @group matrix-testing-exclude-server-5.0-driver-4.0 - * @group matrix-testing-exclude-server-5.0-driver-4.2 - * @group matrix-testing-exclude-server-5.0-driver-4.4 - */ + #[Group('matrix-testing-exclude-server-5.0-driver-4.0')] + #[Group('matrix-testing-exclude-server-5.0-driver-4.2')] + #[Group('matrix-testing-exclude-server-5.0-driver-4.4')] public function testIsGeoHaystack(): void { $this->skipIfGeoHaystackIndexIsNotSupported(); diff --git a/tests/Model/IndexInputTest.php b/tests/Model/IndexInputTest.php index 6b4051e13..a0a44fa1a 100644 --- a/tests/Model/IndexInputTest.php +++ b/tests/Model/IndexInputTest.php @@ -8,6 +8,7 @@ use MongoDB\Model\BSONDocument; use MongoDB\Model\IndexInput; use MongoDB\Tests\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; class IndexInputTest extends TestCase @@ -19,7 +20,7 @@ public function testConstructorShouldRequireKey(): void new IndexInput([]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorShouldRequireKeyToBeArrayOrObject($key): void { $this->expectException(InvalidArgumentException::class); @@ -27,7 +28,7 @@ public function testConstructorShouldRequireKeyToBeArrayOrObject($key): void new IndexInput(['key' => $key]); } - /** @dataProvider provideInvalidFieldOrderValues */ + #[DataProvider('provideInvalidFieldOrderValues')] public function testConstructorShouldRequireKeyFieldOrderToBeNumericOrString($order): void { $this->expectException(InvalidArgumentException::class); @@ -40,7 +41,7 @@ public static function provideInvalidFieldOrderValues() return self::wrapValuesForDataProvider([true, [], new stdClass()]); } - /** @dataProvider provideInvalidStringValues */ + #[DataProvider('provideInvalidStringValues')] public function testConstructorShouldRequireNameToBeString($name): void { $this->expectException(InvalidArgumentException::class); @@ -48,7 +49,7 @@ public function testConstructorShouldRequireNameToBeString($name): void new IndexInput(['key' => ['x' => 1], 'name' => $name]); } - /** @dataProvider provideExpectedNameAndKey */ + #[DataProvider('provideExpectedNameAndKey')] public function testNameGeneration($expectedName, array|object $key): void { $this->assertSame($expectedName, (string) new IndexInput(['key' => $key])); diff --git a/tests/Model/SearchIndexInputTest.php b/tests/Model/SearchIndexInputTest.php index aef36c8c2..507ced5c9 100644 --- a/tests/Model/SearchIndexInputTest.php +++ b/tests/Model/SearchIndexInputTest.php @@ -6,6 +6,7 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Model\SearchIndexInput; use MongoDB\Tests\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; class SearchIndexInputTest extends TestCase { @@ -16,7 +17,7 @@ public function testConstructorIndexDefinitionMustBeDefined(): void new SearchIndexInput([]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorIndexDefinitionMustBeADocument($definition): void { $this->expectException(InvalidArgumentException::class); @@ -24,7 +25,7 @@ public function testConstructorIndexDefinitionMustBeADocument($definition): void new SearchIndexInput(['definition' => $definition]); } - /** @dataProvider provideInvalidStringValues */ + #[DataProvider('provideInvalidStringValues')] public function testConstructorShouldRequireNameToBeString($name): void { $this->expectException(InvalidArgumentException::class); @@ -32,7 +33,7 @@ public function testConstructorShouldRequireNameToBeString($name): void new SearchIndexInput(['definition' => ['mapping' => ['dynamic' => true]], 'name' => $name]); } - /** @dataProvider provideInvalidStringValues */ + #[DataProvider('provideInvalidStringValues')] public function testConstructorShouldRequireTypeToBeString($type): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/AggregateFunctionalTest.php b/tests/Operation/AggregateFunctionalTest.php index 290446f32..2d70ea299 100644 --- a/tests/Operation/AggregateFunctionalTest.php +++ b/tests/Operation/AggregateFunctionalTest.php @@ -11,6 +11,7 @@ use MongoDB\Tests\CommandObserver; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; use MongoDB\Tests\Fixtures\Document\TestObject; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use function array_key_exists; @@ -161,7 +162,7 @@ function (array $event): void { ); } - /** @dataProvider provideTypeMapOptionsAndExpectedDocuments */ + #[DataProvider('provideTypeMapOptionsAndExpectedDocuments')] public function testTypeMapOption(?array $typeMap, array $expectedDocuments): void { $this->createFixtures(3); diff --git a/tests/Operation/AggregateTest.php b/tests/Operation/AggregateTest.php index 237ddfc69..f9befaf36 100644 --- a/tests/Operation/AggregateTest.php +++ b/tests/Operation/AggregateTest.php @@ -7,6 +7,7 @@ use MongoDB\Driver\WriteConcern; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\Aggregate; +use PHPUnit\Framework\Attributes\DataProvider; class AggregateTest extends TestCase { @@ -17,7 +18,7 @@ public function testConstructorPipelineArgumentMustBeAList(): void new Aggregate($this->getDatabaseName(), $this->getCollectionName(), [1 => ['$match' => ['x' => 1]]]); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/BulkWriteFunctionalTest.php b/tests/Operation/BulkWriteFunctionalTest.php index 30213cca7..7a9cb5df9 100644 --- a/tests/Operation/BulkWriteFunctionalTest.php +++ b/tests/Operation/BulkWriteFunctionalTest.php @@ -14,6 +14,8 @@ use MongoDB\Tests\CommandObserver; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; use MongoDB\Tests\Fixtures\Document\TestObject; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; use stdClass; use function is_array; @@ -60,10 +62,8 @@ public function testInserts(): void $this->assertSameDocuments($expected, $this->collection->find()); } - /** - * @dataProvider provideDocumentsWithIds - * @dataProvider provideDocumentsWithoutIds - */ + #[DataProvider('provideDocumentsWithIds')] + #[DataProvider('provideDocumentsWithoutIds')] public function testInsertDocumentEncoding($document, stdClass $expectedDocument): void { (new CommandObserver())->observe( @@ -150,7 +150,7 @@ public function testUpdates(): void $this->assertSameDocuments($expected, $this->collection->find()); } - /** @dataProvider provideFilterDocuments */ + #[DataProvider('provideFilterDocuments')] public function testUpdateFilterDocuments($filter, stdClass $expectedFilter): void { (new CommandObserver())->observe( @@ -175,7 +175,7 @@ function (array $event) use ($expectedFilter): void { ); } - /** @dataProvider provideReplacementDocuments */ + #[DataProvider('provideReplacementDocuments')] public function testReplacementDocuments($replacement, stdClass $expectedReplacement): void { (new CommandObserver())->observe( @@ -194,10 +194,8 @@ function (array $event) use ($expectedReplacement): void { ); } - /** - * @dataProvider provideUpdateDocuments - * @dataProvider provideUpdatePipelines - */ + #[DataProvider('provideUpdateDocuments')] + #[DataProvider('provideUpdatePipelines')] public function testUpdateDocuments($update, $expectedUpdate): void { if (is_array($expectedUpdate)) { @@ -246,7 +244,7 @@ public function testDeletes(): void $this->assertSameDocuments($expected, $this->collection->find()); } - /** @dataProvider provideFilterDocuments */ + #[DataProvider('provideFilterDocuments')] public function testDeleteFilterDocuments($filter, stdClass $expectedQuery): void { (new CommandObserver())->observe( @@ -317,7 +315,7 @@ public function testUnacknowledgedWriteConcern() return $result; } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesDeletedCount(BulkWriteResult $result): void { $this->expectException(BadMethodCallException::class); @@ -325,7 +323,7 @@ public function testUnacknowledgedWriteConcernAccessesDeletedCount(BulkWriteResu $result->getDeletedCount(); } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesInsertCount(BulkWriteResult $result): void { $this->expectException(BadMethodCallException::class); @@ -333,7 +331,7 @@ public function testUnacknowledgedWriteConcernAccessesInsertCount(BulkWriteResul $result->getInsertedCount(); } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesMatchedCount(BulkWriteResult $result): void { $this->expectException(BadMethodCallException::class); @@ -341,7 +339,7 @@ public function testUnacknowledgedWriteConcernAccessesMatchedCount(BulkWriteResu $result->getMatchedCount(); } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesModifiedCount(BulkWriteResult $result): void { $this->expectException(BadMethodCallException::class); @@ -349,7 +347,7 @@ public function testUnacknowledgedWriteConcernAccessesModifiedCount(BulkWriteRes $result->getModifiedCount(); } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesUpsertedCount(BulkWriteResult $result): void { $this->expectException(BadMethodCallException::class); @@ -357,7 +355,7 @@ public function testUnacknowledgedWriteConcernAccessesUpsertedCount(BulkWriteRes $result->getUpsertedCount(); } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesUpsertedIds(BulkWriteResult $result): void { $this->expectException(BadMethodCallException::class); diff --git a/tests/Operation/BulkWriteTest.php b/tests/Operation/BulkWriteTest.php index 214305e57..d64fc351f 100644 --- a/tests/Operation/BulkWriteTest.php +++ b/tests/Operation/BulkWriteTest.php @@ -7,6 +7,8 @@ use MongoDB\Exception\UnsupportedValueException; use MongoDB\Operation\BulkWrite; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use TypeError; class BulkWriteTest extends TestCase @@ -57,7 +59,7 @@ public function testInsertOneDocumentArgumentMissing(): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testInsertOneDocumentArgumentTypeCheck($document): void { $this->expectException(InvalidArgumentException::class); @@ -88,7 +90,7 @@ public function testDeleteManyFilterArgumentMissing(): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testDeleteManyFilterArgumentTypeCheck($document): void { $this->expectException(InvalidArgumentException::class); @@ -98,7 +100,7 @@ public function testDeleteManyFilterArgumentTypeCheck($document): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testDeleteManyCollationOptionTypeCheck($collation): void { $this->expectException(InvalidArgumentException::class); @@ -117,7 +119,7 @@ public function testDeleteOneFilterArgumentMissing(): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testDeleteOneFilterArgumentTypeCheck($document): void { $this->expectException(InvalidArgumentException::class); @@ -127,7 +129,7 @@ public function testDeleteOneFilterArgumentTypeCheck($document): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testDeleteOneCollationOptionTypeCheck($collation): void { $this->expectException(InvalidArgumentException::class); @@ -146,7 +148,7 @@ public function testReplaceOneFilterArgumentMissing(): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testReplaceOneFilterArgumentTypeCheck($filter): void { $this->expectException(InvalidArgumentException::class); @@ -156,10 +158,8 @@ public function testReplaceOneFilterArgumentTypeCheck($filter): void ]); } - /** - * @dataProvider provideReplacementDocuments - * @doesNotPerformAssertions - */ + #[DataProvider('provideReplacementDocuments')] + #[DoesNotPerformAssertions] public function testReplaceOneReplacementArgument($replacement): void { new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [ @@ -176,7 +176,7 @@ public function testReplaceOneReplacementArgumentMissing(): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testReplaceOneReplacementArgumentTypeCheck($replacement): void { $this->expectException(InvalidArgumentException::class); @@ -186,7 +186,7 @@ public function testReplaceOneReplacementArgumentTypeCheck($replacement): void ]); } - /** @dataProvider provideUpdateDocuments */ + #[DataProvider('provideUpdateDocuments')] public function testReplaceOneReplacementArgumentProhibitsUpdateDocument($replacement): void { $this->expectException(InvalidArgumentException::class); @@ -196,10 +196,8 @@ public function testReplaceOneReplacementArgumentProhibitsUpdateDocument($replac ]); } - /** - * @dataProvider provideUpdatePipelines - * @dataProvider provideEmptyUpdatePipelinesExcludingArray - */ + #[DataProvider('provideUpdatePipelines')] + #[DataProvider('provideEmptyUpdatePipelinesExcludingArray')] public function testReplaceOneReplacementArgumentProhibitsUpdatePipeline($replacement): void { $this->expectException(InvalidArgumentException::class); @@ -209,7 +207,7 @@ public function testReplaceOneReplacementArgumentProhibitsUpdatePipeline($replac ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testReplaceOneCollationOptionTypeCheck($collation): void { $this->expectException(InvalidArgumentException::class); @@ -219,7 +217,7 @@ public function testReplaceOneCollationOptionTypeCheck($collation): void ]); } - /** @dataProvider provideInvalidBooleanValues */ + #[DataProvider('provideInvalidBooleanValues')] public function testReplaceOneUpsertOptionTypeCheck($upsert): void { $this->expectException(InvalidArgumentException::class); @@ -255,7 +253,7 @@ public function testUpdateManyFilterArgumentMissing(): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testUpdateManyFilterArgumentTypeCheck($filter): void { $this->expectException(InvalidArgumentException::class); @@ -265,11 +263,9 @@ public function testUpdateManyFilterArgumentTypeCheck($filter): void ]); } - /** - * @dataProvider provideUpdateDocuments - * @dataProvider provideUpdatePipelines - * @doesNotPerformAssertions - */ + #[DataProvider('provideUpdateDocuments')] + #[DataProvider('provideUpdatePipelines')] + #[DoesNotPerformAssertions] public function testUpdateManyUpdateArgument($update): void { new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [ @@ -286,7 +282,7 @@ public function testUpdateManyUpdateArgumentMissing(): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testUpdateManyUpdateArgumentTypeCheck($update): void { $this->expectException($update instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); @@ -295,10 +291,8 @@ public function testUpdateManyUpdateArgumentTypeCheck($update): void ]); } - /** - * @dataProvider provideReplacementDocuments - * @dataProvider provideEmptyUpdatePipelines - */ + #[DataProvider('provideReplacementDocuments')] + #[DataProvider('provideEmptyUpdatePipelines')] public function testUpdateManyUpdateArgumentProhibitsReplacementDocumentOrEmptyPipeline($update): void { $this->expectException(InvalidArgumentException::class); @@ -308,7 +302,7 @@ public function testUpdateManyUpdateArgumentProhibitsReplacementDocumentOrEmptyP ]); } - /** @dataProvider provideInvalidArrayValues */ + #[DataProvider('provideInvalidArrayValues')] public function testUpdateManyArrayFiltersOptionTypeCheck($arrayFilters): void { $this->expectException(InvalidArgumentException::class); @@ -318,7 +312,7 @@ public function testUpdateManyArrayFiltersOptionTypeCheck($arrayFilters): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testUpdateManyCollationOptionTypeCheck($collation): void { $this->expectException(InvalidArgumentException::class); @@ -328,7 +322,7 @@ public function testUpdateManyCollationOptionTypeCheck($collation): void ]); } - /** @dataProvider provideInvalidBooleanValues */ + #[DataProvider('provideInvalidBooleanValues')] public function testUpdateManyUpsertOptionTypeCheck($upsert): void { $this->expectException(InvalidArgumentException::class); @@ -338,11 +332,9 @@ public function testUpdateManyUpsertOptionTypeCheck($upsert): void ]); } - /** - * @dataProvider provideUpdateDocuments - * @dataProvider provideUpdatePipelines - * @doesNotPerformAssertions - */ + #[DataProvider('provideUpdateDocuments')] + #[DataProvider('provideUpdatePipelines')] + #[DoesNotPerformAssertions] public function testUpdateOneUpdateArgument($update): void { new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [ @@ -359,7 +351,7 @@ public function testUpdateOneFilterArgumentMissing(): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testUpdateOneFilterArgumentTypeCheck($filter): void { $this->expectException(InvalidArgumentException::class); @@ -378,7 +370,7 @@ public function testUpdateOneUpdateArgumentMissing(): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testUpdateOneUpdateArgumentTypeCheck($update): void { $this->expectException($update instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); @@ -387,10 +379,8 @@ public function testUpdateOneUpdateArgumentTypeCheck($update): void ]); } - /** - * @dataProvider provideReplacementDocuments - * @dataProvider provideEmptyUpdatePipelines - */ + #[DataProvider('provideReplacementDocuments')] + #[DataProvider('provideEmptyUpdatePipelines')] public function testUpdateOneUpdateArgumentProhibitsReplacementDocumentOrEmptyPipeline($update): void { $this->expectException(InvalidArgumentException::class); @@ -400,7 +390,7 @@ public function testUpdateOneUpdateArgumentProhibitsReplacementDocumentOrEmptyPi ]); } - /** @dataProvider provideInvalidArrayValues */ + #[DataProvider('provideInvalidArrayValues')] public function testUpdateOneArrayFiltersOptionTypeCheck($arrayFilters): void { $this->expectException(InvalidArgumentException::class); @@ -410,7 +400,7 @@ public function testUpdateOneArrayFiltersOptionTypeCheck($arrayFilters): void ]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testUpdateOneCollationOptionTypeCheck($collation): void { $this->expectException(InvalidArgumentException::class); @@ -420,7 +410,7 @@ public function testUpdateOneCollationOptionTypeCheck($collation): void ]); } - /** @dataProvider provideInvalidBooleanValues */ + #[DataProvider('provideInvalidBooleanValues')] public function testUpdateOneUpsertOptionTypeCheck($upsert): void { $this->expectException(InvalidArgumentException::class); @@ -430,7 +420,7 @@ public function testUpdateOneUpsertOptionTypeCheck($upsert): void ]); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/CountDocumentsFunctionalTest.php b/tests/Operation/CountDocumentsFunctionalTest.php index e3dc36a53..be6c64bbd 100644 --- a/tests/Operation/CountDocumentsFunctionalTest.php +++ b/tests/Operation/CountDocumentsFunctionalTest.php @@ -5,11 +5,12 @@ use MongoDB\Operation\CountDocuments; use MongoDB\Operation\InsertMany; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; class CountDocumentsFunctionalTest extends FunctionalTestCase { - /** @dataProvider provideFilterDocuments */ + #[DataProvider('provideFilterDocuments')] public function testFilterDocuments($filter, stdClass $expectedMatchStage): void { (new CommandObserver())->observe( diff --git a/tests/Operation/CountDocumentsTest.php b/tests/Operation/CountDocumentsTest.php index 65e002a46..44ee49825 100644 --- a/tests/Operation/CountDocumentsTest.php +++ b/tests/Operation/CountDocumentsTest.php @@ -5,18 +5,19 @@ use MongoDB\BSON\PackedArray; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\CountDocuments; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; class CountDocumentsTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorFilterArgumentTypeCheck($filter): void { $this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new CountDocuments($this->getDatabaseName(), $this->getCollectionName(), $filter); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/CountFunctionalTest.php b/tests/Operation/CountFunctionalTest.php index 55435ab98..58326a01a 100644 --- a/tests/Operation/CountFunctionalTest.php +++ b/tests/Operation/CountFunctionalTest.php @@ -6,11 +6,12 @@ use MongoDB\Operation\CreateIndexes; use MongoDB\Operation\InsertMany; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; class CountFunctionalTest extends FunctionalTestCase { - /** @dataProvider provideFilterDocuments */ + #[DataProvider('provideFilterDocuments')] public function testFilterDocuments($filter, stdClass $expectedQuery): void { (new CommandObserver())->observe( diff --git a/tests/Operation/CountTest.php b/tests/Operation/CountTest.php index 8d109ae81..b8a5d357e 100644 --- a/tests/Operation/CountTest.php +++ b/tests/Operation/CountTest.php @@ -6,18 +6,19 @@ use MongoDB\Driver\ReadConcern; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\Count; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; class CountTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorFilterArgumentTypeCheck($filter): void { $this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new Count($this->getDatabaseName(), $this->getCollectionName(), $filter); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/CreateCollectionTest.php b/tests/Operation/CreateCollectionTest.php index 530299ba4..21a280032 100644 --- a/tests/Operation/CreateCollectionTest.php +++ b/tests/Operation/CreateCollectionTest.php @@ -4,6 +4,7 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\CreateCollection; +use PHPUnit\Framework\Attributes\DataProvider; class CreateCollectionTest extends TestCase { @@ -14,7 +15,7 @@ public function testConstructorPipelineOptionMustBeAList(): void new CreateCollection($this->getDatabaseName(), $this->getCollectionName(), ['pipeline' => [1 => ['$match' => ['x' => 1]]]]); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/CreateEncryptedCollectionFunctionalTest.php b/tests/Operation/CreateEncryptedCollectionFunctionalTest.php index 4c851edff..8d4978639 100644 --- a/tests/Operation/CreateEncryptedCollectionFunctionalTest.php +++ b/tests/Operation/CreateEncryptedCollectionFunctionalTest.php @@ -10,6 +10,7 @@ use MongoDB\Model\BSONArray; use MongoDB\Model\BSONDocument; use MongoDB\Operation\CreateEncryptedCollection; +use PHPUnit\Framework\Attributes\DataProvider; use function base64_decode; use function getenv; @@ -54,7 +55,7 @@ public function setUp(): void ]); } - /** @dataProvider provideEncryptedFieldsAndFieldsIsMissing */ + #[DataProvider('provideEncryptedFieldsAndFieldsIsMissing')] public function testCreateDataKeysNopIfFieldsIsMissing($input, array $expectedOutput): void { $operation = new CreateEncryptedCollection( @@ -85,7 +86,7 @@ public static function provideEncryptedFieldsAndFieldsIsMissing(): array ]; } - /** @dataProvider provideEncryptedFieldsAndFieldsHasInvalidType */ + #[DataProvider('provideEncryptedFieldsAndFieldsHasInvalidType')] public function testCreateDataKeysNopIfFieldsHasInvalidType($input, array $expectedOutput): void { $operation = new CreateEncryptedCollection( @@ -116,7 +117,7 @@ public static function provideEncryptedFieldsAndFieldsHasInvalidType(): array ]; } - /** @dataProvider provideEncryptedFieldsElementHasInvalidType */ + #[DataProvider('provideEncryptedFieldsElementHasInvalidType')] public function testCreateDataKeysSkipsNonDocumentFields($input, array $expectedOutput): void { $operation = new CreateEncryptedCollection( @@ -171,7 +172,7 @@ public function testCreateDataKeysDoesNotModifyOriginalEncryptedFieldsOption(): $this->assertInstanceOf(Binary::class, $modifiedEncryptedFields['fields'][0]['keyId'] ?? null); } - /** @dataProvider provideEncryptedFields */ + #[DataProvider('provideEncryptedFields')] public function testEncryptedFieldsDocuments($input): void { $operation = new CreateEncryptedCollection( diff --git a/tests/Operation/CreateEncryptedCollectionTest.php b/tests/Operation/CreateEncryptedCollectionTest.php index fc38bc830..b5c8bf4ea 100644 --- a/tests/Operation/CreateEncryptedCollectionTest.php +++ b/tests/Operation/CreateEncryptedCollectionTest.php @@ -5,10 +5,11 @@ use Generator; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\CreateEncryptedCollection; +use PHPUnit\Framework\Attributes\DataProvider; class CreateEncryptedCollectionTest extends TestCase { - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/CreateIndexesFunctionalTest.php b/tests/Operation/CreateIndexesFunctionalTest.php index ba79971ac..a90eaec75 100644 --- a/tests/Operation/CreateIndexesFunctionalTest.php +++ b/tests/Operation/CreateIndexesFunctionalTest.php @@ -12,6 +12,7 @@ use MongoDB\Operation\CreateIndexes; use MongoDB\Operation\ListIndexes; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\DataProvider; use function call_user_func; use function is_callable; @@ -79,7 +80,7 @@ public function testCreateTTLIndex(): void }); } - /** @dataProvider provideKeyCasts */ + #[DataProvider('provideKeyCasts')] public function testCreateIndexes(callable $cast): void { $expectedNames = ['x_1', 'y_-1_z_1', 'g_2dsphere_z_1', 'my_ttl']; diff --git a/tests/Operation/CreateIndexesTest.php b/tests/Operation/CreateIndexesTest.php index 2647bcc46..5db02f67f 100644 --- a/tests/Operation/CreateIndexesTest.php +++ b/tests/Operation/CreateIndexesTest.php @@ -7,6 +7,7 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Model\BSONDocument; use MongoDB\Operation\CreateIndexes; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; class CreateIndexesTest extends TestCase @@ -18,7 +19,7 @@ public function testConstructorIndexesArgumentMustBeAList(): void new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), [1 => ['key' => ['x' => 1]]]); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); @@ -43,7 +44,7 @@ public function testConstructorRequiresAtLeastOneIndex(): void new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), []); } - /** @dataProvider provideInvalidIndexSpecificationTypes */ + #[DataProvider('provideInvalidIndexSpecificationTypes')] public function testConstructorRequiresIndexSpecificationsToBeAnArray($index): void { $this->expectException(InvalidArgumentException::class); @@ -63,7 +64,7 @@ public function testConstructorRequiresIndexSpecificationKey(): void new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), [[]]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorRequiresIndexSpecificationKeyToBeADocument($key): void { $this->expectException(InvalidArgumentException::class); @@ -71,7 +72,7 @@ public function testConstructorRequiresIndexSpecificationKeyToBeADocument($key): new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), [['key' => $key]]); } - /** @dataProvider provideKeyDocumentsWithInvalidOrder */ + #[DataProvider('provideKeyDocumentsWithInvalidOrder')] public function testConstructorValidatesIndexSpecificationKeyOrder($key): void { $this->expectException(InvalidArgumentException::class); @@ -91,7 +92,7 @@ public static function provideKeyDocumentsWithInvalidOrder(): Generator } } - /** @dataProvider provideInvalidStringValues */ + #[DataProvider('provideInvalidStringValues')] public function testConstructorRequiresIndexSpecificationNameToBeString($name): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/CreateSearchIndexesTest.php b/tests/Operation/CreateSearchIndexesTest.php index 27246873b..d55915048 100644 --- a/tests/Operation/CreateSearchIndexesTest.php +++ b/tests/Operation/CreateSearchIndexesTest.php @@ -4,6 +4,7 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\CreateSearchIndexes; +use PHPUnit\Framework\Attributes\DataProvider; class CreateSearchIndexesTest extends TestCase { @@ -14,7 +15,7 @@ public function testConstructorIndexesArgumentMustBeAList(): void new CreateSearchIndexes($this->getDatabaseName(), $this->getCollectionName(), [1 => ['name' => 'index name', 'definition' => ['mappings' => ['dynamic' => true]]]], []); } - /** @dataProvider provideInvalidArrayValues */ + #[DataProvider('provideInvalidArrayValues')] public function testConstructorIndexDefinitionMustBeADocument($index): void { $this->expectException(InvalidArgumentException::class); @@ -22,7 +23,7 @@ public function testConstructorIndexDefinitionMustBeADocument($index): void new CreateSearchIndexes($this->getDatabaseName(), $this->getCollectionName(), [$index], []); } - /** @dataProvider provideInvalidStringValues */ + #[DataProvider('provideInvalidStringValues')] public function testConstructorIndexNameMustBeAString($name): void { $this->expectException(InvalidArgumentException::class); @@ -30,7 +31,7 @@ public function testConstructorIndexNameMustBeAString($name): void new CreateSearchIndexes($this->getDatabaseName(), $this->getCollectionName(), [['name' => $name, 'definition' => ['mappings' => ['dynamic' => true]]]], []); } - /** @dataProvider provideInvalidStringValues */ + #[DataProvider('provideInvalidStringValues')] public function testConstructorIndexTypeMustBeAString($type): void { $this->expectException(InvalidArgumentException::class); @@ -45,7 +46,7 @@ public function testConstructorIndexDefinitionMustBeDefined(): void new CreateSearchIndexes($this->getDatabaseName(), $this->getCollectionName(), [['name' => 'index name']], []); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorIndexDefinitionMustBeAnArray($definition): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/DatabaseCommandFunctionalTest.php b/tests/Operation/DatabaseCommandFunctionalTest.php index 861302595..abed3b2c1 100644 --- a/tests/Operation/DatabaseCommandFunctionalTest.php +++ b/tests/Operation/DatabaseCommandFunctionalTest.php @@ -7,10 +7,11 @@ use MongoDB\Model\BSONDocument; use MongoDB\Operation\DatabaseCommand; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\DataProvider; class DatabaseCommandFunctionalTest extends FunctionalTestCase { - /** @dataProvider provideCommandDocuments */ + #[DataProvider('provideCommandDocuments')] public function testCommandDocuments($command): void { (new CommandObserver())->observe( diff --git a/tests/Operation/DatabaseCommandTest.php b/tests/Operation/DatabaseCommandTest.php index 869f0c7c3..c579ea5b2 100644 --- a/tests/Operation/DatabaseCommandTest.php +++ b/tests/Operation/DatabaseCommandTest.php @@ -5,18 +5,19 @@ use MongoDB\BSON\PackedArray; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\DatabaseCommand; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; class DatabaseCommandTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorCommandArgumentTypeCheck($command): void { $this->expectException($command instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new DatabaseCommand($this->getDatabaseName(), $command); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/DeleteFunctionalTest.php b/tests/Operation/DeleteFunctionalTest.php index 7ff002f97..b501aa21b 100644 --- a/tests/Operation/DeleteFunctionalTest.php +++ b/tests/Operation/DeleteFunctionalTest.php @@ -10,6 +10,8 @@ use MongoDB\Exception\UnsupportedException; use MongoDB\Operation\Delete; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; use stdClass; class DeleteFunctionalTest extends FunctionalTestCase @@ -23,7 +25,7 @@ public function setUp(): void $this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName()); } - /** @dataProvider provideFilterDocuments */ + #[DataProvider('provideFilterDocuments')] public function testFilterDocuments($filter, stdClass $expectedQuery): void { (new CommandObserver())->observe( @@ -133,7 +135,7 @@ public function testUnacknowledgedWriteConcern() return $result; } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesDeletedCount(DeleteResult $result): void { $this->expectException(BadMethodCallException::class); diff --git a/tests/Operation/DeleteTest.php b/tests/Operation/DeleteTest.php index 818689610..e1cd5bd74 100644 --- a/tests/Operation/DeleteTest.php +++ b/tests/Operation/DeleteTest.php @@ -11,25 +11,26 @@ use MongoDB\Driver\WriteConcern; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\Delete; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; class DeleteTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorFilterArgumentTypeCheck($filter): void { $this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new Delete($this->getDatabaseName(), $this->getCollectionName(), $filter, 0); } - /** @dataProvider provideInvalidIntegerValues */ + #[DataProvider('provideInvalidIntegerValues')] public function testConstructorLimitArgumentMustBeInt($limit): void { $this->expectException(TypeError::class); new Delete($this->getDatabaseName(), $this->getCollectionName(), [], $limit); } - /** @dataProvider provideInvalidLimitValues */ + #[DataProvider('provideInvalidLimitValues')] public function testConstructorLimitArgumentMustBeOneOrZero($limit): void { $this->expectException(InvalidArgumentException::class); @@ -42,7 +43,7 @@ public static function provideInvalidLimitValues() return self::wrapValuesForDataProvider([-1, 2]); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/DistinctFunctionalTest.php b/tests/Operation/DistinctFunctionalTest.php index d9a18307a..0a1d61a01 100644 --- a/tests/Operation/DistinctFunctionalTest.php +++ b/tests/Operation/DistinctFunctionalTest.php @@ -5,6 +5,7 @@ use MongoDB\Driver\BulkWrite; use MongoDB\Operation\Distinct; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use function is_scalar; @@ -15,7 +16,7 @@ class DistinctFunctionalTest extends FunctionalTestCase { - /** @dataProvider provideFilterDocuments */ + #[DataProvider('provideFilterDocuments')] public function testFilterDocuments($filter, stdClass $expectedQuery): void { (new CommandObserver())->observe( @@ -75,7 +76,7 @@ function (array $event): void { ); } - /** @dataProvider provideTypeMapOptionsAndExpectedDocuments */ + #[DataProvider('provideTypeMapOptionsAndExpectedDocuments')] public function testTypeMapOption(array $typeMap, array $expectedDocuments): void { $bulkWrite = new BulkWrite(['ordered' => true]); diff --git a/tests/Operation/DistinctTest.php b/tests/Operation/DistinctTest.php index e181abb0a..ad5012068 100644 --- a/tests/Operation/DistinctTest.php +++ b/tests/Operation/DistinctTest.php @@ -7,18 +7,19 @@ use MongoDB\Driver\ReadPreference; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\Distinct; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; class DistinctTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorFilterArgumentTypeCheck($filter): void { $this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new Distinct($this->getDatabaseName(), $this->getCollectionName(), 'x', $filter); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/DropCollectionFunctionalTest.php b/tests/Operation/DropCollectionFunctionalTest.php index 602982f5c..a7d317e67 100644 --- a/tests/Operation/DropCollectionFunctionalTest.php +++ b/tests/Operation/DropCollectionFunctionalTest.php @@ -5,6 +5,7 @@ use MongoDB\Operation\DropCollection; use MongoDB\Operation\InsertOne; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\Depends; class DropCollectionFunctionalTest extends FunctionalTestCase { @@ -41,7 +42,7 @@ public function testDropExistingCollection(): void $this->assertCollectionDoesNotExist($this->getCollectionName()); } - /** @depends testDropExistingCollection */ + #[Depends('testDropExistingCollection')] public function testDropNonexistentCollection(): void { $this->assertCollectionDoesNotExist($this->getCollectionName()); diff --git a/tests/Operation/DropCollectionTest.php b/tests/Operation/DropCollectionTest.php index dda688686..19dc28bd4 100644 --- a/tests/Operation/DropCollectionTest.php +++ b/tests/Operation/DropCollectionTest.php @@ -4,10 +4,11 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\DropCollection; +use PHPUnit\Framework\Attributes\DataProvider; class DropCollectionTest extends TestCase { - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/DropDatabaseFunctionalTest.php b/tests/Operation/DropDatabaseFunctionalTest.php index 628c3b0f3..0ef812a10 100644 --- a/tests/Operation/DropDatabaseFunctionalTest.php +++ b/tests/Operation/DropDatabaseFunctionalTest.php @@ -7,6 +7,7 @@ use MongoDB\Operation\InsertOne; use MongoDB\Operation\ListDatabases; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\Depends; use function sprintf; @@ -43,7 +44,7 @@ public function testDropExistingDatabase(): void $this->assertDatabaseDoesNotExist($server, $this->getDatabaseName()); } - /** @depends testDropExistingDatabase */ + #[Depends('testDropExistingDatabase')] public function testDropNonexistentDatabase(): void { $server = $this->getPrimaryServer(); diff --git a/tests/Operation/DropDatabaseTest.php b/tests/Operation/DropDatabaseTest.php index 4bdc69192..cd58e6356 100644 --- a/tests/Operation/DropDatabaseTest.php +++ b/tests/Operation/DropDatabaseTest.php @@ -4,10 +4,11 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\DropDatabase; +use PHPUnit\Framework\Attributes\DataProvider; class DropDatabaseTest extends TestCase { - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/DropEncryptedCollectionTest.php b/tests/Operation/DropEncryptedCollectionTest.php index 669cc8590..a0055104c 100644 --- a/tests/Operation/DropEncryptedCollectionTest.php +++ b/tests/Operation/DropEncryptedCollectionTest.php @@ -5,10 +5,11 @@ use Generator; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\DropEncryptedCollection; +use PHPUnit\Framework\Attributes\DataProvider; class DropEncryptedCollectionTest extends TestCase { - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/DropIndexesTest.php b/tests/Operation/DropIndexesTest.php index c90ca1376..cc2aff405 100644 --- a/tests/Operation/DropIndexesTest.php +++ b/tests/Operation/DropIndexesTest.php @@ -4,6 +4,7 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\DropIndexes; +use PHPUnit\Framework\Attributes\DataProvider; class DropIndexesTest extends TestCase { @@ -13,7 +14,7 @@ public function testDropIndexShouldNotAllowEmptyIndexName(): void new DropIndexes($this->getDatabaseName(), $this->getCollectionName(), ''); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/EstimatedDocumentCountTest.php b/tests/Operation/EstimatedDocumentCountTest.php index f1b4c9211..c530d0e2d 100644 --- a/tests/Operation/EstimatedDocumentCountTest.php +++ b/tests/Operation/EstimatedDocumentCountTest.php @@ -4,10 +4,11 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\EstimatedDocumentCount; +use PHPUnit\Framework\Attributes\DataProvider; class EstimatedDocumentCountTest extends TestCase { - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/ExplainFunctionalTest.php b/tests/Operation/ExplainFunctionalTest.php index 486ee4095..e40024bff 100644 --- a/tests/Operation/ExplainFunctionalTest.php +++ b/tests/Operation/ExplainFunctionalTest.php @@ -20,13 +20,14 @@ use MongoDB\Operation\UpdateMany; use MongoDB\Operation\UpdateOne; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\DataProvider; use function array_key_exists; use function array_key_first; class ExplainFunctionalTest extends FunctionalTestCase { - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testCount($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $this->createFixtures(3); @@ -39,7 +40,7 @@ public function testCount($verbosity, $executionStatsExpected, $allPlansExecutio $this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testDelete($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $this->createFixtures(3); @@ -54,7 +55,7 @@ public function testDelete($verbosity, $executionStatsExpected, $allPlansExecuti $this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testDeleteMany($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $this->createFixtures(3); @@ -69,7 +70,7 @@ public function testDeleteMany($verbosity, $executionStatsExpected, $allPlansExe $this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testDeleteOne($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $this->createFixtures(3); @@ -84,7 +85,7 @@ public function testDeleteOne($verbosity, $executionStatsExpected, $allPlansExec $this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testDistinct($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $operation = new Distinct($this->getDatabaseName(), $this->getCollectionName(), 'x', []); @@ -95,7 +96,7 @@ public function testDistinct($verbosity, $executionStatsExpected, $allPlansExecu $this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testFindAndModify($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $operation = new FindAndModify($this->getDatabaseName(), $this->getCollectionName(), ['remove' => true]); @@ -106,7 +107,7 @@ public function testFindAndModify($verbosity, $executionStatsExpected, $allPlans $this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testFind($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $this->createFixtures(3); @@ -181,7 +182,7 @@ function (array $event): void { ); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testFindOne($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $this->createFixtures(1); @@ -194,7 +195,7 @@ public function testFindOne($verbosity, $executionStatsExpected, $allPlansExecut $this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testFindOneAndDelete($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $operation = new FindOneAndDelete($this->getDatabaseName(), $this->getCollectionName(), []); @@ -205,7 +206,7 @@ public function testFindOneAndDelete($verbosity, $executionStatsExpected, $allPl $this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testFindOneAndReplace($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $operation = new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1.1], ['x' => 5]); @@ -216,7 +217,7 @@ public function testFindOneAndReplace($verbosity, $executionStatsExpected, $allP $this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testFindOneAndUpdate($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $operation = new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), [], ['$rename' => ['x' => 'y']]); @@ -227,7 +228,7 @@ public function testFindOneAndUpdate($verbosity, $executionStatsExpected, $allPl $this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testUpdate($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $this->createFixtures(3); @@ -296,7 +297,7 @@ function (array $event): void { ); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testUpdateMany($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $this->createFixtures(3); @@ -312,7 +313,7 @@ public function testUpdateMany($verbosity, $executionStatsExpected, $allPlansExe $this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testUpdateOne($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $this->createFixtures(3); @@ -344,7 +345,7 @@ public function testAggregate(): void $this->assertExplainResult($result, false, false); } - /** @dataProvider provideVerbosityInformation */ + #[DataProvider('provideVerbosityInformation')] public function testAggregateOptimizedToQuery($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { $this->skipIfServerVersion('<', '4.2.0', 'MongoDB < 4.2 does not optimize simple aggregation pipelines'); diff --git a/tests/Operation/ExplainTest.php b/tests/Operation/ExplainTest.php index 98937a1ca..1255d787c 100644 --- a/tests/Operation/ExplainTest.php +++ b/tests/Operation/ExplainTest.php @@ -5,10 +5,11 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\Explain; use MongoDB\Operation\Explainable; +use PHPUnit\Framework\Attributes\DataProvider; class ExplainTest extends TestCase { - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $explainable = $this->getMockBuilder(Explainable::class)->getMock(); diff --git a/tests/Operation/FindAndModifyFunctionalTest.php b/tests/Operation/FindAndModifyFunctionalTest.php index c16413218..576b0474c 100644 --- a/tests/Operation/FindAndModifyFunctionalTest.php +++ b/tests/Operation/FindAndModifyFunctionalTest.php @@ -12,11 +12,12 @@ use MongoDB\Tests\CommandObserver; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; use MongoDB\Tests\Fixtures\Document\TestObject; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; class FindAndModifyFunctionalTest extends FunctionalTestCase { - /** @dataProvider provideQueryDocuments */ + #[DataProvider('provideQueryDocuments')] public function testQueryDocuments($query, stdClass $expectedQuery): void { (new CommandObserver())->observe( @@ -47,12 +48,10 @@ public static function provideQueryDocuments(): array ]; } - /** - * @dataProvider provideReplacementDocuments - * @dataProvider provideUpdateDocuments - * @dataProvider provideUpdatePipelines - * @dataProvider provideReplacementDocumentLikePipeline - */ + #[DataProvider('provideReplacementDocuments')] + #[DataProvider('provideUpdateDocuments')] + #[DataProvider('provideUpdatePipelines')] + #[DataProvider('provideReplacementDocumentLikePipeline')] public function testUpdateDocuments($update, $expectedUpdate): void { (new CommandObserver())->observe( @@ -233,7 +232,7 @@ function (array $event): void { ); } - /** @dataProvider provideTypeMapOptionsAndExpectedDocument */ + #[DataProvider('provideTypeMapOptionsAndExpectedDocument')] public function testTypeMapOption(?array $typeMap, $expectedDocument): void { $this->createFixtures(1); diff --git a/tests/Operation/FindAndModifyTest.php b/tests/Operation/FindAndModifyTest.php index a6049ed78..7abc5bfb9 100644 --- a/tests/Operation/FindAndModifyTest.php +++ b/tests/Operation/FindAndModifyTest.php @@ -5,10 +5,11 @@ use MongoDB\Driver\WriteConcern; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\FindAndModify; +use PHPUnit\Framework\Attributes\DataProvider; class FindAndModifyTest extends TestCase { - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/FindFunctionalTest.php b/tests/Operation/FindFunctionalTest.php index 2a64a7d71..81745c23f 100644 --- a/tests/Operation/FindFunctionalTest.php +++ b/tests/Operation/FindFunctionalTest.php @@ -11,13 +11,15 @@ use MongoDB\Tests\CommandObserver; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; use MongoDB\Tests\Fixtures\Document\TestObject; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; +use function is_array; use function microtime; class FindFunctionalTest extends FunctionalTestCase { - /** @dataProvider provideFilterDocuments */ + #[DataProvider('provideFilterDocuments')] public function testFilterDocuments($filter, stdClass $expectedQuery): void { (new CommandObserver())->observe( @@ -36,11 +38,16 @@ function (array $event) use ($expectedQuery): void { ); } - /** @dataProvider provideModifierDocuments */ + #[DataProvider('provideModifierDocuments')] public function testModifierDocuments($modifiers, stdClass $expectedSort): void { (new CommandObserver())->observe( function () use ($modifiers): void { + // @todo revert this lines after PHPC-2457 + if (is_array($modifiers)) { + $modifiers = [...$modifiers]; + } + $operation = new Find( $this->getDatabaseName(), $this->getCollectionName(), @@ -159,7 +166,7 @@ function (array $event): void { ); } - /** @dataProvider provideTypeMapOptionsAndExpectedDocuments */ + #[DataProvider('provideTypeMapOptionsAndExpectedDocuments')] public function testTypeMapOption(array $typeMap, array $expectedDocuments): void { $this->createFixtures(3); diff --git a/tests/Operation/FindOneAndDeleteTest.php b/tests/Operation/FindOneAndDeleteTest.php index 76f18bda4..9f4cefd1f 100644 --- a/tests/Operation/FindOneAndDeleteTest.php +++ b/tests/Operation/FindOneAndDeleteTest.php @@ -6,18 +6,19 @@ use MongoDB\Driver\WriteConcern; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\FindOneAndDelete; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; class FindOneAndDeleteTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorFilterArgumentTypeCheck($filter): void { $this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new FindOneAndDelete($this->getDatabaseName(), $this->getCollectionName(), $filter); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/FindOneAndReplaceTest.php b/tests/Operation/FindOneAndReplaceTest.php index c71946ec7..dd273a46d 100644 --- a/tests/Operation/FindOneAndReplaceTest.php +++ b/tests/Operation/FindOneAndReplaceTest.php @@ -6,34 +6,34 @@ use MongoDB\Driver\WriteConcern; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\FindOneAndReplace; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use TypeError; class FindOneAndReplaceTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorFilterArgumentTypeCheck($filter): void { $this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), $filter, []); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorReplacementArgumentTypeCheck($replacement): void { $this->expectException($replacement instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], $replacement); } - /** - * @dataProvider provideReplacementDocuments - * @doesNotPerformAssertions - */ + #[DataProvider('provideReplacementDocuments')] + #[DoesNotPerformAssertions] public function testConstructorReplacementArgument($replacement): void { new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], $replacement); } - /** @dataProvider provideUpdateDocuments */ + #[DataProvider('provideUpdateDocuments')] public function testConstructorReplacementArgumentProhibitsUpdateDocument($replacement): void { $this->expectException(InvalidArgumentException::class); @@ -41,10 +41,8 @@ public function testConstructorReplacementArgumentProhibitsUpdateDocument($repla new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], $replacement); } - /** - * @dataProvider provideUpdatePipelines - * @dataProvider provideEmptyUpdatePipelinesExcludingArray - */ + #[DataProvider('provideUpdatePipelines')] + #[DataProvider('provideEmptyUpdatePipelinesExcludingArray')] public function testConstructorReplacementArgumentProhibitsUpdatePipeline($replacement): void { $this->expectException(InvalidArgumentException::class); @@ -52,7 +50,7 @@ public function testConstructorReplacementArgumentProhibitsUpdatePipeline($repla new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], $replacement); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); @@ -68,7 +66,7 @@ public static function provideInvalidConstructorOptions() ]); } - /** @dataProvider provideInvalidConstructorReturnDocumentOptions */ + #[DataProvider('provideInvalidConstructorReturnDocumentOptions')] public function testConstructorReturnDocumentOption($returnDocument): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/FindOneAndUpdateTest.php b/tests/Operation/FindOneAndUpdateTest.php index 54defcad6..b20ab59ac 100644 --- a/tests/Operation/FindOneAndUpdateTest.php +++ b/tests/Operation/FindOneAndUpdateTest.php @@ -6,28 +6,27 @@ use MongoDB\Driver\WriteConcern; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\FindOneAndUpdate; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; class FindOneAndUpdateTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorFilterArgumentTypeCheck($filter): void { $this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), $filter, []); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorUpdateArgumentTypeCheck($update): void { $this->expectException($update instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), [], $update); } - /** - * @dataProvider provideReplacementDocuments - * @dataProvider provideEmptyUpdatePipelines - */ + #[DataProvider('provideReplacementDocuments')] + #[DataProvider('provideEmptyUpdatePipelines')] public function testConstructorUpdateArgumentProhibitsReplacementDocumentOrEmptyPipeline($update): void { $this->expectException(InvalidArgumentException::class); @@ -35,7 +34,7 @@ public function testConstructorUpdateArgumentProhibitsReplacementDocumentOrEmpty new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), [], $update); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); @@ -50,7 +49,7 @@ public static function provideInvalidConstructorOptions() ]); } - /** @dataProvider provideInvalidConstructorReturnDocumentOptions */ + #[DataProvider('provideInvalidConstructorReturnDocumentOptions')] public function testConstructorReturnDocumentOption($returnDocument): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/FindOneFunctionalTest.php b/tests/Operation/FindOneFunctionalTest.php index 6ae0a28da..de9058b7c 100644 --- a/tests/Operation/FindOneFunctionalTest.php +++ b/tests/Operation/FindOneFunctionalTest.php @@ -6,10 +6,11 @@ use MongoDB\Operation\FindOne; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; use MongoDB\Tests\Fixtures\Document\TestObject; +use PHPUnit\Framework\Attributes\DataProvider; class FindOneFunctionalTest extends FunctionalTestCase { - /** @dataProvider provideTypeMapOptionsAndExpectedDocument */ + #[DataProvider('provideTypeMapOptionsAndExpectedDocument')] public function testTypeMapOption(array $typeMap, $expectedDocument): void { $this->createFixtures(1); diff --git a/tests/Operation/FindTest.php b/tests/Operation/FindTest.php index 1a88cd6a2..d7eccf7f3 100644 --- a/tests/Operation/FindTest.php +++ b/tests/Operation/FindTest.php @@ -7,18 +7,19 @@ use MongoDB\Driver\ReadPreference; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\Find; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; class FindTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorFilterArgumentTypeCheck($filter): void { $this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new Find($this->getDatabaseName(), $this->getCollectionName(), $filter); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); @@ -55,7 +56,7 @@ public static function provideInvalidConstructorOptions() ]); } - /** @dataProvider provideInvalidConstructorCursorTypeOptions */ + #[DataProvider('provideInvalidConstructorCursorTypeOptions')] public function testConstructorCursorTypeOption($cursorType): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/InsertManyFunctionalTest.php b/tests/Operation/InsertManyFunctionalTest.php index d4a786e71..68de6dfce 100644 --- a/tests/Operation/InsertManyFunctionalTest.php +++ b/tests/Operation/InsertManyFunctionalTest.php @@ -13,6 +13,7 @@ use MongoDB\Tests\CommandObserver; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; use MongoDB\Tests\Fixtures\Document\TestObject; +use PHPUnit\Framework\Attributes\Depends; class InsertManyFunctionalTest extends FunctionalTestCase { @@ -189,7 +190,7 @@ public function testUnacknowledgedWriteConcern() return $result; } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesInsertedCount(InsertManyResult $result): void { $this->expectException(BadMethodCallException::class); @@ -197,7 +198,7 @@ public function testUnacknowledgedWriteConcernAccessesInsertedCount(InsertManyRe $result->getInsertedCount(); } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesInsertedId(InsertManyResult $result): void { $this->assertInstanceOf(ObjectId::class, $result->getInsertedIds()[0]); diff --git a/tests/Operation/InsertManyTest.php b/tests/Operation/InsertManyTest.php index 52f32d2cf..8ee11ff5d 100644 --- a/tests/Operation/InsertManyTest.php +++ b/tests/Operation/InsertManyTest.php @@ -6,6 +6,7 @@ use MongoDB\Exception\UnsupportedValueException; use MongoDB\Operation\InsertMany; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; +use PHPUnit\Framework\Attributes\DataProvider; class InsertManyTest extends TestCase { @@ -23,7 +24,7 @@ public function testConstructorDocumentsMustBeAList(): void new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [1 => ['x' => 1]]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorDocumentsArgumentElementTypeChecks($document): void { $this->expectException(InvalidArgumentException::class); @@ -31,7 +32,7 @@ public function testConstructorDocumentsArgumentElementTypeChecks($document): vo new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [$document]); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/InsertOneFunctionalTest.php b/tests/Operation/InsertOneFunctionalTest.php index 218a8853c..9cef81f04 100644 --- a/tests/Operation/InsertOneFunctionalTest.php +++ b/tests/Operation/InsertOneFunctionalTest.php @@ -13,6 +13,8 @@ use MongoDB\Tests\CommandObserver; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; use MongoDB\Tests\Fixtures\Document\TestObject; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; use stdClass; class InsertOneFunctionalTest extends FunctionalTestCase @@ -26,10 +28,8 @@ public function setUp(): void $this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName()); } - /** - * @dataProvider provideDocumentsWithIds - * @dataProvider provideDocumentsWithoutIds - */ + #[DataProvider('provideDocumentsWithIds')] + #[DataProvider('provideDocumentsWithoutIds')] public function testDocumentEncoding($document, stdClass $expectedDocument): void { (new CommandObserver())->observe( @@ -80,7 +80,7 @@ public static function provideDocumentsWithoutIds(): array ]; } - /** @dataProvider provideDocumentsWithIds */ + #[DataProvider('provideDocumentsWithIds')] public function testInsertOneWithExistingId($document, stdClass $expectedDocument): void { $operation = new InsertOne($this->getDatabaseName(), $this->getCollectionName(), $document); @@ -93,7 +93,7 @@ public function testInsertOneWithExistingId($document, stdClass $expectedDocumen $this->assertSameDocuments([$expectedDocument], $this->collection->find()); } - /** @dataProvider provideDocumentsWithoutIds */ + #[DataProvider('provideDocumentsWithoutIds')] public function testInsertOneWithGeneratedId($document, stdClass $expectedDocument): void { $operation = new InsertOne($this->getDatabaseName(), $this->getCollectionName(), $document); @@ -180,7 +180,7 @@ public function testUnacknowledgedWriteConcern() return $result; } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesInsertedCount(InsertOneResult $result): void { $this->expectException(BadMethodCallException::class); @@ -188,7 +188,7 @@ public function testUnacknowledgedWriteConcernAccessesInsertedCount(InsertOneRes $result->getInsertedCount(); } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesInsertedId(InsertOneResult $result): void { $this->assertInstanceOf(ObjectId::class, $result->getInsertedId()); diff --git a/tests/Operation/InsertOneTest.php b/tests/Operation/InsertOneTest.php index 6f493d9d1..1f641ea88 100644 --- a/tests/Operation/InsertOneTest.php +++ b/tests/Operation/InsertOneTest.php @@ -7,18 +7,19 @@ use MongoDB\Exception\UnsupportedValueException; use MongoDB\Operation\InsertOne; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; class InsertOneTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorDocumentArgumentTypeCheck($document): void { $this->expectException($document instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new InsertOne($this->getDatabaseName(), $this->getCollectionName(), $document); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/ListCollectionsFunctionalTest.php b/tests/Operation/ListCollectionsFunctionalTest.php index 9f03e14fe..259e6cbdb 100644 --- a/tests/Operation/ListCollectionsFunctionalTest.php +++ b/tests/Operation/ListCollectionsFunctionalTest.php @@ -8,6 +8,7 @@ use MongoDB\Operation\InsertOne; use MongoDB\Operation\ListCollections; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\Group; class ListCollectionsFunctionalTest extends FunctionalTestCase { @@ -35,12 +36,10 @@ public function testListCollectionsForNewlyCreatedDatabase(): void } } - /** - * @group matrix-testing-exclude-server-4.4-driver-4.0 - * @group matrix-testing-exclude-server-4.4-driver-4.2 - * @group matrix-testing-exclude-server-5.0-driver-4.0 - * @group matrix-testing-exclude-server-5.0-driver-4.2 - */ + #[Group('matrix-testing-exclude-server-4.4-driver-4.0')] + #[Group('matrix-testing-exclude-server-4.4-driver-4.2')] + #[Group('matrix-testing-exclude-server-5.0-driver-4.0')] + #[Group('matrix-testing-exclude-server-5.0-driver-4.2')] public function testIdIndexAndInfo(): void { $server = $this->getPrimaryServer(); diff --git a/tests/Operation/ListIndexesTest.php b/tests/Operation/ListIndexesTest.php index 690eb4bca..f6c7a095b 100644 --- a/tests/Operation/ListIndexesTest.php +++ b/tests/Operation/ListIndexesTest.php @@ -4,10 +4,11 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\ListIndexes; +use PHPUnit\Framework\Attributes\DataProvider; class ListIndexesTest extends TestCase { - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/ListSearchIndexesTest.php b/tests/Operation/ListSearchIndexesTest.php index b07909351..d47e5e893 100644 --- a/tests/Operation/ListSearchIndexesTest.php +++ b/tests/Operation/ListSearchIndexesTest.php @@ -4,6 +4,7 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\ListSearchIndexes; +use PHPUnit\Framework\Attributes\DataProvider; class ListSearchIndexesTest extends TestCase { @@ -13,7 +14,7 @@ public function testConstructorIndexNameMustNotBeEmpty(): void new ListSearchIndexes($this->getDatabaseName(), $this->getCollectionName(), ['name' => '']); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/MapReduceFunctionalTest.php b/tests/Operation/MapReduceFunctionalTest.php index 69a39f297..5dbe45f3a 100644 --- a/tests/Operation/MapReduceFunctionalTest.php +++ b/tests/Operation/MapReduceFunctionalTest.php @@ -8,18 +8,18 @@ use MongoDB\Operation\Find; use MongoDB\Operation\MapReduce; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use function is_object; use function iterator_to_array; use function usort; use function version_compare; -/** - * @group matrix-testing-exclude-server-4.4-driver-4.0 - * @group matrix-testing-exclude-server-4.4-driver-4.2 - * @group matrix-testing-exclude-server-5.0-driver-4.0 - * @group matrix-testing-exclude-server-5.0-driver-4.2 - */ +#[Group('matrix-testing-exclude-server-4.4-driver-4.0')] +#[Group('matrix-testing-exclude-server-4.4-driver-4.2')] +#[Group('matrix-testing-exclude-server-5.0-driver-4.0')] +#[Group('matrix-testing-exclude-server-5.0-driver-4.2')] class MapReduceFunctionalTest extends FunctionalTestCase { public function testDefaultReadConcernIsOmitted(): void @@ -213,7 +213,7 @@ function (array $event): void { ); } - /** @dataProvider provideTypeMapOptionsAndExpectedDocuments */ + #[DataProvider('provideTypeMapOptionsAndExpectedDocuments')] public function testTypeMapOptionWithInlineResults(?array $typeMap, array $expectedDocuments): void { $this->createFixtures(3); @@ -258,7 +258,7 @@ public static function provideTypeMapOptionsAndExpectedDocuments() ]; } - /** @dataProvider provideTypeMapOptionsAndExpectedDocuments */ + #[DataProvider('provideTypeMapOptionsAndExpectedDocuments')] public function testTypeMapOptionWithOutputCollection(?array $typeMap, array $expectedDocuments): void { $this->createFixtures(3); diff --git a/tests/Operation/MapReduceTest.php b/tests/Operation/MapReduceTest.php index 6db1a9b99..86af81197 100644 --- a/tests/Operation/MapReduceTest.php +++ b/tests/Operation/MapReduceTest.php @@ -10,12 +10,13 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Model\BSONDocument; use MongoDB\Operation\MapReduce; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use TypeError; class MapReduceTest extends TestCase { - /** @dataProvider provideInvalidOutValues */ + #[DataProvider('provideInvalidOutValues')] public function testConstructorOutArgumentTypeCheck($out): void { $map = new Javascript('function() { emit(this.x, this.y); }'); @@ -30,7 +31,7 @@ public static function provideInvalidOutValues() return self::wrapValuesForDataProvider([123, 3.14, true]); } - /** @dataProvider provideDeprecatedOutValues */ + #[DataProvider('provideDeprecatedOutValues')] public function testConstructorOutArgumentDeprecations($out): void { $map = new Javascript('function() { emit(this.x, this.y); }'); @@ -55,7 +56,7 @@ public static function provideDeprecatedOutValues(): array ]; } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $map = new Javascript('function() { emit(this.x, this.y); }'); diff --git a/tests/Operation/ModifyCollectionFunctionalTest.php b/tests/Operation/ModifyCollectionFunctionalTest.php index c92cdb0e8..9c6e3a42d 100644 --- a/tests/Operation/ModifyCollectionFunctionalTest.php +++ b/tests/Operation/ModifyCollectionFunctionalTest.php @@ -4,14 +4,13 @@ use MongoDB\Operation\CreateIndexes; use MongoDB\Operation\ModifyCollection; +use PHPUnit\Framework\Attributes\Group; class ModifyCollectionFunctionalTest extends FunctionalTestCase { - /** - * @group matrix-testing-exclude-server-4.2-driver-4.0-topology-sharded_cluster - * @group matrix-testing-exclude-server-4.4-driver-4.0-topology-sharded_cluster - * @group matrix-testing-exclude-server-5.0-driver-4.0-topology-sharded_cluster - */ + #[Group('matrix-testing-exclude-server-4.2-driver-4.0-topology-sharded_cluster')] + #[Group('matrix-testing-exclude-server-4.4-driver-4.0-topology-sharded_cluster')] + #[Group('matrix-testing-exclude-server-5.0-driver-4.0-topology-sharded_cluster')] public function testCollMod(): void { if ($this->isShardedCluster()) { diff --git a/tests/Operation/ModifyCollectionTest.php b/tests/Operation/ModifyCollectionTest.php index 8369d341e..c835d6a6d 100644 --- a/tests/Operation/ModifyCollectionTest.php +++ b/tests/Operation/ModifyCollectionTest.php @@ -4,6 +4,7 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\ModifyCollection; +use PHPUnit\Framework\Attributes\DataProvider; class ModifyCollectionTest extends TestCase { @@ -14,7 +15,7 @@ public function testConstructorEmptyCollectionOptions(): void new ModifyCollection($this->getDatabaseName(), $this->getCollectionName(), []); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/RenameCollectionTest.php b/tests/Operation/RenameCollectionTest.php index a4e190652..bae80e9ee 100644 --- a/tests/Operation/RenameCollectionTest.php +++ b/tests/Operation/RenameCollectionTest.php @@ -4,10 +4,11 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\RenameCollection; +use PHPUnit\Framework\Attributes\DataProvider; class RenameCollectionTest extends TestCase { - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/ReplaceOneTest.php b/tests/Operation/ReplaceOneTest.php index dc6ef2c47..d74cd7566 100644 --- a/tests/Operation/ReplaceOneTest.php +++ b/tests/Operation/ReplaceOneTest.php @@ -7,34 +7,34 @@ use MongoDB\Exception\UnsupportedValueException; use MongoDB\Operation\ReplaceOne; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use TypeError; class ReplaceOneTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorFilterArgumentTypeCheck($filter): void { $this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), $filter, ['y' => 1]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorReplacementArgumentTypeCheck($replacement): void { $this->expectException($replacement instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement); } - /** - * @dataProvider provideReplacementDocuments - * @doesNotPerformAssertions - */ + #[DataProvider('provideReplacementDocuments')] + #[DoesNotPerformAssertions] public function testConstructorReplacementArgument($replacement): void { new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement); } - /** @dataProvider provideUpdateDocuments */ + #[DataProvider('provideUpdateDocuments')] public function testConstructorReplacementArgumentProhibitsUpdateDocument($replacement): void { $this->expectException(InvalidArgumentException::class); @@ -42,10 +42,8 @@ public function testConstructorReplacementArgumentProhibitsUpdateDocument($repla new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement); } - /** - * @dataProvider provideUpdatePipelines - * @dataProvider provideEmptyUpdatePipelinesExcludingArray - */ + #[DataProvider('provideUpdatePipelines')] + #[DataProvider('provideEmptyUpdatePipelinesExcludingArray')] public function testConstructorReplacementArgumentProhibitsUpdatePipeline($replacement): void { $this->expectException(InvalidArgumentException::class); @@ -53,7 +51,7 @@ public function testConstructorReplacementArgumentProhibitsUpdatePipeline($repla new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionsTypeCheck($options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/UpdateFunctionalTest.php b/tests/Operation/UpdateFunctionalTest.php index 2a18f13aa..9415960f5 100644 --- a/tests/Operation/UpdateFunctionalTest.php +++ b/tests/Operation/UpdateFunctionalTest.php @@ -11,6 +11,8 @@ use MongoDB\Operation\Update; use MongoDB\Tests\CommandObserver; use MongoDB\UpdateResult; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; use stdClass; use function is_array; @@ -26,7 +28,7 @@ public function setUp(): void $this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName()); } - /** @dataProvider provideFilterDocuments */ + #[DataProvider('provideFilterDocuments')] public function testFilterDocuments($filter, stdClass $expectedFilter): void { (new CommandObserver())->observe( @@ -46,12 +48,10 @@ function (array $event) use ($expectedFilter): void { ); } - /** - * @dataProvider provideReplacementDocuments - * @dataProvider provideUpdateDocuments - * @dataProvider provideUpdatePipelines - * @dataProvider provideReplacementDocumentLikePipeline - */ + #[DataProvider('provideReplacementDocuments')] + #[DataProvider('provideUpdateDocuments')] + #[DataProvider('provideUpdatePipelines')] + #[DataProvider('provideReplacementDocumentLikePipeline')] public function testUpdateDocuments($update, $expectedUpdate): void { if (is_array($expectedUpdate)) { @@ -284,7 +284,7 @@ public function testUnacknowledgedWriteConcern() return $result; } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesMatchedCount(UpdateResult $result): void { $this->expectException(BadMethodCallException::class); @@ -292,7 +292,7 @@ public function testUnacknowledgedWriteConcernAccessesMatchedCount(UpdateResult $result->getMatchedCount(); } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesModifiedCount(UpdateResult $result): void { $this->expectException(BadMethodCallException::class); @@ -300,7 +300,7 @@ public function testUnacknowledgedWriteConcernAccessesModifiedCount(UpdateResult $result->getModifiedCount(); } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesUpsertedCount(UpdateResult $result): void { $this->expectException(BadMethodCallException::class); @@ -308,7 +308,7 @@ public function testUnacknowledgedWriteConcernAccessesUpsertedCount(UpdateResult $result->getUpsertedCount(); } - /** @depends testUnacknowledgedWriteConcern */ + #[Depends('testUnacknowledgedWriteConcern')] public function testUnacknowledgedWriteConcernAccessesUpsertedId(UpdateResult $result): void { $this->expectException(BadMethodCallException::class); diff --git a/tests/Operation/UpdateManyTest.php b/tests/Operation/UpdateManyTest.php index 99acecf33..30c0a0836 100644 --- a/tests/Operation/UpdateManyTest.php +++ b/tests/Operation/UpdateManyTest.php @@ -5,38 +5,36 @@ use MongoDB\BSON\PackedArray; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\UpdateMany; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use TypeError; class UpdateManyTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorFilterArgumentTypeCheck($filter): void { $this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorUpdateArgumentTypeCheck($update): void { $this->expectException($update instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update); } - /** - * @dataProvider provideUpdateDocuments - * @dataProvider provideUpdatePipelines - * @doesNotPerformAssertions - */ + #[DataProvider('provideUpdateDocuments')] + #[DataProvider('provideUpdatePipelines')] + #[DoesNotPerformAssertions] public function testConstructorUpdateArgument($update): void { new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update); } - /** - * @dataProvider provideReplacementDocuments - * @dataProvider provideEmptyUpdatePipelines - */ + #[DataProvider('provideReplacementDocuments')] + #[DataProvider('provideEmptyUpdatePipelines')] public function testConstructorUpdateArgumentProhibitsReplacementDocumentOrEmptyPipeline($update): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/UpdateOneTest.php b/tests/Operation/UpdateOneTest.php index e0c4086a0..25d67f45c 100644 --- a/tests/Operation/UpdateOneTest.php +++ b/tests/Operation/UpdateOneTest.php @@ -5,38 +5,36 @@ use MongoDB\BSON\PackedArray; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\UpdateOne; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use TypeError; class UpdateOneTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorFilterArgumentTypeCheck($filter): void { $this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorUpdateArgumentTypeCheck($update): void { $this->expectException($update instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update); } - /** - * @dataProvider provideUpdateDocuments - * @dataProvider provideUpdatePipelines - * @doesNotPerformAssertions - */ + #[DataProvider('provideUpdateDocuments')] + #[DataProvider('provideUpdatePipelines')] + #[DoesNotPerformAssertions] public function testConstructorUpdateArgument($update): void { new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update); } - /** - * @dataProvider provideReplacementDocuments - * @dataProvider provideEmptyUpdatePipelines - */ + #[DataProvider('provideReplacementDocuments')] + #[DataProvider('provideEmptyUpdatePipelines')] public function testConstructorUpdateArgumentProhibitsReplacementDocumentOrEmptyPipeline($update): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/UpdateSearchIndexTest.php b/tests/Operation/UpdateSearchIndexTest.php index befe07eb1..f61db793e 100644 --- a/tests/Operation/UpdateSearchIndexTest.php +++ b/tests/Operation/UpdateSearchIndexTest.php @@ -5,6 +5,7 @@ use MongoDB\BSON\PackedArray; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\UpdateSearchIndex; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; class UpdateSearchIndexTest extends TestCase @@ -15,7 +16,7 @@ public function testConstructorIndexNameMustNotBeEmpty(): void new UpdateSearchIndex($this->getDatabaseName(), $this->getCollectionName(), '', []); } - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorIndexDefinitionMustBeADocument($definition): void { $this->expectException($definition instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); diff --git a/tests/Operation/UpdateTest.php b/tests/Operation/UpdateTest.php index 468bf00bf..6c6f590d5 100644 --- a/tests/Operation/UpdateTest.php +++ b/tests/Operation/UpdateTest.php @@ -6,25 +6,26 @@ use MongoDB\Driver\WriteConcern; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\Update; +use PHPUnit\Framework\Attributes\DataProvider; use TypeError; class UpdateTest extends TestCase { - /** @dataProvider provideInvalidDocumentValues */ + #[DataProvider('provideInvalidDocumentValues')] public function testConstructorFilterArgumentTypeCheck($filter): void { $this->expectException($filter instanceof PackedArray ? InvalidArgumentException::class : TypeError::class); new Update($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]); } - /** @dataProvider provideInvalidUpdateValues */ + #[DataProvider('provideInvalidUpdateValues')] public function testConstructorUpdateArgumentTypeCheck($update): void { $this->expectException(TypeError::class); new Update($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); @@ -45,10 +46,8 @@ public static function provideInvalidConstructorOptions() ]); } - /** - * @dataProvider provideReplacementDocuments - * @dataProvider provideEmptyUpdatePipelines - */ + #[DataProvider('provideReplacementDocuments')] + #[DataProvider('provideEmptyUpdatePipelines')] public function testConstructorMultiOptionProhibitsReplacementDocumentOrEmptyPipeline($update): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Operation/WatchFunctionalTest.php b/tests/Operation/WatchFunctionalTest.php index df4c98fdc..15326f696 100644 --- a/tests/Operation/WatchFunctionalTest.php +++ b/tests/Operation/WatchFunctionalTest.php @@ -25,6 +25,8 @@ use MongoDB\Operation\InsertOne; use MongoDB\Operation\Watch; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Constraint\ObjectHasProperty; use PHPUnit\Framework\ExpectationFailedException; use ReflectionClass; @@ -37,11 +39,9 @@ use function microtime; use function sprintf; -/** - * @group matrix-testing-exclude-server-4.2-driver-4.0-topology-sharded_cluster - * @group matrix-testing-exclude-server-4.4-driver-4.0-topology-sharded_cluster - * @group matrix-testing-exclude-server-5.0-driver-4.0-topology-sharded_cluster - */ +#[Group('matrix-testing-exclude-server-4.2-driver-4.0-topology-sharded_cluster')] +#[Group('matrix-testing-exclude-server-4.4-driver-4.0-topology-sharded_cluster')] +#[Group('matrix-testing-exclude-server-5.0-driver-4.0-topology-sharded_cluster')] class WatchFunctionalTest extends FunctionalTestCase { public const INTERRUPTED = 11601; @@ -109,9 +109,8 @@ public function encode($value): Document /** * Prose test 1: "ChangeStream must continuously track the last seen * resumeToken" - * - * @dataProvider provideCodecOptions */ + #[DataProvider('provideCodecOptions')] public function testGetResumeToken(array $options, Closure $getIdentifier): void { $this->skipIfServerVersion('>=', '4.0.7', 'postBatchResumeToken is supported'); @@ -162,9 +161,8 @@ public function testGetResumeToken(array $options, Closure $getIdentifier): void * - The batch has been iterated up to but not including the last element. * Expected result: getResumeToken must return the _id of the previous * document returned. - * - * @dataProvider provideCodecOptions */ + #[DataProvider('provideCodecOptions')] public function testGetResumeTokenWithPostBatchResumeToken(array $options, Closure $getIdentifier): void { $this->skipIfServerVersion('<', '4.0.7', 'postBatchResumeToken is not supported'); @@ -489,7 +487,7 @@ public function testRewindMultipleTimesWithNoResults(): void $this->assertNull($changeStream->current()); } - /** @dataProvider provideCodecOptions */ + #[DataProvider('provideCodecOptions')] public function testNoChangeAfterResumeBeforeInsert(array $options): void { $operation = new Watch( @@ -895,7 +893,7 @@ public function testMaxAwaitTimeMS(): void } } - /** @dataProvider provideCodecOptions */ + #[DataProvider('provideCodecOptions')] public function testRewindExtractsResumeTokenAndNextResumes(array $options, Closure $getIdentifier): void { $operation = new Watch( @@ -953,7 +951,7 @@ public function testRewindExtractsResumeTokenAndNextResumes(array $options, Clos $this->assertMatchesDocument(['_id' => 3, 'x' => 'baz'], $changeStream->current()->fullDocument); } - /** @dataProvider provideCodecOptions */ + #[DataProvider('provideCodecOptions')] public function testResumeAfterOption(array $options, Closure $getIdentifier): void { $operation = new Watch( @@ -999,7 +997,7 @@ public function testResumeAfterOption(array $options, Closure $getIdentifier): v $this->assertMatchesDocument(['_id' => 2, 'x' => 'bar'], $changeStream->current()->fullDocument); } - /** @dataProvider provideCodecOptions */ + #[DataProvider('provideCodecOptions')] public function testStartAfterOption(array $options, Closure $getIdentifier): void { $this->skipIfServerVersion('<', '4.1.1', 'startAfter is not supported'); @@ -1047,7 +1045,7 @@ public function testStartAfterOption(array $options, Closure $getIdentifier): vo $this->assertMatchesDocument(['_id' => 2, 'x' => 'bar'], $changeStream->current()->fullDocument); } - /** @dataProvider provideTypeMapOptionsAndExpectedChangeDocument */ + #[DataProvider('provideTypeMapOptionsAndExpectedChangeDocument')] public function testTypeMapOption(array $typeMap, $expectedChangeDocument): void { $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['typeMap' => $typeMap] + $this->defaultOptions); @@ -1427,9 +1425,8 @@ public function testGetResumeTokenReturnsOriginalResumeTokenOnEmptyBatch(): void * - getResumeToken must return startAfter from the initial aggregate if the option was specified. * - getResumeToken must return resumeAfter from the initial aggregate if the option was specified. * - If neither the startAfter nor resumeAfter options were specified, the getResumeToken result must be empty. - * - * @dataProvider provideCodecOptions */ + #[DataProvider('provideCodecOptions')] public function testResumeTokenBehaviour(array $options): void { $this->skipIfServerVersion('<', '4.1.1', 'Testing resumeAfter and startAfter can only be tested on servers >= 4.1.1'); diff --git a/tests/Operation/WatchTest.php b/tests/Operation/WatchTest.php index 8a3f4945d..9e874c484 100644 --- a/tests/Operation/WatchTest.php +++ b/tests/Operation/WatchTest.php @@ -5,6 +5,7 @@ use MongoDB\Exception\InvalidArgumentException; use MongoDB\Operation\Watch; use MongoDB\Tests\Fixtures\Codec\TestDocumentCodec; +use PHPUnit\Framework\Attributes\DataProvider; use stdClass; /** @@ -32,7 +33,7 @@ public function testConstructorPipelineArgumentMustBeAList(): void new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), ['foo' => ['$match' => ['x' => 1]]]); } - /** @dataProvider provideInvalidConstructorOptions */ + #[DataProvider('provideInvalidConstructorOptions')] public function testConstructorOptionTypeChecks(array $options): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/PedantryTest.php b/tests/PedantryTest.php index 5c6b07eed..3d89f259a 100644 --- a/tests/PedantryTest.php +++ b/tests/PedantryTest.php @@ -3,6 +3,7 @@ namespace MongoDB\Tests; use MongoDB; +use PHPUnit\Framework\Attributes\DataProvider; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use ReflectionClass; @@ -32,7 +33,7 @@ class PedantryTest extends TestCase MongoDB\Builder\Stage\FluentFactoryTrait::class, ]; - /** @dataProvider provideProjectClassNames */ + #[DataProvider('provideProjectClassNames')] public function testMethodsAreOrderedAlphabeticallyByVisibility($className): void { $class = new ReflectionClass($className); diff --git a/tests/PsrLogAdapterTest.php b/tests/PsrLogAdapterTest.php index 5e945dd62..1907b8532 100644 --- a/tests/PsrLogAdapterTest.php +++ b/tests/PsrLogAdapterTest.php @@ -5,6 +5,7 @@ use MongoDB\Driver\Monitoring\LogSubscriber; use MongoDB\Exception\UnexpectedValueException; use MongoDB\PsrLogAdapter; +use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase as BaseTestCase; use Psr\Log\AbstractLogger; use Psr\Log\LoggerInterface; @@ -84,10 +85,8 @@ public function testLog(): void $this->assertSame($expectedLogs, $this->logger->logs); } - /** - * @testWith [-1] - * [9] - */ + #[TestWith([-1])] + #[TestWith([9])] public function testWriteLogWithInvalidLevel(int $level): void { $this->expectException(UnexpectedValueException::class); diff --git a/tests/SpecTests/AtlasDataLakeSpecTest.php b/tests/SpecTests/AtlasDataLakeSpecTest.php index 3d008093c..da8af86df 100644 --- a/tests/SpecTests/AtlasDataLakeSpecTest.php +++ b/tests/SpecTests/AtlasDataLakeSpecTest.php @@ -4,6 +4,7 @@ use MongoDB\Driver\Cursor; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Attributes\Group; use function current; use function explode; @@ -13,8 +14,8 @@ * Atlas Data Lake spec tests. * * @see https://github.com/mongodb/specifications/tree/master/source/atlas-data-lake-testing/tests - * @group atlas-data-lake */ +#[Group('atlas-data-lake')] class AtlasDataLakeSpecTest extends FunctionalTestCase { public function setUp(): void diff --git a/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php b/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php index ddea08972..874671642 100644 --- a/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php +++ b/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php @@ -10,6 +10,8 @@ use MongoDB\Driver\Exception\CommandException; use MongoDB\Exception\CreateEncryptedCollectionException; use MongoDB\Exception\InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use function base64_decode; @@ -17,9 +19,9 @@ * Prose test 21: Automatic Data Encryption Keys * * @see https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#automatic-data-encryption-keys - * @group csfle - * @group serverless */ +#[Group('csfle')] +#[Group('serverless')] class Prose21_AutomaticDataEncryptionKeysTest extends FunctionalTestCase { public const SERVER_ERROR_TYPEMISMATCH = 14; @@ -63,10 +65,8 @@ public function tearDown(): void $this->database = null; } - /** - * @see https://github.com/mongodb/specifications/blob/bc37892f360cab9df4082922384e0f4d4233f6d3/source/client-side-encryption/tests/README.rst#case-1-simple-creation-and-validation - * @dataProvider provideKmsProviderAndMasterKey - */ + /** @see https://github.com/mongodb/specifications/blob/bc37892f360cab9df4082922384e0f4d4233f6d3/source/client-side-encryption/tests/README.rst#case-1-simple-creation-and-validation */ + #[DataProvider('provideKmsProviderAndMasterKey')] public function testCase1_SimpleCreationAndValidation(string $kmsProvider, ?array $masterKey): void { [$result, $encryptedFields] = $this->database->createEncryptedCollection( @@ -98,10 +98,8 @@ public static function provideKmsProviderAndMasterKey(): Generator ]; } - /** - * @see https://github.com/mongodb/specifications/blob/bc37892f360cab9df4082922384e0f4d4233f6d3/source/client-side-encryption/tests/README.rst#case-2-missing-encryptedfields - * @dataProvider provideKmsProviderAndMasterKey - */ + /** @see https://github.com/mongodb/specifications/blob/bc37892f360cab9df4082922384e0f4d4233f6d3/source/client-side-encryption/tests/README.rst#case-2-missing-encryptedfields */ + #[DataProvider('provideKmsProviderAndMasterKey')] public function testCase2_MissingEncryptedFields(string $kmsProvider, ?array $masterKey): void { $this->expectException(InvalidArgumentException::class); @@ -115,10 +113,8 @@ public function testCase2_MissingEncryptedFields(string $kmsProvider, ?array $ma ); } - /** - * @see https://github.com/mongodb/specifications/blob/bc37892f360cab9df4082922384e0f4d4233f6d3/source/client-side-encryption/tests/README.rst#case-3-invalid-keyid - * @dataProvider provideKmsProviderAndMasterKey - */ + /** @see https://github.com/mongodb/specifications/blob/bc37892f360cab9df4082922384e0f4d4233f6d3/source/client-side-encryption/tests/README.rst#case-3-invalid-keyid */ + #[DataProvider('provideKmsProviderAndMasterKey')] public function testCase3_InvalidKeyId(string $kmsProvider, ?array $masterKey): void { try { @@ -140,10 +136,8 @@ public function testCase3_InvalidKeyId(string $kmsProvider, ?array $masterKey): } } - /** - * @see https://github.com/mongodb/specifications/blob/bc37892f360cab9df4082922384e0f4d4233f6d3/source/client-side-encryption/tests/README.rst#case-4-insert-encrypted-value - * @dataProvider provideKmsProviderAndMasterKey - */ + /** @see https://github.com/mongodb/specifications/blob/bc37892f360cab9df4082922384e0f4d4233f6d3/source/client-side-encryption/tests/README.rst#case-4-insert-encrypted-value */ + #[DataProvider('provideKmsProviderAndMasterKey')] public function testCase4_InsertEncryptedValue(string $kmsProvider, ?array $masterKey): void { [$result, $encryptedFields] = $this->database->createEncryptedCollection( diff --git a/tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php b/tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php index f805df3c0..a4c869866 100644 --- a/tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php +++ b/tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php @@ -16,6 +16,8 @@ use MongoDB\Driver\ClientEncryption; use MongoDB\Driver\Exception\EncryptionException; use MultipleIterator; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use function base64_decode; use function file_get_contents; @@ -26,9 +28,9 @@ * Prose test 22: Range Explicit Encryption * * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#22-range-explicit-encryption - * @group csfle - * @group serverless */ +#[Group('csfle')] +#[Group('serverless')] class Prose22_RangeExplicitEncryptionTest extends FunctionalTestCase { private ?ClientEncryption $clientEncryption = null; @@ -178,10 +180,8 @@ public static function provideTypeAndRangeOpts(): Generator ]; } - /** - * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-1-can-decrypt-a-payload - * @dataProvider provideTypeAndRangeOpts - */ + /** @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-1-can-decrypt-a-payload */ + #[DataProvider('provideTypeAndRangeOpts')] public function testCase1_CanDecryptAPayload(string $type, array $rangeOpts): void { $this->setUpWithTypeAndRangeOpts($type, $rangeOpts); @@ -211,10 +211,8 @@ public function testCase1_CanDecryptAPayload(string $type, array $rangeOpts): vo $this->assertEquals($originalValue, $decryptedValue); } - /** - * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-2-can-find-encrypted-range-and-return-the-maximum - * @dataProvider provideTypeAndRangeOpts - */ + /** @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-2-can-find-encrypted-range-and-return-the-maximum */ + #[DataProvider('provideTypeAndRangeOpts')] public function testCase2_CanFindEncryptedRangeAndReturnTheMaximum(string $type, array $rangeOpts): void { $this->setUpWithTypeAndRangeOpts($type, $rangeOpts); @@ -248,10 +246,8 @@ public function testCase2_CanFindEncryptedRangeAndReturnTheMaximum(string $type, $this->assertMultipleDocumentsMatch($expectedDocuments, $cursor); } - /** - * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-3-can-find-encrypted-range-and-return-the-minimum - * @dataProvider provideTypeAndRangeOpts - */ + /** @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-3-can-find-encrypted-range-and-return-the-minimum */ + #[DataProvider('provideTypeAndRangeOpts')] public function testCase3_CanFindEncryptedRangeAndReturnTheMinimum(string $type, array $rangeOpts): void { $this->setUpWithTypeAndRangeOpts($type, $rangeOpts); @@ -284,10 +280,8 @@ public function testCase3_CanFindEncryptedRangeAndReturnTheMinimum(string $type, $this->assertMultipleDocumentsMatch($expectedDocuments, $cursor); } - /** - * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-4-can-find-encrypted-range-with-an-open-range-query - * @dataProvider provideTypeAndRangeOpts - */ + /** @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-4-can-find-encrypted-range-with-an-open-range-query */ + #[DataProvider('provideTypeAndRangeOpts')] public function testCase4_CanFindEncryptedRangeWithAnOpenRangeQuery(string $type, array $rangeOpts): void { $this->setUpWithTypeAndRangeOpts($type, $rangeOpts); @@ -311,10 +305,8 @@ public function testCase4_CanFindEncryptedRangeWithAnOpenRangeQuery(string $type $this->assertMultipleDocumentsMatch($expectedDocuments, $cursor); } - /** - * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-5-can-run-an-aggregation-expression-inside-expr - * @dataProvider provideTypeAndRangeOpts - */ + /** @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-5-can-run-an-aggregation-expression-inside-expr */ + #[DataProvider('provideTypeAndRangeOpts')] public function testCase5_CanRunAnAggregationExpressionInsideExpr(string $type, array $rangeOpts): void { $this->setUpWithTypeAndRangeOpts($type, $rangeOpts); @@ -343,10 +335,8 @@ public function testCase5_CanRunAnAggregationExpressionInsideExpr(string $type, $this->assertMultipleDocumentsMatch($expectedDocuments, $cursor); } - /** - * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-6-encrypting-a-document-greater-than-the-maximum-errors - * @dataProvider provideTypeAndRangeOpts - */ + /** @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-6-encrypting-a-document-greater-than-the-maximum-errors */ + #[DataProvider('provideTypeAndRangeOpts')] public function testCase6_EncryptingADocumentGreaterThanTheMaximumErrors(string $type, array $rangeOpts): void { if ($type === 'DecimalNoPrecision' || $type === 'DoubleNoPrecision') { @@ -367,10 +357,8 @@ public function testCase6_EncryptingADocumentGreaterThanTheMaximumErrors(string $this->clientEncryption->encrypt(self::cast($type, 201), $encryptOpts); } - /** - * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-7-encrypting-a-value-of-a-different-type-errors - * @dataProvider provideTypeAndRangeOpts - */ + /** @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-7-encrypting-a-value-of-a-different-type-errors */ + #[DataProvider('provideTypeAndRangeOpts')] public function testCase7_EncryptingAValueOfADifferentTypeErrors(string $type, array $rangeOpts): void { if ($type === 'DecimalNoPrecision' || $type === 'DoubleNoPrecision') { @@ -395,10 +383,8 @@ public function testCase7_EncryptingAValueOfADifferentTypeErrors(string $type, a $this->clientEncryption->encrypt($value, $encryptOpts); } - /** - * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-8-setting-precision-errors-if-the-type-is-not-double-or-decimal128 - * @dataProvider provideTypeAndRangeOpts - */ + /** @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#case-8-setting-precision-errors-if-the-type-is-not-double-or-decimal128 */ + #[DataProvider('provideTypeAndRangeOpts')] public function testCase8_SettingPrecisionErrorsIfTheTypeIsNotDoubleOrDecimal128(string $type, array $rangeOpts): void { if ($type === 'DecimalNoPrecision' || $type === 'DecimalPrecision' || $type === 'DoubleNoPrecision' || $type === 'DoublePrecision') { diff --git a/tests/SpecTests/ClientSideEncryptionSpecTest.php b/tests/SpecTests/ClientSideEncryptionSpecTest.php index 263fc61c2..b18eff642 100644 --- a/tests/SpecTests/ClientSideEncryptionSpecTest.php +++ b/tests/SpecTests/ClientSideEncryptionSpecTest.php @@ -24,6 +24,9 @@ use MongoDB\Driver\WriteConcern; use MongoDB\Tests\CommandObserver; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\SkippedTestError; use stdClass; use Throwable; @@ -48,9 +51,9 @@ * Client-side encryption spec tests. * * @see https://github.com/mongodb/specifications/tree/master/source/client-side-encryption - * @group csfle - * @group serverless */ +#[Group('csfle')] +#[Group('serverless')] class ClientSideEncryptionSpecTest extends FunctionalTestCase { public const LOCAL_MASTERKEY = 'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk'; @@ -149,7 +152,6 @@ public static function createTestClient(?string $uri = null, array $options = [] /** * Execute an individual test case from the specification. * - * @dataProvider provideTests * @param stdClass $test Individual "tests[]" document * @param array $runOn Top-level "runOn" array with server requirements * @param array $data Top-level "data" array to initialize collection @@ -158,6 +160,7 @@ public static function createTestClient(?string $uri = null, array $options = [] * @param string $databaseName Name of database under test * @param string $collectionName Name of collection under test */ + #[DataProvider('provideTests')] public function testClientSideEncryption(stdClass $test, ?array $runOn, array $data, ?stdClass $encryptedFields = null, ?array $keyVaultData = null, ?stdClass $jsonSchema = null, ?string $databaseName = null, ?string $collectionName = null): void { if (isset(self::$incompleteTests[$this->dataDescription()])) { @@ -270,8 +273,8 @@ public static function provideTests() * Prose test 2: Data Key and Double Encryption * * @see https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#data-key-and-double-encryption - * @dataProvider dataKeyProvider */ + #[DataProvider('dataKeyProvider')] public function testDataKeyAndDoubleEncryption(string $providerName, $masterKey): void { $client = static::createTestClient(); @@ -409,9 +412,9 @@ public static function dataKeyProvider() * Prose test 3: External Key Vault * * @see https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#external-key-vault-test - * @testWith [false] - * [true] */ + #[TestWith([false])] + #[TestWith([true])] public function testExternalKeyVault($withExternalKeyVault): void { $client = static::createTestClient(); @@ -557,8 +560,8 @@ static function (self $test, Collection $collection, array $document): void { * Prose test 4: BSON Size Limits and Batch Splitting * * @see https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#bson-size-limits-and-batch-splitting - * @dataProvider provideBSONSizeLimitsAndBatchSplittingTests */ + #[DataProvider('provideBSONSizeLimitsAndBatchSplittingTests')] public function testBSONSizeLimitsAndBatchSplitting(Closure $test): void { $client = static::createTestClient(); @@ -623,9 +626,9 @@ public function testViewsAreProhibited(): void * Prose test 6: BSON Corpus * * @see https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#corpus-test - * @testWith [true] - * [false] */ + #[TestWith([true])] + #[TestWith([false])] public function testCorpus($schemaMap = true): void { $client = static::createTestClient(); @@ -732,8 +735,8 @@ public function testCorpus($schemaMap = true): void * Prose test 7: Custom Endpoint * * @see https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#custom-endpoint-test - * @dataProvider customEndpointProvider */ + #[DataProvider('customEndpointProvider')] public function testCustomEndpoint(Closure $test): void { $client = static::createTestClient(); @@ -1103,8 +1106,8 @@ public function testInvalidHostnameInKmsCertificate(): void * Prose test 11: KMS TLS Options * * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.rst#kms-tls-options-tests - * @dataProvider provideKmsTlsOptionsTests */ + #[DataProvider('provideKmsTlsOptionsTests')] public function testKmsTlsOptions(Closure $test): void { $client = static::createTestClient(); @@ -1321,8 +1324,8 @@ static function (self $test, ClientEncryption $clientEncryptionNoClientCert, Cli * Prose test 12: Explicit Encryption * * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.rst#explicit-encryption - * @dataProvider provideExplicitEncryptionTests */ + #[DataProvider('provideExplicitEncryptionTests')] public function testExplicitEncryption(Closure $test): void { if ($this->isStandalone()) { @@ -1500,8 +1503,8 @@ static function (self $test, ClientEncryption $clientEncryption, Client $encrypt * Prose test 13: Unique Index on keyAltNames * * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.rst#unique-index-on-keyaltnames - * @dataProvider provideUniqueIndexOnKeyAltNamesTests */ + #[DataProvider('provideUniqueIndexOnKeyAltNamesTests')] public function testUniqueIndexOnKeyAltNames(Closure $test): void { // Test setup @@ -1587,8 +1590,8 @@ static function (self $test, Client $client, ClientEncryption $clientEncryption) * Prose test 14: Decryption Events * * @see https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#decryption-events - * @dataProvider provideDecryptionEventsTests */ + #[DataProvider('provideDecryptionEventsTests')] public function testDecryptionEvents(Closure $test): void { // Test setup @@ -1736,10 +1739,10 @@ static function (self $test, Client $setupClient, ClientEncryption $clientEncryp * Prose test 15: On-demand AWS Credentials * * @see https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#on-demand-aws-credentials - * @group csfle-without-aws-creds - * @testWith [true] - * [false] */ + #[TestWith([true])] + #[TestWith([false])] + #[Group('csfle-without-aws-creds')] public function testOnDemandAwsCredentials(bool $shouldSucceed): void { $hasCredentials = (getenv('AWS_ACCESS_KEY_ID') && getenv('AWS_SECRET_ACCESS_KEY')); @@ -1779,8 +1782,8 @@ public function testOnDemandAwsCredentials(bool $shouldSucceed): void * Prose test 16: RewrapManyDataKey * * @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.rst#rewrap - * @dataProvider provideRewrapManyDataKeySrcAndDstProviders */ + #[DataProvider('provideRewrapManyDataKeySrcAndDstProviders')] public function testRewrapManyDataKey(string $srcProvider, string $dstProvider): void { $providerMasterKeys = [ diff --git a/tests/SpecTests/DocumentsMatchConstraint.php b/tests/SpecTests/DocumentsMatchConstraint.php index e8d4d0de0..82f4885d0 100644 --- a/tests/SpecTests/DocumentsMatchConstraint.php +++ b/tests/SpecTests/DocumentsMatchConstraint.php @@ -12,6 +12,7 @@ use RuntimeException; use SebastianBergmann\Comparator\ComparisonFailure; use SebastianBergmann\Comparator\Factory; +use SebastianBergmann\Exporter\Exporter; use stdClass; use function array_values; @@ -80,12 +81,12 @@ public function evaluate($other, string $description = '', bool $returnResult = $this->assertEquals($this->value, $other, $this->ignoreExtraKeysInRoot); $success = true; } catch (RuntimeException $e) { + $exporter = new Exporter(); $this->lastFailure = new ComparisonFailure( $this->value, $other, - $this->exporter()->export($this->value), - $this->exporter()->export($other), - false, + $exporter->export($this->value), + $exporter->export($other), $e->getMessage(), ); } @@ -123,7 +124,7 @@ private function assertEquals(ArrayObject $expected, ArrayObject $actual, bool $ if ($expected::class !== $actual::class) { throw new RuntimeException(sprintf( '%s is not instance of expected class "%s"', - $this->exporter()->shortenedExport($actual), + (new Exporter())->shortenedExport($actual), $expected::class, )); } @@ -162,11 +163,10 @@ private function assertEquals(ArrayObject $expected, ArrayObject $actual, bool $ $actualValue, '', '', - false, sprintf( 'Field path "%s": %s is not instance of expected type "%s".', $keyPrefix . $key, - $this->exporter()->shortenedExport($actualValue), + (new Exporter())->shortenedExport($actualValue), $expectedType, ), ); @@ -180,7 +180,6 @@ private function assertEquals(ArrayObject $expected, ArrayObject $actual, bool $ $actualValue, '', '', - false, sprintf('Field path "%s": %s', $keyPrefix . $key, $failure->getMessage()), ); } @@ -233,7 +232,7 @@ protected function matches($other): bool public function toString(): string { - return 'matches ' . $this->exporter()->export($this->value); + return 'matches ' . (new Exporter())->export($this->value); } private static function isNumeric($value): bool diff --git a/tests/SpecTests/DocumentsMatchConstraintTest.php b/tests/SpecTests/DocumentsMatchConstraintTest.php index 283d05fe8..f410591bf 100644 --- a/tests/SpecTests/DocumentsMatchConstraintTest.php +++ b/tests/SpecTests/DocumentsMatchConstraintTest.php @@ -16,6 +16,7 @@ use MongoDB\Model\BSONArray; use MongoDB\Model\BSONDocument; use MongoDB\Tests\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use const PHP_INT_SIZE; @@ -70,7 +71,7 @@ public function testIgnoreExtraKeysInEmbedded(): void $this->assertResult(false, $c, [1, ['a' => 2]], 'Keys must have the correct value'); } - /** @dataProvider provideBSONTypes */ + #[DataProvider('provideBSONTypes')] public function testBSONTypeAssertions($type, $value): void { $constraint = new DocumentsMatchConstraint(['x' => ['$$type' => $type]]); @@ -132,7 +133,7 @@ public function testBSONTypeAssertionsWithMultipleTypes(): void $this->assertResult(false, $c2, ['x' => true], 'bool is not number or string'); } - /** @dataProvider errorMessageProvider */ + #[DataProvider('errorMessageProvider')] public function testErrorMessages($expectedMessagePart, DocumentsMatchConstraint $constraint, $actualValue): void { try { diff --git a/tests/SpecTests/RetryableWrites/Prose3_ReturnOriginalErrorTest.php b/tests/SpecTests/RetryableWrites/Prose3_ReturnOriginalErrorTest.php index 7e573fc8c..06c35c825 100644 --- a/tests/SpecTests/RetryableWrites/Prose3_ReturnOriginalErrorTest.php +++ b/tests/SpecTests/RetryableWrites/Prose3_ReturnOriginalErrorTest.php @@ -8,13 +8,14 @@ use MongoDB\Driver\Monitoring\CommandSubscriber; use MongoDB\Driver\Monitoring\CommandSucceededEvent; use MongoDB\Tests\SpecTests\FunctionalTestCase; +use PHPUnit\Framework\Attributes\Group; /** * Prose test 3: Return Original Error * * @see https://github.com/mongodb/specifications/blob/master/source/retryable-writes/tests/README.md - * @group serverless */ +#[Group('serverless')] class Prose3_ReturnOriginalErrorTest extends FunctionalTestCase { public const NOT_WRITABLE_PRIMARY = 10107; diff --git a/tests/SpecTests/SearchIndexSpecTest.php b/tests/SpecTests/SearchIndexSpecTest.php index d5ed619ef..31a8a85a6 100644 --- a/tests/SpecTests/SearchIndexSpecTest.php +++ b/tests/SpecTests/SearchIndexSpecTest.php @@ -6,6 +6,7 @@ use MongoDB\Collection; use MongoDB\Model\CachingIterator; use MongoDB\Tests\FunctionalTestCase; +use PHPUnit\Framework\Attributes\Group; use function bin2hex; use function count; @@ -19,8 +20,8 @@ * Functional tests for the Atlas Search index management. * * @see https://github.com/mongodb/specifications/blob/master/source/index-management/tests/README.rst#search-index-management-helpers - * @group atlas */ +#[Group('atlas')] class SearchIndexSpecTest extends FunctionalTestCase { private const WAIT_TIMEOUT_SEC = 300; diff --git a/tests/TestCase.php b/tests/TestCase.php index 07f8219ed..c8c7db09d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,8 +6,6 @@ use MongoDB\BSON\Document; use MongoDB\BSON\PackedArray; use MongoDB\Codec\Codec; -use MongoDB\Codec\DecodeIfSupported; -use MongoDB\Codec\EncodeIfSupported; use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadPreference; use MongoDB\Driver\WriteConcern; @@ -161,13 +159,18 @@ final public static function provideInvalidStringValues(): array return self::wrapValuesForDataProvider(self::getInvalidStringValues()); } - protected function assertDeprecated(callable $execution) + protected function assertDeprecated(callable $execution): mixed + { + return $this->assertError(E_USER_DEPRECATED | E_DEPRECATED, $execution); + } + + protected function assertError(int $levels, callable $execution): mixed { $errors = []; set_error_handler(function ($errno, $errstr) use (&$errors): void { $errors[] = $errstr; - }, E_USER_DEPRECATED | E_DEPRECATED); + }, $levels); try { $result = call_user_func($execution); @@ -205,7 +208,7 @@ protected function getCollectionName(): string { $class = new ReflectionClass($this); - return sprintf('%s.%s', $class->getShortName(), hash('crc32b', $this->getName())); + return sprintf('%s.%s', $class->getShortName(), hash('xxh3', $this->name())); } /** @@ -239,34 +242,7 @@ protected static function getInvalidObjectValues(bool $includeNull = false): arr protected static function getInvalidDocumentCodecValues(): array { - $codec = new class implements Codec { - use DecodeIfSupported; - use EncodeIfSupported; - - public function canDecode(mixed $value): bool - { - return true; - } - - public function decode(mixed $value): mixed - { - return $value; - } - - public function canEncode(mixed $value): bool - { - return true; - } - - public function encode(mixed $value): mixed - { - return $value; - } - }; - // @fixme: createStub can be called statically in PHPUnit 10 - // $codec = self::createStub(Codec::class); - - return [123, 3.14, 'foo', true, [], new stdClass(), $codec]; + return [123, 3.14, 'foo', true, [], new stdClass(), self::createStub(Codec::class)]; } /** diff --git a/tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php b/tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php index 248a989b3..dd3c6e3e3 100644 --- a/tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php +++ b/tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php @@ -17,6 +17,7 @@ use MongoDB\Model\BSONArray; use MongoDB\Model\BSONDocument; use MongoDB\Tests\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\ExpectationFailedException; use stdClass; @@ -27,7 +28,7 @@ class IsBsonTypeTest extends TestCase { - /** @dataProvider provideTypes */ + #[DataProvider('provideTypes')] public function testConstraint($type, $value): void { $this->assertResult(true, new IsBsonType($type), $value, $this->dataName() . ' is ' . $type); @@ -76,7 +77,7 @@ public static function provideTypes() ]; } - /** @dataProvider provideTypes */ + #[DataProvider('provideTypes')] public function testAny($type, $value): void { $this->assertResult(true, IsBsonType::any(), $value, $this->dataName() . ' is a BSON type'); diff --git a/tests/UnifiedSpecTests/Constraint/Matches.php b/tests/UnifiedSpecTests/Constraint/Matches.php index 4346b6dc8..e1b659a3e 100644 --- a/tests/UnifiedSpecTests/Constraint/Matches.php +++ b/tests/UnifiedSpecTests/Constraint/Matches.php @@ -13,6 +13,7 @@ use RuntimeException; use SebastianBergmann\Comparator\ComparisonFailure; use SebastianBergmann\Comparator\Factory; +use SebastianBergmann\Exporter\Exporter; use function array_keys; use function count; @@ -82,14 +83,14 @@ public function evaluate($other, $description = '', $returnResult = false): ?boo } catch (RuntimeException $e) { /* This will generally catch internal errors from failAt(), which * include a key path to pinpoint the failure. */ + $exporter = new Exporter(); $this->lastFailure = new ComparisonFailure( $this->value, $other, /* TODO: Improve the exporter to canonicalize documents by * sorting keys and remove spl_object_hash from output. */ - $this->exporter()->export($this->value), - $this->exporter()->export($other), - false, + $exporter->export($this->value), + $exporter->export($other), $e->getMessage(), ); } @@ -256,7 +257,7 @@ private function assertMatchesOperator(BSONDocument $operator, $actual, string $ $constraint = IsBsonType::anyOf(...(array) $operator['$$type']); if (! $constraint->evaluate($actual, '', true)) { - self::failAt(sprintf('%s is not an expected BSON type: %s', $this->exporter()->shortenedExport($actual), implode(', ', $types)), $keyPath); + self::failAt(sprintf('%s is not an expected BSON type: %s', (new Exporter())->shortenedExport($actual), implode(', ', (array) $operator['$$type'])), $keyPath); } return; @@ -284,7 +285,7 @@ private function assertMatchesOperator(BSONDocument $operator, $actual, string $ assertIsString($actual); if ($actual !== hex2bin($operator['$$matchesHexBytes'])) { - self::failAt(sprintf('%s does not match expected hex bytes: %s', $this->exporter()->shortenedExport($actual), $operator['$$matchesHexBytes']), $keyPath); + self::failAt(sprintf('%s does not match expected hex bytes: %s', (new Exporter())->shortenedExport($actual), $operator['$$matchesHexBytes']), $keyPath); } return; @@ -349,7 +350,7 @@ protected function matches($other): bool public function toString(): string { - return 'matches ' . $this->exporter()->export($this->value); + return 'matches ' . (new Exporter())->export($this->value); } /** @psalm-return never-return */ diff --git a/tests/UnifiedSpecTests/Constraint/MatchesTest.php b/tests/UnifiedSpecTests/Constraint/MatchesTest.php index 472fdd1d1..0de7aa9cb 100644 --- a/tests/UnifiedSpecTests/Constraint/MatchesTest.php +++ b/tests/UnifiedSpecTests/Constraint/MatchesTest.php @@ -5,6 +5,7 @@ use MongoDB\BSON\Binary; use MongoDB\Tests\FunctionalTestCase; use MongoDB\Tests\UnifiedSpecTests\EntityMap; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use stdClass; @@ -170,7 +171,7 @@ public function testOperatorSessionLsid(): void $this->assertResult(false, $c, ['x' => 1], 'session LSID does not match (embedded)'); } - /** @dataProvider errorMessageProvider */ + #[DataProvider('errorMessageProvider')] public function testErrorMessages($expectedMessageRegex, Matches $constraint, $actualValue): void { try { @@ -253,7 +254,7 @@ public static function errorMessageProvider() ]; } - /** @dataProvider operatorErrorMessageProvider */ + #[DataProvider('operatorErrorMessageProvider')] public function testOperatorSyntaxValidation($expectedMessage, Matches $constraint): void { $this->expectException(ExpectationFailedException::class); diff --git a/tests/UnifiedSpecTests/UnifiedSpecTest.php b/tests/UnifiedSpecTests/UnifiedSpecTest.php index 6b6031948..f34696be3 100644 --- a/tests/UnifiedSpecTests/UnifiedSpecTest.php +++ b/tests/UnifiedSpecTests/UnifiedSpecTest.php @@ -5,6 +5,8 @@ use Exception; use Generator; use MongoDB\Tests\FunctionalTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\SkippedTest; use PHPUnit\Framework\Warning; @@ -221,10 +223,8 @@ public function setUp(): void } } - /** - * @dataProvider provideAtlasDataLakeTests - * @group atlas-data-lake - */ + #[DataProvider('provideAtlasDataLakeTests')] + #[Group('atlas-data-lake')] public function testAtlasDataLake(UnifiedTestCase $test): void { if (! $this->isAtlasDataLake()) { @@ -239,10 +239,8 @@ public static function provideAtlasDataLakeTests(): Generator return self::provideTests(__DIR__ . '/atlas-data-lake/*.json'); } - /** - * @dataProvider provideChangeStreamsTests - * @group serverless - */ + #[DataProvider('provideChangeStreamsTests')] + #[Group('serverless')] public function testChangeStreams(UnifiedTestCase $test): void { self::$runner->run($test); @@ -253,11 +251,9 @@ public static function provideChangeStreamsTests(): Generator return self::provideTests(__DIR__ . '/change-streams/*.json'); } - /** - * @dataProvider provideClientSideEncryptionTests - * @group csfle - * @group serverless - */ + #[DataProvider('provideClientSideEncryptionTests')] + #[Group('csfle')] + #[Group('serverless')] public function testClientSideEncryption(UnifiedTestCase $test): void { self::$runner->run($test); @@ -268,10 +264,8 @@ public static function provideClientSideEncryptionTests(): Generator return self::provideTests(__DIR__ . '/client-side-encryption/*.json'); } - /** - * @dataProvider provideCollectionManagementTests - * @group serverless - */ + #[DataProvider('provideCollectionManagementTests')] + #[Group('serverless')] public function testCollectionManagement(UnifiedTestCase $test): void { self::$runner->run($test); @@ -282,10 +276,8 @@ public static function provideCollectionManagementTests(): Generator return self::provideTests(__DIR__ . '/collection-management/*.json'); } - /** - * @dataProvider provideCommandMonitoringTests - * @group serverless - */ + #[DataProvider('provideCommandMonitoringTests')] + #[Group('serverless')] public function testCommandMonitoring(UnifiedTestCase $test): void { self::$runner->run($test); @@ -296,10 +288,8 @@ public static function provideCommandMonitoringTests(): Generator return self::provideTests(__DIR__ . '/command-monitoring/*.json'); } - /** - * @dataProvider provideCrudTests - * @group serverless - */ + #[DataProvider('provideCrudTests')] + #[Group('serverless')] public function testCrud(UnifiedTestCase $test): void { self::$runner->run($test); @@ -310,10 +300,8 @@ public static function provideCrudTests(): Generator return self::provideTests(__DIR__ . '/crud/*.json'); } - /** - * @dataProvider provideGridFSTests - * @group serverless - */ + #[DataProvider('provideGridFSTests')] + #[Group('serverless')] public function testGridFS(UnifiedTestCase $test): void { self::$runner->run($test); @@ -324,10 +312,8 @@ public static function provideGridFSTests(): Generator return self::provideTests(__DIR__ . '/gridfs/*.json'); } - /** - * @dataProvider provideLoadBalancers - * @group serverless - */ + #[DataProvider('provideLoadBalancers')] + #[Group('serverless')] public function testLoadBalancers(UnifiedTestCase $test): void { self::$runner->run($test); @@ -338,7 +324,7 @@ public static function provideLoadBalancers(): Generator return self::provideTests(__DIR__ . '/load-balancers/*.json'); } - /** @dataProvider provideReadWriteConcernTests */ + #[DataProvider('provideReadWriteConcernTests')] public function testReadWriteConcern(UnifiedTestCase $test): void { self::$runner->run($test); @@ -349,10 +335,8 @@ public static function provideReadWriteConcernTests(): Generator return self::provideTests(__DIR__ . '/read-write-concern/*.json'); } - /** - * @dataProvider provideRetryableReadsTests - * @group serverless - */ + #[DataProvider('provideRetryableReadsTests')] + #[Group('serverless')] public function testRetryableReads(UnifiedTestCase $test): void { self::$runner->run($test); @@ -363,10 +347,8 @@ public static function provideRetryableReadsTests(): Generator return self::provideTests(__DIR__ . '/retryable-reads/*.json'); } - /** - * @dataProvider provideRetryableWritesTests - * @group serverless - */ + #[DataProvider('provideRetryableWritesTests')] + #[Group('serverless')] public function testRetryableWrites(UnifiedTestCase $test): void { self::$runner->run($test); @@ -377,10 +359,8 @@ public static function provideRetryableWritesTests(): Generator return self::provideTests(__DIR__ . '/retryable-writes/*.json'); } - /** - * @dataProvider provideRunCommandTests - * @group serverless - */ + #[DataProvider('provideRunCommandTests')] + #[Group('serverless')] public function testRunCommand(UnifiedTestCase $test): void { self::$runner->run($test); @@ -391,10 +371,8 @@ public static function provideRunCommandTests(): Generator return self::provideTests(__DIR__ . '/run-command/*.json'); } - /** - * @dataProvider provideSessionsTests - * @group serverless - */ + #[DataProvider('provideSessionsTests')] + #[Group('serverless')] public function testSessions(UnifiedTestCase $test): void { self::$runner->run($test); @@ -405,10 +383,8 @@ public static function provideSessionsTests(): Generator return self::provideTests(__DIR__ . '/sessions/*.json'); } - /** - * @dataProvider provideTransactionsTests - * @group serverless - */ + #[DataProvider('provideTransactionsTests')] + #[Group('serverless')] public function testTransactions(UnifiedTestCase $test): void { self::$runner->run($test); @@ -419,7 +395,7 @@ public static function provideTransactionsTests(): Generator return self::provideTests(__DIR__ . '/transactions/*.json'); } - /** @dataProvider provideTransactionsConvenientApiTests */ + #[DataProvider('provideTransactionsConvenientApiTests')] public function testTransactionsConvenientApi(UnifiedTestCase $test): void { self::$runner->run($test); @@ -430,11 +406,9 @@ public static function provideTransactionsConvenientApiTests(): Generator return self::provideTests(__DIR__ . '/transactions-convenient-api/*.json'); } - /** - * @dataProvider provideVersionedApiTests - * @group serverless - * @group versioned-api - */ + #[DataProvider('provideVersionedApiTests')] + #[Group('serverless')] + #[Group('versioned-api')] public function testVersionedApi(UnifiedTestCase $test): void { self::$runner->run($test); @@ -445,7 +419,7 @@ public static function provideVersionedApiTests(): Generator return self::provideTests(__DIR__ . '/versioned-api/*.json'); } - /** @dataProvider providePassingTests */ + #[DataProvider('providePassingTests')] public function testPassingTests(UnifiedTestCase $test): void { self::$runner->run($test); @@ -456,7 +430,7 @@ public static function providePassingTests(): Generator yield from self::provideTests(__DIR__ . '/valid-pass/*.json'); } - /** @dataProvider provideFailingTests */ + #[DataProvider('provideFailingTests')] public function testFailingTests(UnifiedTestCase $test): void { // Cannot use expectException(), as it ignores PHPUnit Exceptions @@ -494,7 +468,7 @@ public static function provideFailingTests(): Generator yield from self::provideTests(__DIR__ . '/valid-fail/*.json'); } - /** @dataProvider provideIndexManagementTests */ + #[DataProvider('provideIndexManagementTests')] public function testIndexManagement(UnifiedTestCase $test): void { if (self::isAtlas()) {