Поставил AspectMock
Создаю класс
namespace updater;
class User {
private $name;
function setName($name)
{
$this->name = $name;
}
function getName()
{
return $this->name;
}
function save()
{
echo 'Save!!!!';
}
}
и тест
use AspectMock\Test as test;
use updater\User;
class UserService {
function createUserByName($name)
{
$user = new User;
$user->setName($name);
$user->save();
}
}
class aspectMoskTest extends \PHPUnit_Framework_TestCase
{
function testUserCreate()
{
$user = test::double('updater\User', ['save' => null]);
$service = new UserService;
$service->createUserByName('davert');
$this->assertEquals('davert', $user->getName());
$user->verifyInvoked('save');
}
}
Содержимое _bootstrap.php
<?php
require_once \dirname(__DIR__).'/vendor/autoload.php';
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
'debug' => true,
'includePaths' => [\dirname(__DIR__).'/updater']
]);
Добавлял
'appDir' => \dirname(__DIR__),
Структура директории
updater
User.php
tests
_bootstrap.php
тесты в поддиректориях
vendors
пакеты Composer
Вроде все делаю по базовому примеру. Получаю ошибку
aspectMoskTest::testUserCreate
Exception: Called updater\User->getName, but this is a proxy for a class definition.
Probably you was trying to access instance method.
Construct an instance from this class
Что я делаю не так?