AspectMock icon indicating copy to clipboard operation
AspectMock copied to clipboard

Class 'yii\base\UnknownClassException' not found

Open basheerOct opened this issue 4 years ago • 1 comments

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

basheerOct avatar Aug 05 '19 06:08 basheerOct

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

lionsoftware avatar Oct 15 '19 15:10 lionsoftware