Skip to content

Commit

Permalink
Merge pull request #480: test: add json tests for empty array and null
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored May 9, 2024
2 parents 7253fa4 + 27d1dbd commit 47ffcf4
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/ORM/Functional/Driver/Common/Typecast/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,64 @@ public function testStore(): void
$this->assertSame(['some' => 'data'], $result->settingsNullable);
}

public function testStoresEmptyArraySettings(): void
{
$e = new User();
$e->email = 'test@email.com';
$e->settings = [];
$e->settingsNullable = [];

$this->captureWriteQueries();
$this-save($e);
$this->assertNumWrites(1);

$this->captureWriteQueries();
$this-save($e)
$this->assertNumWrites(0);

$this->assertEquals(3, $e->id);

$this->assertTrue($this->orm->getHeap()->has($e));
$this->assertSame(Node::MANAGED, $this->orm->getHeap()->get($e)->getStatus());

$this->orm = $this->orm->getHeap()->clear();

$selector = new Select($this->orm, User::class);
$result = $selector->where('id', 3)->fetchOne();
$this->assertSame('test@email.com', $result->email);
$this->assertSame([], $result->settings);
$this->assertSame([], $result->settingsNullable);
}

public function testStoresNullSettings(): void
{
$e = new User();
$e->email = 'test@email.com';
$e->settings = [];
$e->settingsNullable = null;

$this->captureWriteQueries();
$this-save($e)
$this->assertNumWrites(1);

$this->captureWriteQueries();
$this-save($e)
$this->assertNumWrites(0);

$this->assertEquals(3, $e->id);

$this->assertTrue($this->orm->getHeap()->has($e));
$this->assertSame(Node::MANAGED, $this->orm->getHeap()->get($e)->getStatus());

$this->orm = $this->orm->with(heap: new Heap());

$selector = new Select($this->orm, User::class);
$result = $selector->where('id', 3)->fetchOne();
$this->assertSame('test@email.com', $result->email);
$this->assertSame([], $result->settings);
$this->assertSame(null, $result->settingsNullable);
}

public function testStoreJsonSerializable(): void
{
$e = new User();
Expand Down

0 comments on commit 47ffcf4

Please sign in to comment.