Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
using CodeCeption Stub helper #5210
I've already opened a post in the forums but didn't have a single reply, so I'm posting it here hoping someone could enlighten me.
tl;dr; I've used PHPUnit
As an example: I've implemented some tests for the
I've then tried to create a stub of the security component using Composer
$security = Stub::construct( 'yii\base\Security', [ 'validatePassword' => true, 'generatePasswordHash' => $expectedPassword ] ); Yii::$app->set('security', $security);
but if I run the tests containing such call I get the following exception
(almost) the same logic done with PHPUnit
$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);
I'm quite new to CodeCeption and I've been following its documentation and guides to use it fully as I do appreciate some of the syntactic sugar they've added to testing.
I also have to add that CodeCeption documentation on this topic is not exceptionally clear :)
The correct code is:
$security = Stub::construct( 'yii\base\Security', [], // __construct expects one parameter, an array [ 'validatePassword' => true, 'generatePasswordHash' => 'aaaaa', ] );
However, you will then run into #1694
So it's not fixable because it's not an issue as it stands now?
Not a problem at all as long as PHPUnit works fine, but a pity as it would have been interesting to begin with :)
Thanks @Ragazzo very useful to know.
If that's correct, I can only second what @DavertMik said. Although the Stub class addresses some complexity issues on the use of PHPUnit, on the other hand it might introduce some undesired side-effects both on the use and on scope of CodeCeption itself (e.g. keeping it lightweight, simple and modular).