1

我正在尝试将方面模拟与代码接收测试一起使用。

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

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]);
}

and when I run test

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

I get message

==== 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

Can you explain me how to configure this?

Also I saw in readme

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

but test is not even found. So I tried to use \AspectMock\Test which is at least found.

Notice that the error is throw before even running my test function. When I tried running before class declaration

$kernel->init();

it already gives same error.

4

1 回答 1

1

_bootstrap.php files are no longer created automatically by Codeception. To enabled them you have to add

settings:
    bootstrap: _bootstrap.php

to codeception.yml file and manually create _bootstrap.php files in tests directory and in every suite.

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

ReflectionFile issue looks like autoloading issue.

于 2017-09-19T10:57:54.740 回答