AspectMock icon indicating copy to clipboard operation
AspectMock copied to clipboard

test::double doesn't work

Open sggeorgiev opened this issue 5 years ago • 2 comments

I created this simple test: ` require_once DIR.'/vendor/autoload.php';

$kernel = \AspectMock\Kernel::getInstance(); $kernel->init([ 'debug' => true, 'appDir'=>DIR."/vendor/codeception/aspect-mock/src/", 'cacheDir' => "/tmp/amock" ]);

class User { public function getName() { return "test"; } };

$user = AspectMock\Test::double(User::class, ['getName' => 'davert']); $u = new User; print $u->getName()."\n"; ` It always print "test" instead "davert". Here is my composer.json file: "require": { "php": ">=7.0.0", "goaop/framework": "^2.2.0", "symfony/finder": "~2.4|~3.0|~4.0" }, "require-dev": { "codeception/base": "^2.4", "codeception/verify": "~0.2", "codeception/specify": "~0.3", "codeception/aspect-mock": "*", "phpunit/phpunit": "^6.5" }

PHP 7.0.33-0ubuntu0.16.04.1 (cli) ( NTS )

sggeorgiev avatar Feb 20 '19 14:02 sggeorgiev

appDir should contain the path to your application, not aspect mock's source

davidcochrum avatar May 29 '19 15:05 davidcochrum

Hello, I have the same problem: codeception version: 3.1.2 codecept version: 3.1.0 framework: Codeigniter 2 (a legacy app)

_bootstrap file: `include DIR.'/../vendor/autoload.php';

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

codeception.yml: unit: actor: Unit path: ./unit modules: enabled: - \Helper\Unit - Asserts bootstrap: '../_bootstrap.php'

class = application/A.php class A { public function aa() { return 'aa'; } public static function bb() { return 'bb'; } }

test: test::double(A::class, [ 'aa' => 'cc', 'bb' => 'dd', ]); $c = new A(); $r = $c->aa(); $r2 = $c::bb();

    `$this->assertEquals('cc', $r);`
    `$this->assertEquals('dd', $r2);`

results:

Test tests/unit/Permissions/UserCanTest.php:testMock Failed asserting that two strings are equal. - Expected | + Actual @@ @@ -'cc' +'aa'

vincenzodibiaggio avatar Apr 06 '20 09:04 vincenzodibiaggio