public function testHasManyRelationCountZero()
{
$mapper = test_spot_mapper('\SpotTest\Entity\Post');
$post = $mapper->get();
$post->title = "No Comments";
$post->body = "<p>Comments relation test</p>";
$mapper->save($post);
$this->assertSame(0, count($post->comments));
}
The $post->comments will be null and the count($post->comments) will throw an error, because the $mapper->save($post) silently fails with validation error (author_id is required).
Should someone check every save(), update(), etc. operation with $entity->hasErrors() or $result !== false or should the validation throw a ValidationError or something like that?
Should the entity validation fail silently? Is this by design? For example if I have an entity with required fields like the
author_id
:tests/Entity/Post.php
And If I do something like in tests/Relations.php
The $post->comments will be
null
and thecount($post->comments)
will throw an error, because the$mapper->save($post)
silently fails with validation error (author_id is required
).Should someone check every
save()
,update()
, etc. operation with$entity->hasErrors()
or$result !== false
or should the validation throw aValidationError
or something like that?