Skip to content

Commit

Permalink
refactor: Migrated to DataProvider attribute (PHPUnit).
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru committed Mar 22, 2024
1 parent e40a945 commit dbe4013
Show file tree
Hide file tree
Showing 116 changed files with 301 additions and 418 deletions.
7 changes: 3 additions & 4 deletions packages/core/src/Helpers/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use LastDragon_ru\LaraASP\Core\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\Testing\Utils\WithTranslations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @internal
Expand All @@ -20,12 +21,11 @@ final class TranslatorTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderChoice
*
* @param list<string>|string $key
* @param TranslationsFactory $translations
* @param array<string, mixed> $replace
*/
#[DataProvider('dataProviderChoice')]
public function testChoice(
string $expected,
mixed $translations,
Expand All @@ -45,12 +45,11 @@ public function testChoice(
}

/**
* @dataProvider dataProviderGet
*
* @param list<string>|string $key
* @param TranslationsFactory $translations
* @param array<string, mixed> $replace
*/
#[DataProvider('dataProviderGet')]
public function testGet(
string $expected,
mixed $translations,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Utils/ConfigMergerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use InvalidArgumentException;
use LastDragon_ru\LaraASP\Core\Testing\Package\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use stdClass;

/**
Expand All @@ -16,12 +17,11 @@ final class ConfigMergerTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderMerge
*
* @param array<array-key, mixed>|Exception $expected
* @param array<array-key, mixed> $target
* @param array<array-key, mixed> $configs
*/
#[DataProvider('dataProviderMerge')]
public function testMerge(
array|Exception $expected,
array $target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\TargetIsNotValidPhpFile;
use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

use function str_replace;

Expand All @@ -17,9 +18,7 @@
final class InstructionTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderProcess
*/
#[DataProvider('dataProviderProcess')]
public function testProcess(Exception|string $expected, string $file, Parameters $params): void {
$file = self::getTestData()->file($file);
$instance = Container::getInstance()->make(Instruction::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use LastDragon_ru\LaraASP\Documentator\Preprocessor\Exceptions\PackageReadmeIsMissing;
use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

use function basename;

Expand All @@ -18,9 +19,7 @@
final class InstructionTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderProcess
*/
#[DataProvider('dataProviderProcess')]
public function testProcess(string $expected, string $template): void {
$path = self::getTestData()->file('Document.md')->getPathname();
$target = basename(self::getTestData()->path('/packages'));
Expand Down
9 changes: 3 additions & 6 deletions packages/documentator/src/Utils/ArtisanSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Parser;
use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

Expand All @@ -17,9 +18,7 @@
final class ArtisanSerializerTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderGetArgumentSignature
*/
#[DataProvider('dataProviderGetArgumentSignature')]
public function testGetArgumentSignature(string $signature): void {
$parsed = Parser::parse("command {{$signature}}")[1] ?? [];
$argument = reset($parsed);
Expand All @@ -28,9 +27,7 @@ public function testGetArgumentSignature(string $signature): void {
self::assertEquals($signature, (new ArtisanSerializer())->getArgumentSignature($argument));
}

/**
* @dataProvider dataProviderGetOptionSignature
*/
#[DataProvider('dataProviderGetOptionSignature')]
public function testGetOptionSignature(string $signature): void {
$parsed = Parser::parse("command {{$signature}}")[2] ?? [];
$option = reset($parsed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Mockery;
use Override;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

use function count;
use function iterator_to_array;
Expand Down Expand Up @@ -82,9 +83,7 @@ public function testGetIterator(): void {
->times(2);
}

/**
* @dataProvider dataProviderGetIteratorColumn
*/
#[DataProvider('dataProviderGetIteratorColumn')]
public function testGetIteratorDefaults(string $column): void {
TestObject::factory()->create(['value' => '1']);
TestObject::factory()->create(['value' => '2']);
Expand All @@ -101,9 +100,7 @@ public function testGetIteratorDefaults(string $column): void {
self::assertEquals($expected, $actual);
}

/**
* @dataProvider dataProviderGetIteratorColumn
*/
#[DataProvider('dataProviderGetIteratorColumn')]
public function testGetIteratorEloquentDefaults(string $column): void {
TestObject::factory()->create(['value' => '1']);
TestObject::factory()->create(['value' => '2']);
Expand All @@ -127,10 +124,9 @@ public function testGetIteratorUnion(): void {
}

/**
* @dataProvider dataProviderGetDefaultColumn
*
* @param Closure(): Builder<Model> $factory
*/
#[DataProvider('dataProviderGetDefaultColumn')]
public function testGetDefaultColumn(string $expected, Closure $factory): void {
$iterator = new class() extends ChunkedChangeSafeIterator {
/** @noinspection PhpMissingParentConstructorInspection */
Expand Down
5 changes: 2 additions & 3 deletions packages/eloquent/src/Iterators/IteratorImplTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Mockery;
use Override;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @internal
Expand All @@ -17,9 +18,7 @@
final class IteratorImplTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderCount
*/
#[DataProvider('dataProviderCount')]
public function testCount(int $expected, ?int $limit, int $count): void {
$query = Mockery::mock(QueryBuilder::class);
$query
Expand Down
10 changes: 4 additions & 6 deletions packages/eloquent/src/ModelHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use LastDragon_ru\LaraASP\Testing\Providers\CompositeDataProvider;
use LastDragon_ru\LaraASP\Testing\Providers\UnknownValue;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use stdClass;

use function is_string;
Expand All @@ -27,11 +28,10 @@ final class ModelHelperTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderGetRelation
*
* @param Exception|class-string $expected
* @param Closure(): (Builder<Model>|Model|class-string<Model>) $model
*/
#[DataProvider('dataProviderGetRelation')]
public function testGetRelation(Exception|string $expected, Closure $model, string $name): void {
if ($expected instanceof Exception) {
self::expectExceptionObject($expected);
Expand All @@ -45,11 +45,10 @@ public function testGetRelation(Exception|string $expected, Closure $model, stri
}

/**
* @dataProvider dataProviderGetRelation
*
* @param Exception|class-string $expected
* @param Closure(): (Builder<Model>|Model|class-string<Model>) $model
*/
#[DataProvider('dataProviderGetRelation')]
public function testIsRelation(Exception|string $expected, Closure $model, string $name): void {
$actual = (new ModelHelper($model()))->isRelation($name);
$expected = !($expected instanceof Exception);
Expand All @@ -58,10 +57,9 @@ public function testIsRelation(Exception|string $expected, Closure $model, strin
}

/**
* @dataProvider dataProviderIsSoftDeletable
*
* @param Closure(): (Builder<Model>|Model|class-string<Model>) $model
*/
#[DataProvider('dataProviderIsSoftDeletable')]
public function testIsSoftDeletable(bool $expected, Closure $model): void {
$actual = (new ModelHelper($model()))->isSoftDeletable();

Expand Down
9 changes: 3 additions & 6 deletions packages/formatter/src/Utils/DurationFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DateTime;
use LastDragon_ru\LaraASP\Formatter\Testing\Package\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @internal
Expand All @@ -14,16 +15,12 @@
final class DurationFormatterTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderGetTimestamp
*/
#[DataProvider('dataProviderGetTimestamp')]
public function testGetTimestamp(float $expected, DateInterval $interval): void {
self::assertEquals($expected, DurationFormatter::getTimestamp($interval));
}

/**
* @dataProvider dataProviderFormat
*/
#[DataProvider('dataProviderFormat')]
public function testFormat(string $expected, string $format, float|int $duration): void {
$formatter = new DurationFormatter($format);
$actual = $formatter->format($duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use LastDragon_ru\LaraASP\Formatter\Testing\Package\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

use function array_map;
use function iterator_to_array;
Expand All @@ -16,10 +17,9 @@ final class UnicodeDateTimeFormatParserTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderGetIterator
*
* @param array<array-key, array{string, string}> $expected
*/
#[DataProvider('dataProviderGetIterator')]
public function testGetIterator(array $expected, string $format): void {
$actual = iterator_to_array(new UnicodeDateTimeFormatParser($format));
$actual = array_map(static fn (UnicodeDateTimeFormatToken $token) => [$token->pattern, $token->value], $actual);
Expand Down
5 changes: 2 additions & 3 deletions packages/graphql-printer/src/Blocks/Document/ArgumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use LastDragon_ru\LaraASP\GraphQLPrinter\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\GraphQLPrinter\Testing\TestSettings;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @internal
Expand All @@ -21,9 +22,7 @@
final class ArgumentTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderSerialize
*/
#[DataProvider('dataProviderSerialize')]
public function testSerialize(
string $expected,
Settings $settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use LastDragon_ru\LaraASP\GraphQLPrinter\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\GraphQLPrinter\Testing\TestSettings;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @internal
Expand All @@ -25,9 +26,7 @@
final class DirectiveDefinitionTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderSerialize
*/
#[DataProvider('dataProviderSerialize')]
public function testSerialize(
string $expected,
Settings $settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use LastDragon_ru\LaraASP\GraphQLPrinter\Testing\TestSettings;
use Override;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @internal
Expand All @@ -26,9 +27,7 @@
final class DirectiveTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderSerialize
*/
#[DataProvider('dataProviderSerialize')]
public function testSerialize(
string $expected,
Settings $settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use LastDragon_ru\LaraASP\GraphQLPrinter\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\GraphQLPrinter\Testing\TestSettings;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @internal
Expand All @@ -20,10 +21,9 @@ final class DirectivesTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderSerialize
*
* @param list<DirectiveNode> $directives
*/
#[DataProvider('dataProviderSerialize')]
public function testSerialize(
string $expected,
Settings $settings,
Expand Down
5 changes: 2 additions & 3 deletions packages/graphql-printer/src/Blocks/Document/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use LastDragon_ru\LaraASP\GraphQLPrinter\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\GraphQLPrinter\Testing\TestSettings;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @internal
Expand All @@ -20,9 +21,7 @@
final class DocumentTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderSerialize
*/
#[DataProvider('dataProviderSerialize')]
public function testSerialize(
string $expected,
Settings $settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use LastDragon_ru\LaraASP\GraphQLPrinter\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\GraphQLPrinter\Testing\TestSettings;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @internal
Expand All @@ -20,9 +21,7 @@
final class EnumTypeDefinitionTest extends TestCase {
// <editor-fold desc="Tests">
// =========================================================================
/**
* @dataProvider dataProviderSerialize
*/
#[DataProvider('dataProviderSerialize')]
public function testSerialize(
string $expected,
Settings $settings,
Expand Down
Loading

0 comments on commit dbe4013

Please sign in to comment.