I am trying to use aspect mock with codeception tests.
From their documentation it is not clear how to configure.
https://github.com/Codeception/AspectMock
Include AspectMock\Kernel into tests/_bootstrap.php.
I do not have such file. Should I create it? Where should I include it?
My directory structure of codeception is:
test/codeception/acceptance.
I have file SummaryCest.php in test/codeception/acceptance.
Since I do not have _bootstrap.php file, I decided to try in SummaryCest - before declaring a class:
include __DIR__.'/../../../vendor/autoload.php'; // composer autoload
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
'debug' => true,
'includePaths' => [__DIR__.'/../../../'],
'excludePaths' => [__DIR__.'../../../vendor'],
'cacheDir' => '/tmp/datamanager',
]);
I do not know do I really need to exclude vendor directory, but I saw such suggestions. If that is mandatory, it should be written probably in readme which I did not see.
In includePaths there should be visible all my project files.
I have function in 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.
_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.