Skip to content

Commit

Permalink
Convert PHPUnit annotations to attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crell committed Sep 23, 2023
1 parent d200833 commit 70d5c3a
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 217 deletions.
13 changes: 4 additions & 9 deletions tests/ArrayBasedFormatterTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Crell\Serde\Records\MappedCollected\ThingC;
use Crell\Serde\Records\Point;
use Crell\Serde\Records\Shapes\Circle;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;

abstract class ArrayBasedFormatterTests extends SerdeTests
{
Expand Down Expand Up @@ -283,10 +285,7 @@ public function root_typemap_validate(mixed $serialized): void
self::assertEquals(4, $toTest['bottomRight']['y']);
}

/**
* @test
* @dataProvider non_strict_properties_examples()
*/
#[Test, DataProvider('non_strict_properties_examples')]
public function non_strict_mode_casts_values(mixed $serialized, object $expected): void
{
$s = new SerdeCommon();
Expand Down Expand Up @@ -331,11 +330,7 @@ public static function non_strict_properties_examples_data(): iterable
];
}


/**
* @test
* @dataProvider strict_mode_throws_examples
*/
#[Test, DataProvider('strict_mode_throws_examples')]
public function strict_mode_throws_correct_exception(mixed $serialized, string $errorField, string $expectedType, string $foundType): void
{
$s = new SerdeCommon();
Expand Down
4 changes: 1 addition & 3 deletions tests/ArrayFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ protected function arrayify(mixed $serialized): array
return $serialized;
}

/**
* @test
*/
#[Test]
public function literal_enums(): void
{
$s = new SerdeCommon(handlers: [new EnumOnArrayImporter()], formatters: $this->formatters);
Expand Down
6 changes: 3 additions & 3 deletions tests/CasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
namespace Crell\Serde;

use Crell\Serde\Renaming\Cases;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class CasesTest extends TestCase
{
/**
* @test
* @dataProvider caseExamples
*
* @param Cases $case
* @param string $in
* @param string $expected
*/
#[Test, DataProvider('caseExamples')]
public function caseFold(Cases $case, string $in, string $expected): void
{
self::assertEquals($expected, $case->convert($in));
Expand Down
7 changes: 3 additions & 4 deletions tests/CsvFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
use Crell\Serde\Records\CsvTableLazy;
use Crell\Serde\Records\Point;
use Crell\Serde\Records\PointList;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class CsvFormatterTest extends TestCase
{
/**
* @test
* @dataProvider csvExamples()
*/
#[Test, DataProvider('csvExamples')]
public function csv_serialize(object $data, ?object $expected = null): void
{
$s = new SerdeCommon(formatters: [new CsvFormatter()]);
Expand Down
7 changes: 3 additions & 4 deletions tests/CsvStreamFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
use Crell\Serde\Records\CsvTableLazy;
use Crell\Serde\Records\Point;
use Crell\Serde\Records\PointList;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class CsvStreamFormatterTest extends TestCase
{
/**
* @test
* @dataProvider csvExamples()
*/
#[Test, DataProvider('csvExamples')]
public function csv_serialize(object $data, ?object $expected = null): void
{
$s = new SerdeCommon(formatters: [new CsvStreamFormatter(), new CsvFormatter()]);
Expand Down
10 changes: 4 additions & 6 deletions tests/DictionaryFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
namespace Crell\Serde;

use Crell\Serde\Attributes\DictionaryField;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class DictionaryFieldTest extends TestCase
{
/**
* @test
* @dataProvider implosionExamples
*
* @param array<string, string> $in
*/
#[Test, DataProvider('implosionExamples')]
public function implosion(string $implodeOn, string $joinOn, array $in, string $expected): void
{
$d = new DictionaryField(
Expand Down Expand Up @@ -50,11 +50,9 @@ public static function implosionExamples(): iterable
}

/**
* @test
* @dataProvider explosionExamples
*
* @param array<string, string> $expected
*/
#[Test, DataProvider('explosionExamples')]
public function explosion(string $implodeOn, string $joinOn, string $in, array $expected): void
{
$d = new DictionaryField(
Expand Down
7 changes: 3 additions & 4 deletions tests/FieldValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
use Crell\Serde\Attributes\DictionaryField;
use Crell\Serde\Attributes\Field;
use Crell\Serde\Attributes\SequenceField;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class FieldValidationTest extends TestCase
{
/**
* @test
* @dataProvider fieldValidationExamples()
*/
#[Test, DataProvider('fieldValidationExamples')]
public function fields_validate_their_types(string $phpType, mixed $value, ?TypeField $typeField, bool $expected): void
{
$f = Field::create('fake', phpType: $phpType, typeField: $typeField);
Expand Down
11 changes: 4 additions & 7 deletions tests/JsonStreamFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
use Crell\Serde\Records\Point;
use Crell\Serde\Records\Size;
use Crell\Serde\Records\Visibility;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class JsonStreamFormatterTest extends TestCase
{
/**
* @test
* @dataProvider streamExamples()
*/
#[Test, DataProvider('streamExamples')]
public function stream_serialize(object $data): void
{
$s = new SerdeCommon(formatters: [new JsonStreamFormatter()]);
Expand Down Expand Up @@ -160,9 +159,7 @@ public static function streamExamples(): iterable
];
}

/**
* @test
*/
#[Test]
public function object_with_generator_streams_cleanly(): void
{
$s = new SerdeCommon(formatters: [new JsonStreamFormatter()]);
Expand Down
6 changes: 3 additions & 3 deletions tests/SequenceFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
namespace Crell\Serde;

use Crell\Serde\Attributes\SequenceField;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class SequenceFieldTest extends TestCase
{

/**
* @test
* @dataProvider explodeExamples
*
* @param string[] $expected
*/
#[Test, DataProvider('explodeExamples')]
public function explode(string $implodeOn, string $in, array $expected): void
{
$s = new SequenceField(implodeOn: $implodeOn);
Expand Down
Loading

0 comments on commit 70d5c3a

Please sign in to comment.