Skip to content

Commit

Permalink
Use PHPUnit's Attributes instead of annotation (#3035)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Jul 9, 2024
1 parent 9431912 commit f6ee9cc
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 27 deletions.
3 changes: 2 additions & 1 deletion tests/Casts/BinaryUuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use MongoDB\BSON\Binary;
use MongoDB\Laravel\Tests\Models\Casting;
use MongoDB\Laravel\Tests\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

use function hex2bin;

Expand All @@ -20,7 +21,7 @@ protected function setUp(): void
Casting::truncate();
}

/** @dataProvider provideBinaryUuidCast */
#[DataProvider('provideBinaryUuidCast')]
public function testBinaryUuidCastModel(string $expectedUuid, string|Binary $saveUuid, Binary $queryUuid): void
{
Casting::create(['uuid' => $saveUuid]);
Expand Down
3 changes: 2 additions & 1 deletion tests/Casts/ObjectIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use MongoDB\BSON\ObjectId;
use MongoDB\Laravel\Tests\Models\CastObjectId;
use MongoDB\Laravel\Tests\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class ObjectIdTest extends TestCase
{
Expand All @@ -18,7 +19,7 @@ protected function setUp(): void
CastObjectId::truncate();
}

/** @dataProvider provideObjectIdCast */
#[DataProvider('provideObjectIdCast')]
public function testStoreObjectId(string|ObjectId $saveObjectId, ObjectId $queryObjectId): void
{
$stringObjectId = (string) $saveObjectId;
Expand Down
3 changes: 2 additions & 1 deletion tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use MongoDB\Laravel\Connection;
use MongoDB\Laravel\Query\Builder;
use MongoDB\Laravel\Schema\Builder as SchemaBuilder;
use PHPUnit\Framework\Attributes\DataProvider;

use function env;
use function spl_object_hash;
Expand Down Expand Up @@ -186,7 +187,7 @@ public static function dataConnectionConfig(): Generator
];
}

/** @dataProvider dataConnectionConfig */
#[DataProvider('dataConnectionConfig')]
public function testConnectionConfig(string $expectedUri, string $expectedDatabaseName, array $config): void
{
$connection = new Connection($config);
Expand Down
5 changes: 3 additions & 2 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use MongoDB\Laravel\Tests\Models\Soft;
use MongoDB\Laravel\Tests\Models\SqlUser;
use MongoDB\Laravel\Tests\Models\User;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestWith;

use function abs;
Expand Down Expand Up @@ -370,7 +371,7 @@ public function testSoftDelete(): void
$this->assertEquals(2, Soft::count());
}

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

/** @dataProvider provideDate */
#[DataProvider('provideDate')]
public function testDateInputs($date): void
{
// Test with create and standard property
Expand Down
7 changes: 4 additions & 3 deletions tests/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use MongoDB\Laravel\Query\Builder;
use MongoDB\Laravel\Query\Grammar;
use MongoDB\Laravel\Query\Processor;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use stdClass;

Expand All @@ -29,7 +30,7 @@

class BuilderTest extends TestCase
{
/** @dataProvider provideQueryBuilderToMql */
#[DataProvider('provideQueryBuilderToMql')]
public function testMql(array $expected, Closure $build): void
{
$builder = $build(self::getBuilder());
Expand Down Expand Up @@ -1298,7 +1299,7 @@ function (Builder $elemMatchQuery): void {
}
}

/** @dataProvider provideExceptions */
#[DataProvider('provideExceptions')]
public function testException($class, $message, Closure $build): void
{
$builder = self::getBuilder();
Expand Down Expand Up @@ -1396,7 +1397,7 @@ public static function provideExceptions(): iterable
];
}

/** @dataProvider getEloquentMethodsNotSupported */
#[DataProvider('getEloquentMethodsNotSupported')]
public function testEloquentMethodsNotSupported(Closure $callback)
{
$builder = self::getBuilder();
Expand Down
7 changes: 3 additions & 4 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use MongoDB\Laravel\Tests\Models\Birthday;
use MongoDB\Laravel\Tests\Models\Scoped;
use MongoDB\Laravel\Tests\Models\User;
use PHPUnit\Framework\Attributes\TestWith;

use function str;

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

/**
* @testWith [0]
* [2]
*/
#[TestWith([0])]
#[TestWith([2])]
public function testDeleteException(int $limit): void
{
$this->expectException(LogicException::class);
Expand Down
7 changes: 1 addition & 6 deletions tests/Seeder/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@

class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
public function run(): void
{
$this->call(UserTableSeeder::class);
}
Expand Down
12 changes: 3 additions & 9 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ class TestCase extends OrchestraTestCase
* Get application providers.
*
* @param Application $app
*
* @return array
*/
protected function getApplicationProviders($app)
protected function getApplicationProviders($app): array
{
$providers = parent::getApplicationProviders($app);

Expand All @@ -37,10 +35,8 @@ protected function getApplicationProviders($app)
* Get package providers.
*
* @param Application $app
*
* @return array
*/
protected function getPackageProviders($app)
protected function getPackageProviders($app): array
{
return [
MongoDBServiceProvider::class,
Expand All @@ -54,10 +50,8 @@ protected function getPackageProviders($app)
* Define environment setup.
*
* @param Application $app
*
* @return void
*/
protected function getEnvironmentSetUp($app)
protected function getEnvironmentSetUp($app): void
{
// reset base path to point to our package's src directory
//$app['path.base'] = __DIR__ . '/../src';
Expand Down

0 comments on commit f6ee9cc

Please sign in to comment.