Codeception / Codeception/AspectMock

Class 'yii\base\UnknownClassException' not found

Open
#173 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
784
Forks
132
PR merge metrics
No merged PRs in 30d

Description

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](https://www.screencast.com/t/1suVpY4O1bj)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the autoload method in BaseYii.php and reproduce the reported AspectMock unit-testing case shown in the linked test snapshot. Trace why UnknownClassException cannot be found even though the tests pass; done means the reported autoload failure is resolved without regressing the existing passing tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.