Hi all,
back again on testing.
I’m still stuck on a couple of things regarding unit testing.
I’m trying to see if it’s possible to use CodeCeption Stub static class.
Let’s take as an example Stubbing the security component.
What I need to do is just have the two methods validatePassword and generatePasswordHash to return what I need.
With CodeCeption it seems I should be able to do the following:
$security = Stub::construct(
'yii\base\Security',
[
'validatePassword' => true,
'generatePasswordHash' => $expectedPassword
]
);
Yii::$app->set('security', $security);
which seems to be really neat and clean.
Unfortunately this doesn’t work and throws all kind of errors.
Instead the PHPUnit classic method works flawlessly:
$security = $this->getMock(
'yii\base\Security',
['validatePassword', 'generatePasswordHash']
);
$security->expects($this->any())
->method('validatePassword')
->with($expectedPassword)
->willReturn(true);
$security->expects($this->any())
->method('generatePasswordHash')
->with($expectedPassword)
->willReturn($expectedPassword);
Any ideas here?