【问题标题】:Aspect mock 'Go\ParserReflection\ReflectionFile' not found未找到方面模拟“Go\ParserReflection\ReflectionFile”
【发布时间】:2018-02-28 02:25:28
【问题描述】:

我正在尝试在代码接收测试中使用方面模拟。

从他们的文档中不清楚如何配置。

https://github.com/Codeception/AspectMock

将 AspectMock\Kernel 包含到 tests/_bootstrap.php 中。

我没有这样的文件。我应该创建它吗?我应该在哪里包含它?

我的codeception目录结构是:

测试/代码接收/接受。

我在 test/codeception/acceptance 中有文件 SummaryCest.php。

由于我没有 _bootstrap.php 文件,我决定在 SummaryCest 中尝试 - 在声明一个类之前:

include __DIR__.'/../../../vendor/autoload.php'; // composer autoload

$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
    'debug' => true,
    'includePaths' => [__DIR__.'/../../../'],
    'excludePaths' => [__DIR__.'../../../vendor'],
    'cacheDir'  => '/tmp/datamanager',
]);

我不知道我真的需要排除供应商目录,但我看到了这样的建议。如果这是强制性的,它可能应该写在我没有看到的自述文件中。

在 includePaths 中应该可以看到我的所有项目文件。

我在 SummaryCest.php 中有函数

public function correctSummaryCounts(AcceptanceTester $I)
{
    \AspectMock\Test::double(SummaryController::class, ['get' => null]);
}

当我运行测试时

php codecept.phar run test/codeception/acceptance/SummaryCest.php 

我收到消息

==== Redirecting to Composer-installed version in vendor/codeception ====
Codeception PHP Testing Framework v2.3.5
Powered by PHPUnit 6.2.4 by Sebastian Bergmann and contributors.
PHP Fatal error:  Uncaught Error: Class 'Go\ParserReflection\ReflectionFile' not found in /var/www/warehouseDataManager/vendor/codeception/aspect-mock/src/AspectMock/Intercept/BeforeMockTransformer.php:16
Stack trace:
#0 /var/www/warehouseDataManager/vendor/goaop/framework/src/Instrument/Transformer/CachingTransformer.php(124): AspectMock\Intercept\BeforeMockTransformer->transform(Object(Go\Instrument\Transformer\StreamMetaData))
#1 /var/www/warehouseDataManager/vendor/goaop/framework/src/Instrument/Transformer/CachingTransformer.php(83): Go\Instrument\Transformer\CachingTransformer->processTransformers(Object(Go\Instrument\Transformer\StreamMetaData))
#2 /var/www/warehouseDataManager/vendor/goaop/framework/src/Instrument/ClassLoading/SourceTransformingLoader.php(134): Go\Instrument\Transformer\CachingTransformer->transform(Object(Go\Instrument\Transformer\StreamMetaData))
#3 /var/www/warehouseDataManager/vendor/goaop/framework/src/Instrument/ClassLoading/SourceTransformingLoader.php(101): Go\Instrument\ClassLoading\SourceTran in /var/www/warehouseDataManager/vendor/codeception/aspect-mock/src/AspectMock/Intercept/BeforeMockTransformer.php on line 16

你能解释一下如何配置吗?

我在自述文件中也看到了

$userModel = test::double('UserModel', ['tableName' => 'my_users']);

但甚至没有找到测试。所以我尝试使用至少找到的\AspectMock\Test。

请注意,甚至在运行我的测试功能之前就会抛出错误。当我尝试在类声明之前运行时

$kernel->init();

它已经给出了同样的错误。

【问题讨论】:

    标签: php codeception goaop


    【解决方案1】:

    _bootstrap.php 文件不再由 Codeception 自动创建。 要启用它们,您必须添加

    settings:
        bootstrap: _bootstrap.php
    

    到 codeception.yml 文件 并在测试目录和每个套件中手动创建 _bootstrap.php 文件。

    http://codeception.com/docs/reference/Configuration

    ReflectionFile 问题看起来像自动加载问题。

    【讨论】:

    • 有帮助吗?
    猜你喜欢
    • 2019-02-18
    • 1970-01-01
    • 2018-08-16
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    相关资源
    最近更新 更多