Closed Erwane closed 1 year ago
On the unit test level, you might just want to test it this way:
public function testCanUpdate()
{
$userId = rand(1, 100);
$identityStub = $this->getMockBuilder(IdentityInterface::class)->getMock();
$identityStub->method('getIdentifier')->willReturn($userId);
$userId = (string)$identityStub->getIdentifier();
$article = ArticleFactory::make()->setField('user_id', $userId)->getEntity();
$this->assertTrue($classUnderTest->canUpdate($identityStub, $article));
}
On the integration side of testing however, you want to have the entities persisted anyway.
Generally I do not think that involving IDs in the getEntity()
method is a good idea, nor necessary.
Hi, How to test this, without persisting data ?
My first way was to create a PR (https://github.com/vierge-noire/cakephp-fixture-factories/pull/192) to add a method to get entity with primary keys sets.
I known the answer could be something like
But, this is more in the same way of persist writing
Thanks