Codeception: Class not found when generating Test tests

Created on 15 Jul 2015  路  7Comments  路  Source: Codeception/Codeception

Codeception 2.1.1

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

Generators

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.

All 7 comments

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\UnitTester

I 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
produces

Building 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\Unit

same 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.

Was this page helpful?
0 / 5 - 0 ratings