Skip to content

Commit

Permalink
Fix PHPUnit/PHPCS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtyler committed Nov 18, 2024
1 parent dddb91a commit 9538cce
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
5 changes: 4 additions & 1 deletion tests/Fixtures/DataFalse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

class DataFalse
{
public false $data;

public function __construct(
public false $data
false $data
) {
$this->data = $data;
}
}
6 changes: 6 additions & 0 deletions tests/Fixtures/DataTrue.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
class DataTrue
{
public true $data;

public function __construct(
true $data
) {
$this->data = $data;
}
}
32 changes: 27 additions & 5 deletions tests/Serializer/JsonSerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use JMS\Serializer\Tests\Fixtures\Author;
use JMS\Serializer\Tests\Fixtures\AuthorList;
use JMS\Serializer\Tests\Fixtures\DataFalse;
use JMS\Serializer\Tests\Fixtures\DataTrue;
use JMS\Serializer\Tests\Fixtures\DiscriminatedAuthor;
use JMS\Serializer\Tests\Fixtures\DiscriminatedComment;
use JMS\Serializer\Tests\Fixtures\FirstClassMapCollection;
Expand All @@ -28,6 +29,7 @@
use JMS\Serializer\Visitor\Factory\JsonSerializationVisitorFactory;
use JMS\Serializer\Visitor\SerializationVisitorInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use TypeError;

class JsonSerializationTest extends BaseSerializationTestCase
{
Expand Down Expand Up @@ -483,10 +485,33 @@ public function testSerializingUnionProperties()
self::assertEquals(static::getContent('data_string'), $serialized);
}

public function testTrueDataType()
{
if (PHP_VERSION_ID < 80200) {
$this->markTestSkipped('True type requires PHP 8.2');

return;
}

self::assertEquals(
static::getContent('data_true'),
$this->serialize(new DataTrue(true)),
);

self::assertEquals(
new DataTrue(true),
$this->deserialize(static::getContent('data_true'), DataTrue::class),
);

$this->expectException(TypeError::class);
$this->deserialize(static::getContent('data_false'), DataTrue::class);
}

public function testFalseDataType()
{
if (PHP_VERSION_ID < 80200) {
$this->markTestSkipped('False type requires PHP 8.2');

return;
}

Expand All @@ -500,11 +525,8 @@ public function testFalseDataType()
$this->deserialize(static::getContent('data_false'), DataFalse::class),
);

//What should we expect here?
self::assertEquals(
null,
$this->deserialize(static::getContent('data_true'), DataFalse::class),
);
$this->expectException(TypeError::class);
$this->deserialize(static::getContent('data_true'), DataFalse::class);
}

public function testDeserializingComplexDiscriminatedUnionProperties()
Expand Down

0 comments on commit 9538cce

Please sign in to comment.