Darius.V Darius.V - 3 years ago 275
PHP Question

Aspect mock does not overload method in codeception

I have such files:



namespace src;

class Api {
function apiCall()
return 'api_result';



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

$kernel = \AspectMock\Kernel::getInstance();
'debug' => true,
'includePaths' => [__DIR__.'/../src'],
'cacheDir' => __DIR__ . '/aspectCache'


tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
- Codeception\Extension\RunFailed

bootstrap: _bootstrap.php


"require-dev": {
"codeception/aspect-mock": "*",
"codeception/codeception": "^2.3"

"autoload": {
"psr-4": {
"": "src/"



require_once "vendor/autoload.php";

use src\Api;

$api = new Api();
echo $api->apiCall();
echo 'test';



use AspectMock\Test as test;
use src\Api;

class FirstCest
public function frontpageWorks(AcceptanceTester $I)

test::double(Api::class, ['apiCall' => 'mock']);


When I load page in browser I see string 'api_resulttest'

Now when I mock the apiCall function, the output should be 'mocktest'.

I run command

php codecept.phar run --steps -d

And test fails, I still see the output 'api_resulttest'.

Why? And do I use it correctly? https://github.com/Codeception/AspectMock here it does not show how to use it in codeception tests.

Or please tell another way - how should I mock api calls in codeception? Thats what I want to do.

I have pushed into bitbucket so you can test the example:

Update 2017 10 01
Now removed aspect mock in my newest commits.

Answer Source

PhpBrowser makes request to your website over HTTP, so the mocks set in the test code have no effect over app code.

The mocks work in unit tests and in functional tests if you are using a framework module.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download