I tried to figure out how to use Stubs/Mocks in Cest tests. I assume that the only way to do this is to use the stub trait. So I tried this:
namespace app\tests\unit\base;
use Codeception\Stub\Expected;
use app\models\Session;
class DataPersisterCest
{
use \Codeception\Test\Feature\Stub;
public function canGetAndSetSessionProperty($I)
{
// Doesn't work
$sessionStorage = $this->make(Session::class);
// Doesn't work
$sessionStorage = $this->make(Session::class, [
'get' => Expected::never(),
'set' => Expected::never(),
]);
// ...
}
}
It always throws an error like this:
1) DataPersisterCest: Construct
Test tests/unit/base/DataPersisterCest.php:construct
[ArgumentCountError] Too few arguments to function Codeception\Actor::__construct(), 0 passed in /usr/local/include/codecept/phpunit/phpunit/src/Framework/MockObject/Generator.php on line 532 and exactly 1 expected
#1 /usr/local/include/codecept/phpunit/phpunit/src/Framework/MockObject/Generator.php:532
#2 /usr/local/include/codecept/phpunit/phpunit/src/Framework/MockObject/Generator.php:170
#3 PHPUnit\Framework\MockObject\Generator->getMock
#4 /usr/local/include/codecept/codeception/stub/src/Stub.php:527
#5 /usr/local/include/codecept/codeception/stub/src/Stub.php:494
#6 /usr/local/include/codecept/codeception/stub/src/Stub.php:341
#7 /usr/local/include/codecept/codeception/stub/src/Test/Feature/Stub.php:217
#8 app\tests\unit\base\DataPersisterCest->construct
#9 /usr/local/include/codecept/phpunit/phpunit/src/Framework/TestSuite.php:568
#10 /usr/local/include/codecept/codeception/phpunit-wrapper/src/Runner.php:117
Unfortunately the documentation is very unclear. An example there would really help.
I tried to figure out how to use Stubs/Mocks in Cest tests. I assume that the only way to do this is to use the stub trait. So I tried this:
It always throws an error like this:
Unfortunately the documentation is very unclear. An example there would really help.