Expected function to be invoked but it never occurred
mlambley opened this issue · 3 comments
Howdy,
I've searched for other issues here and on google. I'm still stumped. I have the following code. It always prints
Expected MyUser::getId to be invoked but it never occurred
Please advise what I'm doing wrong. Please also let me know if you require further information.
use AspectMock\Test as test;
class MyUser {
public function getId() {
return "111111";
}
}
class MyTestCase extends \Codeception\TestCase\Test {
public function __construct() {
$this->backupGlobals = false;
parent::__construct();
}
protected function _after() {
parent::_after();
\AspectMock\Test::clean();
}
function testUser() {
$mock = test::double("MyUser", [
'getId' => '555555'
]);
$user = new MyUser();
$user->getId();
$mock->verifyInvoked('getId');
}
}
Thank you.
An example directly from the readme
use AspectMock\Test as test;
class UserModel {
public static function tableName() {
return "users";
}
}
class MyTestCase extends \Codeception\TestCase\Test {
public function __construct() {
$this->backupGlobals = false;
parent::__construct();
}
protected function _after() {
parent::_after();
\AspectMock\Test::clean();
}
function testTableName() {
$this->assertEquals('users', UserModel::tableName());
$userModel = test::double('UserModel', ['tableName' => 'my_users']);
$this->assertEquals('my_users', UserModel::tableName());
$userModel->verifyInvoked('tableName');
}
}
returns
Failed asserting that two strings are equal.
- Expected | + Actual
@@ @@
-'my_users'
+'users'
On the second assertEquals.
My code structure is not standard, and that's where I believe my problem is.
application/ (source files)
application/unitTests/codeception.yml
application/unitTests/tests/_bootstrap.php
application/unitTests/tests/unit/ (etc.)
objects/ (more source files)
libraries/ (includes codeception)
libraries/codeception/vendor/ (etc.)
My tests/_bootstrap.php file looks like
//This file includes codeception/vendor/autoload
require_once(makeIncludePath("libraries/codeception/autoload.php"));
$webRoot = "/usr/home/www/versions/16.4.2.0.4.0/"; //I won't actually hardcode this.
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
'appDir' => $webRoot, //Entire code folder
'includePaths' => [$webRoot . "application/", $webRoot . "objects/"] //source code folders
'excludePaths' => [], //tests dir is automatically added by init().
]);
unset($webRoot);
Could someone please advise what I'm doing wrong?
Closing this because I'm getting myself confused. I've decided to approach it from a different angle:
I've created a brand new laravel project and am attempting to get AspectMock to work in that instead. Once I can get it to work there, I will work backwards and try to get it to work in my current project.