-
Notifications
You must be signed in to change notification settings - Fork 2
Description
In many tests i have come across situations like this:
$I->haveInRepository(User::class, [
'name' => 'Jane',
'email' => '[email protected]',
'password' => '123456',
'enabled' => true
]);
$user = $I->grabEntityFromRepository(User::class, [
'email' => '[email protected]'
]);
// do assertions with the $user
Use haveInRepository
, and then be forced to use grabEntityFromRepository
to get the entity i just persisted. If i want to check that an entity listener is working, for example, i always have to execute those two statements.
My point is that this would be more useful:
$user = $I->haveInRepository(User::class, [
'name' => 'Jane',
'email' => '[email protected]',
'password' => '123456',
'enabled' => true
]);
// do assertions with the $user
if i wanted to know the primary key of that entity, i would simply write:
$user->getId();
In this context, the ORM is useful for its ability to abstract the details of the persistence process and leave it to me as a programmer to worry more about the data i am working with.
I'm not saying that getting the primary key is not useful, i am saying that it is much more useful to get the entity, where there is more information to work with in my tests, including the persistence identifier.
Please let me know your opinions about it.