-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add json tests for empty array and null
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,72 @@ public function testStore(): void | |
$this->assertSame(['some' => 'data'], $result->settingsNullable); | ||
} | ||
|
||
public function testStoresEmptyArraySettings(): void | ||
{ | ||
$e = new User(); | ||
$e->email = '[email protected]'; | ||
$e->settings = []; | ||
$e->settingsNullable = []; | ||
|
||
$this->captureWriteQueries(); | ||
$em = new EntityManager($this->orm); | ||
$em->persist($e); | ||
$em->run(); | ||
$this->assertNumWrites(1); | ||
|
||
$this->captureWriteQueries(); | ||
$em = new EntityManager($this->orm); | ||
$em->persist($e); | ||
$em->run(); | ||
$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('[email protected]', $result->email); | ||
$this->assertSame([], $result->settings); | ||
$this->assertSame([], $result->settingsNullable); | ||
} | ||
|
||
public function testStoresNullSettings(): void | ||
{ | ||
$e = new User(); | ||
$e->email = '[email protected]'; | ||
$e->settings = []; | ||
$e->settingsNullable = null; | ||
|
||
$this->captureWriteQueries(); | ||
$em = new EntityManager($this->orm); | ||
$em->persist($e); | ||
$em->run(); | ||
$this->assertNumWrites(1); | ||
|
||
$this->captureWriteQueries(); | ||
$em = new EntityManager($this->orm); | ||
$em->persist($e); | ||
$em->run(); | ||
$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('[email protected]', $result->email); | ||
$this->assertSame([], $result->settings); | ||
$this->assertSame(null, $result->settingsNullable); | ||
} | ||
|
||
public function testStoreJsonSerializable(): void | ||
{ | ||
$e = new User(); | ||
|