Skip to content

Commit f6ee9cc

Browse files
authored
Use PHPUnit's Attributes instead of annotation (#3035)
1 parent 9431912 commit f6ee9cc

8 files changed

+20
-27
lines changed

Diff for: tests/Casts/BinaryUuidTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use MongoDB\BSON\Binary;
99
use MongoDB\Laravel\Tests\Models\Casting;
1010
use MongoDB\Laravel\Tests\TestCase;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1112

1213
use function hex2bin;
1314

@@ -20,7 +21,7 @@ protected function setUp(): void
2021
Casting::truncate();
2122
}
2223

23-
/** @dataProvider provideBinaryUuidCast */
24+
#[DataProvider('provideBinaryUuidCast')]
2425
public function testBinaryUuidCastModel(string $expectedUuid, string|Binary $saveUuid, Binary $queryUuid): void
2526
{
2627
Casting::create(['uuid' => $saveUuid]);

Diff for: tests/Casts/ObjectIdTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use MongoDB\BSON\ObjectId;
99
use MongoDB\Laravel\Tests\Models\CastObjectId;
1010
use MongoDB\Laravel\Tests\TestCase;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1112

1213
class ObjectIdTest extends TestCase
1314
{
@@ -18,7 +19,7 @@ protected function setUp(): void
1819
CastObjectId::truncate();
1920
}
2021

21-
/** @dataProvider provideObjectIdCast */
22+
#[DataProvider('provideObjectIdCast')]
2223
public function testStoreObjectId(string|ObjectId $saveObjectId, ObjectId $queryObjectId): void
2324
{
2425
$stringObjectId = (string) $saveObjectId;

Diff for: tests/ConnectionTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use MongoDB\Laravel\Connection;
1515
use MongoDB\Laravel\Query\Builder;
1616
use MongoDB\Laravel\Schema\Builder as SchemaBuilder;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1718

1819
use function env;
1920
use function spl_object_hash;
@@ -186,7 +187,7 @@ public static function dataConnectionConfig(): Generator
186187
];
187188
}
188189

189-
/** @dataProvider dataConnectionConfig */
190+
#[DataProvider('dataConnectionConfig')]
190191
public function testConnectionConfig(string $expectedUri, string $expectedDatabaseName, array $config): void
191192
{
192193
$connection = new Connection($config);

Diff for: tests/ModelTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use MongoDB\Laravel\Tests\Models\Soft;
2929
use MongoDB\Laravel\Tests\Models\SqlUser;
3030
use MongoDB\Laravel\Tests\Models\User;
31+
use PHPUnit\Framework\Attributes\DataProvider;
3132
use PHPUnit\Framework\Attributes\TestWith;
3233

3334
use function abs;
@@ -370,7 +371,7 @@ public function testSoftDelete(): void
370371
$this->assertEquals(2, Soft::count());
371372
}
372373

373-
/** @dataProvider provideId */
374+
#[DataProvider('provideId')]
374375
public function testPrimaryKey(string $model, $id, $expected, bool $expectedFound): void
375376
{
376377
$model::truncate();
@@ -755,7 +756,7 @@ public static function provideDate(): Generator
755756
yield 'DateTime date, time and ms before unix epoch' => [new DateTime('1965-08-08 04.08.37.324')];
756757
}
757758

758-
/** @dataProvider provideDate */
759+
#[DataProvider('provideDate')]
759760
public function testDateInputs($date): void
760761
{
761762
// Test with create and standard property

Diff for: tests/Query/BuilderTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use MongoDB\Laravel\Query\Builder;
2020
use MongoDB\Laravel\Query\Grammar;
2121
use MongoDB\Laravel\Query\Processor;
22+
use PHPUnit\Framework\Attributes\DataProvider;
2223
use PHPUnit\Framework\TestCase;
2324
use stdClass;
2425

@@ -29,7 +30,7 @@
2930

3031
class BuilderTest extends TestCase
3132
{
32-
/** @dataProvider provideQueryBuilderToMql */
33+
#[DataProvider('provideQueryBuilderToMql')]
3334
public function testMql(array $expected, Closure $build): void
3435
{
3536
$builder = $build(self::getBuilder());
@@ -1298,7 +1299,7 @@ function (Builder $elemMatchQuery): void {
12981299
}
12991300
}
13001301

1301-
/** @dataProvider provideExceptions */
1302+
#[DataProvider('provideExceptions')]
13021303
public function testException($class, $message, Closure $build): void
13031304
{
13041305
$builder = self::getBuilder();
@@ -1396,7 +1397,7 @@ public static function provideExceptions(): iterable
13961397
];
13971398
}
13981399

1399-
/** @dataProvider getEloquentMethodsNotSupported */
1400+
#[DataProvider('getEloquentMethodsNotSupported')]
14001401
public function testEloquentMethodsNotSupported(Closure $callback)
14011402
{
14021403
$builder = self::getBuilder();

Diff for: tests/QueryTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use MongoDB\Laravel\Tests\Models\Birthday;
1313
use MongoDB\Laravel\Tests\Models\Scoped;
1414
use MongoDB\Laravel\Tests\Models\User;
15+
use PHPUnit\Framework\Attributes\TestWith;
1516

1617
use function str;
1718

@@ -662,10 +663,8 @@ public function testDelete(): void
662663
$this->assertEquals(0, User::count());
663664
}
664665

665-
/**
666-
* @testWith [0]
667-
* [2]
668-
*/
666+
#[TestWith([0])]
667+
#[TestWith([2])]
669668
public function testDeleteException(int $limit): void
670669
{
671670
$this->expectException(LogicException::class);

Diff for: tests/Seeder/DatabaseSeeder.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88

99
class DatabaseSeeder extends Seeder
1010
{
11-
/**
12-
* Run the database seeds.
13-
*
14-
* @return void
15-
*/
16-
public function run()
11+
public function run(): void
1712
{
1813
$this->call(UserTableSeeder::class);
1914
}

Diff for: tests/TestCase.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ class TestCase extends OrchestraTestCase
2121
* Get application providers.
2222
*
2323
* @param Application $app
24-
*
25-
* @return array
2624
*/
27-
protected function getApplicationProviders($app)
25+
protected function getApplicationProviders($app): array
2826
{
2927
$providers = parent::getApplicationProviders($app);
3028

@@ -37,10 +35,8 @@ protected function getApplicationProviders($app)
3735
* Get package providers.
3836
*
3937
* @param Application $app
40-
*
41-
* @return array
4238
*/
43-
protected function getPackageProviders($app)
39+
protected function getPackageProviders($app): array
4440
{
4541
return [
4642
MongoDBServiceProvider::class,
@@ -54,10 +50,8 @@ protected function getPackageProviders($app)
5450
* Define environment setup.
5551
*
5652
* @param Application $app
57-
*
58-
* @return void
5953
*/
60-
protected function getEnvironmentSetUp($app)
54+
protected function getEnvironmentSetUp($app): void
6155
{
6256
// reset base path to point to our package's src directory
6357
//$app['path.base'] = __DIR__ . '/../src';

0 commit comments

Comments
 (0)