Skip to content

Commit

Permalink
Add end to end tests for False types
Browse files Browse the repository at this point in the history
From `ea7f7be4cb6ca2d1ed5e156b57f1413be8936e82`, but I can't cherry-pick because it's cross-remote
  • Loading branch information
gregtyler committed Nov 18, 2024
1 parent 62f7bb4 commit dddb91a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/GraphNavigator/DeserializationGraphNavigator.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public function accept($data, ?array $type = null)

case 'bool':
case 'boolean':
case 'false':
case 'true':
return $this->visitor->visitBoolean($data, $type);

case 'double':
Expand Down
13 changes: 13 additions & 0 deletions tests/Fixtures/DataFalse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace JMS\Serializer\Tests\Fixtures;

class DataFalse
{
public function __construct(

Check failure on line 9 in tests/Fixtures/DataFalse.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (7.4)

Promoted properties are supported only on PHP 8.0 and later.
public false $data
) {
}
}
10 changes: 10 additions & 0 deletions tests/Fixtures/DataTrue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace JMS\Serializer\Tests\Fixtures;

class DataTrue
{
public true $data;
}
27 changes: 27 additions & 0 deletions tests/Serializer/JsonSerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use JMS\Serializer\SerializationContext;
use JMS\Serializer\Tests\Fixtures\Author;
use JMS\Serializer\Tests\Fixtures\AuthorList;
use JMS\Serializer\Tests\Fixtures\DataFalse;
use JMS\Serializer\Tests\Fixtures\DiscriminatedAuthor;
use JMS\Serializer\Tests\Fixtures\DiscriminatedComment;
use JMS\Serializer\Tests\Fixtures\FirstClassMapCollection;
Expand Down Expand Up @@ -151,6 +152,8 @@ protected static function getContent($key)
$outputs['data_float'] = '{"data":1.236}';
$outputs['data_bool'] = '{"data":false}';
$outputs['data_string'] = '{"data":"foo"}';
$outputs['data_true'] = '{"data":true}';
$outputs['data_false'] = '{"data":false}';
$outputs['data_author'] = '{"data":{"full_name":"foo"}}';
$outputs['data_comment'] = '{"data":{"author":{"full_name":"foo"},"text":"bar"}}';
$outputs['data_discriminated_author'] = '{"data":{"full_name":"foo","objectType":"author"}}';
Expand Down Expand Up @@ -480,6 +483,30 @@ public function testSerializingUnionProperties()
self::assertEquals(static::getContent('data_string'), $serialized);
}

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

Check failure on line 490 in tests/Serializer/JsonSerializationTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards (7.4)

Expected 1 line before "return", found 0.
}

self::assertEquals(
static::getContent('data_false'),
$this->serialize(new DataFalse(false)),
);

self::assertEquals(
new DataFalse(false),
$this->deserialize(static::getContent('data_false'), DataFalse::class),
);

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

public function testDeserializingComplexDiscriminatedUnionProperties()
{
if (PHP_VERSION_ID < 80000) {
Expand Down

0 comments on commit dddb91a

Please sign in to comment.