Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more test for Entity : 100% tested #2798

Merged
merged 1 commit into from
Apr 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions tests/system/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ public function testCastNullable()
$this->assertSame('', $entity->string_empty);
$this->assertSame(null, $entity->integer_null);
$this->assertSame(0, $entity->integer_0);
$this->assertSame('value', $entity->string_value_not_null);
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -566,6 +567,23 @@ public function testAsArrayMapped()
]);
}

public function testToArraySkipAttributesWithUnderscoreInFirstCharacter()
{
$entity = new class extends Entity
{
protected $attributes = [
'_foo' => null,
'bar' => null,
];
};

$result = $entity->toArray();

$this->assertEquals($result, [
'bar' => null,
]);
}

public function testAsArrayOnlyChanged()
{
$entity = $this->getEntity();
Expand Down Expand Up @@ -674,6 +692,12 @@ public function testHasChangedWholeEntity()
$this->assertTrue($entity->hasChanged());
}

public function testHasChangedKeyNotExists()
{
$entity = $this->getEntity();
$this->assertFalse($entity->hasChanged('xxx'));
}

public function testIssetKeyMap()
{
$entity = $this->getEntity();
Expand Down Expand Up @@ -824,24 +848,27 @@ protected function getCastNullableEntity()
return new class extends Entity
{
protected $attributes = [
'string_null' => null,
'string_empty' => null,
'integer_null' => null,
'integer_0' => null,
'string_null' => null,
'string_empty' => null,
'integer_null' => null,
'integer_0' => null,
'string_value_not_null' => 'value',
];
protected $_original = [
'string_null' => null,
'string_empty' => null,
'integer_null' => null,
'integer_0' => null,
'string_null' => null,
'string_empty' => null,
'integer_null' => null,
'integer_0' => null,
'string_value_not_null' => 'value',
];

// 'bar' is db column, 'foo' is internal representation
protected $casts = [
'string_null' => '?string',
'string_empty' => 'string',
'integer_null' => '?integer',
'integer_0' => 'integer',
'string_null' => '?string',
'string_empty' => 'string',
'integer_null' => '?integer',
'integer_0' => 'integer',
'string_value_not_null' => '?string',
];
};
}
Expand Down