AspectMock test::double 在 Yii2 测试中不起作用
AspectMock test::double doesn't work in Yii2 tests
当我尝试像这样模拟任何东西时:
Test::double(MyService::class, [
'accept' => true
]);
它抛出错误:
Call to a member function registerClass() on null
我在互联网上找不到任何可以帮助我解决这个问题的东西。有什么想法吗?
编辑
更进一步。我必须用以下内容更新 Test/_bootstrap.php:
$kernel = Kernel::getInstance();
$kernel->init([
'debug' => true,
'includePaths' => [__DIR__ . '/../service/'],
'excludePaths' => [__DIR__],
'cacheDir' => '/tmp/aopcache',
]);
它仍然不起作用,但至少没有抛出错误。知道如何让 AspectMock 真正模拟东西吗?
解决方案
我明白了。在你的 test/_bootstrap.php 你必须在配置内核后加载 yii:
$kernel->loadFile(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
这可以关闭。
我明白了。在你的 test/_bootstrap.php 中,你必须在配置内核后加载 yii:
$kernel->loadFile(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
当我尝试像这样模拟任何东西时:
Test::double(MyService::class, [
'accept' => true
]);
它抛出错误:
Call to a member function registerClass() on null
我在互联网上找不到任何可以帮助我解决这个问题的东西。有什么想法吗?
编辑 更进一步。我必须用以下内容更新 Test/_bootstrap.php:
$kernel = Kernel::getInstance();
$kernel->init([
'debug' => true,
'includePaths' => [__DIR__ . '/../service/'],
'excludePaths' => [__DIR__],
'cacheDir' => '/tmp/aopcache',
]);
它仍然不起作用,但至少没有抛出错误。知道如何让 AspectMock 真正模拟东西吗?
解决方案
我明白了。在你的 test/_bootstrap.php 你必须在配置内核后加载 yii:
$kernel->loadFile(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
这可以关闭。
我明白了。在你的 test/_bootstrap.php 中,你必须在配置内核后加载 yii:
$kernel->loadFile(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');