Unable to instrument classes in the /vendor directory

Open
#139 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
php
Domain
testing

Research direction

Start with the bootstrap configuration shown in the issue and reproduce the test using PayPal\IPN\PPIPNMessage, focusing on includePaths, excludePaths, and Composer autoloading. Trace why test::double does not intercept getRawData for the /vendor class. Done means the invocation is intercepted and verifyInvoked('getRawData') passes.

Written by the indexing model from the issue text.

Description

I was able to get AspectMock to instrument my own classes in my directory but I can not get it to work on classes in the composer /vendor directory....

Is this even possible?

I tried adding vendor to my includePaths but I get the issue in #112

My bootstrap looks basically like this:

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

$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
    'debug' => true,
    'appDir' => __DIR__.'/..',
    'cacheDir' => __DIR__.'/_data/aopcache',
    'includePaths' => [
        __DIR__.'/../repo'
    ],
    'excludePaths' => [
        __DIR__,
    ]
]);

Sample of my test code:

    $testDataStr = 'var=1&var=2';
    $paypalIPN = test::double(new \PayPal\IPN\PPIPNMessage($testDataStr), [
        'getRawData' => ['Returned test double'],
    ]);
    $this->assertTrue($paypalIPN->class->hasMethod('getRawData'));
    $testData = $paypalIPN->getRawData();
    $paypalIPN->verifyInvoked('getRawData'); // fails

fails with:
Expected PayPal\IPN\PPIPNMessage->getRawData to be invoked but it never occurred. Got:

Versions
php 5.6.30
codeception/aspect-mock:2.0.1 @b7f5c50da89419824102400bb4c71988ec33044f
goaop/framework:2.1.2 @6e2a0fe13c1943db02a67588cfd27692bddaffa5
goaop/parser-reflection:1.4.0 @adfc38fee63014880932ebcc4810871b8e33edc9

Dominant language
PHP
Stars
784
Forks
130
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Codeception/AspectMock

All issues in Codeception/AspectMock

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.