After generating a test with the command
php codecept.phar generate:test unit Issue
the running
php codecept.phar run
fails with the error
Fatal error: Class 'frontend\UnitTester' not found in phar://.../codecept.phar/src/Codeception/TestCase/Test.php on line 26
FATAL ERROR. TESTS NOT FINISHED.
Class 'frontend\UnitTester' not found in phar://.../codecept.phar/src/Codeception/TestCase/Test.php:26
Actually, the error above should read
Class 'frontend\UnitTester' not found
This is not related to issue #2163. The generated code looks like this
namespace frontend;
class IssueTest extends \Codeception\TestCase\Test
{
/**
* @var frontend\UnitTester
*/
protected $tester;
...
}
Even after changing the annotation to@var \frontend\UnitTesterI get this error:
Trying to test me (IssueTest::testMe)...
Fatal error: Class 'frontend\UnitTester' not found in phar:///.../codecept.phar/src/Codeception/TestCase/Test.php on line 26
FATAL ERROR. TESTS NOT FINISHED.
Class 'frontend\UnitTester' not found
in phar://.../build/codecept.phar/src/Codeception/TestCase/Test.php:26
Did you try to run codecept build before executing tests?
Does frontend\Unit class exist in tests/_support directory?
Running
php codecept.phar build
producesBuilding Actor classes for suites: acceptance, functional, unit -> AcceptanceTesterActions.php generated successfully. 0 methods added frontend\\AcceptanceTester includes modules: PhpBrowser, \frontend\Helper\Acceptance -> FunctionalTesterActions.php generated successfully. 0 methods added frontend\\FunctionalTester includes modules: \frontend\Helper\Functional -> UnitTesterActions.php generated successfully. 0 methods added frontend\\UnitTester includes modules: Asserts, \frontend\Helper\Unitsame error though
Fatal error: Class 'frontend\UnitTester'
with this annotation:* @var \frontend\UnitTester
There is no frontend\Unit class exist in tests/_support but there is a UnitTester.php:
<?php
namespace frontend;
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}
Same issue, has found any fix?
I get a fix by replacing '\' with '\' on TestCase\Cest.php line 110.
$className = '\\' . $this->actor;
$className = str_replace('\\\\', '\\', $className);
Off course it's a bad code.
Also change Generator\Cest.php:
$ns .= "use $namespace\$actor;";
Where it will be done into repository?
Try
composer dump-autoload
composer clear-cache
composer install
it works for me. I didn't have all dependencies and I got the same errors.
Most helpful comment
Try
composer dump-autoload
composer clear-cache
composer install
it works for me. I didn't have all dependencies and I got the same errors.