Skip to content

Commit

Permalink
Add missing test for nullable properties (could add more)
Browse files Browse the repository at this point in the history
  • Loading branch information
edudobay committed Jan 8, 2022
1 parent 6059ceb commit 1e85d46
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
18 changes: 18 additions & 0 deletions tests/Entities/EntityTwo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Edudobay\DoctrineSerializable\Tests\Entities;

use Edudobay\DoctrineSerializable\Attributes\Serializable;

class EntityTwo
{
public function __construct(
#[Serializable]
public ?string $name
) {
}

public ?string $_name;
}
16 changes: 14 additions & 2 deletions tests/SerializationHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,23 @@ public function test_can_deserialize_JSON_string_instead_of_array(): void
self::assertEquals(new Entities\User('mickey42', 'Mickey Mouse'), $e->user);
}

public function test_nullable_attributes(): void
// TODO: What else can we verify about nullable properties?
public function test_null_property_is_serialized_to_PHP_null(): void
{
self::markTestIncomplete('TODO');
// 1. Set a non-null value
$e = new Entities\EntityTwo(name: 'pencil');
$this->handler()->serialize($e);
self::assertSame('pencil', $e->_name);

// 2. Set a null value
$e->name = null;

$this->handler()->serialize($e);

self::assertNull($e->_name);
}


private function handler(): SerializationHandler
{
return new SerializationHandler(
Expand Down

0 comments on commit 1e85d46

Please sign in to comment.