We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

AspectMock is not working well with Phalcon

Hi,

I'm trying to mock a simple class that calls a static method with Phalcon and it's not working. I'm using Phalcon 2.0.7.

$client = new \stdClass();
$client->email = '[email protected]';
$client->active = 1;

$mailer = test::double('Mailer', ['send' => null]);
$clientEmails = new \ClientEmails();
$clientEmails->sendOwnerNotification($client);

$mailer->verifyInvoked('send');

When I run the test I got the error:

1) Test\ClientEmailsTestUnitTest::test_sendFirstNotifications
Expected Mailer::send to be invoked but it never occur.

I tried it without PhalconPHP and it worked well, so I think the problem is with the Phalcon Loader. On my TestHelper.php I have:

// Required for phalcon/incubator
include __DIR__ . "/../vendor/autoload.php";

$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
    'debug' => true,
    'includePaths' => [__DIR__ . '/../app/']
]);
$kernel->loadFile('PhalconLoader.php');

And on the PhalconLoader.php I have:

$loader = new \Phalcon\Loader();
$loader->registerDirs(
    array(
        ROOT_PATH,
        PATH_LIBRARY,
    )
);
$loader->register();

Here is all the code: https://github.com/thiagolcks/Phalcon-with-AspectMock/

Ideas?