Codeception / AspectMock

The most powerful and flexible mocking framework for PHPUnit / Codeception.
MIT License
790 stars 129 forks source link

Class 'yii\base\UnknownClassException' not found #173

Open basheerOct opened 5 years ago

basheerOct commented 5 years ago

While using AspectMock for unit testing, the autoload method in BaseYii.php can not find the following class:

Class 'yii\base\UnknownClassException' not found

However tests are passing successfully.

public static function autoload($className)
    {
        if (isset(static::$classMap[$className])) {
            $classFile = static::$classMap[$className];
            if ($classFile[0] === '@') {
                $classFile = static::getAlias($classFile);
            }
        } elseif (strpos($className, '\\') !== false) {
            $classFile = static::getAlias('@' . str_replace('\\', '/', $className) . '.php', false);
            if ($classFile === false || !is_file($classFile)) {
                return;
            }
        } else {
            return;
        }

        include $classFile;

        if (YII_DEBUG && !class_exists($className, false) && !interface_exists($className, false) && !trait_exists($className, false)) {
            throw new UnknownClassException("Unable to find '$className' in file: $classFile. Namespace missing?"); // <---
        }
    }

Test snapshot

lionsoftware commented 5 years ago

To solve this use:

$kernel->loadFile(YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php'); // <- this is exist line $kernel->loadFile(YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/base/ErrorException.php'); // <-- Required to add $kernel->loadFile(YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/base/UnknownClassException.php'); // <-- Required to add