Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test::double doesn't work #168

Open
sggeorgiev opened this issue Feb 20, 2019 · 2 comments
Open

test::double doesn't work #168

sggeorgiev opened this issue Feb 20, 2019 · 2 comments

Comments

@sggeorgiev
Copy link

sggeorgiev commented Feb 20, 2019

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 )

@davidcochrum
Copy link

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

@vincenzodibiaggio
Copy link

vincenzodibiaggio commented Apr 6, 2020

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants