Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
basheerOct opened this issue Aug 5, 2019 · 1 comment
Open

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

basheerOct opened this issue Aug 5, 2019 · 1 comment

Comments

@basheerOct
Copy link

basheerOct commented Aug 5, 2019

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants