Skip to content

Commit

Permalink
TOML support
Browse files Browse the repository at this point in the history
  • Loading branch information
vanodevium authored and Crell committed Sep 6, 2024
1 parent 0e008b3 commit 4496504
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions tests/TomlFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

namespace Crell\Serde;

use Crell\Serde\Records\AllFieldTypes;
use Devium\Toml\Toml;
use Crell\Serde\Formatter\TomlFormatter;
use Devium\Toml\TomlError;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use stdClass;
Expand Down Expand Up @@ -56,6 +54,16 @@ public function setUp(): void
]);
}

#[Test, DataProvider('strict_mode_throws_examples')]
public function strict_mode_throws_correct_exception(mixed $serialized, string $errorField, string $expectedType, string $foundType): void
{
if ($expectedType === 'float' && $foundType === 'string') {
$this->markTestSkipped("it's normal for TOML");
}

parent::strict_mode_throws_correct_exception($serialized, $errorField, $expectedType, $foundType);
}

#[Test, DataProvider('round_trip_examples')]
public function round_trip(object $data, string $name): void
{
Expand Down Expand Up @@ -122,23 +130,4 @@ public static function strict_mode_throws_examples(): iterable
yield $k => $v;
}
}

#[Test, DataProvider('strict_mode_throws_examples')]
public function strict_mode_throws_correct_exception(mixed $serialized, string $errorField, string $expectedType, string $foundType): void
{
if ($expectedType === 'float' && $foundType === 'string') {
$this->markTestSkipped("it's normal for TOML");
}

$s = new SerdeCommon();

try {
$s->deserialize($serialized, from: $this->format, to: AllFieldTypes::class);
$this->fail('No exception was generated.');
} catch (TypeMismatch $e) {
self::assertEquals($errorField, $e->name);
self::assertEquals($expectedType, $e->expectedType);
self::assertEquals($foundType, $e->foundType);
}
}
}

0 comments on commit 4496504

Please sign in to comment.