Создаем следующий пример
<?php
namespace uservice;
class User
{
public static function save()
{
echo 'It is not mock method';
}
}
<?php
namespace uservice;
class UserService {
public function createUser()
{
$user = new \uservice\User;
$user->save();
}
}
<?php
use AspectMock\Test as test;
class UserServiceTest extends \PHPUnit_Framework_TestCase
{
protected function tearDown()
{
test::clean();
}
function testUserService()
{
$user = test::double('uservice\User', [
'save' => function () {echo 'It is mock method';}
]);
$service = new \uservice\UserService;
$service->createUser();
}
}
В результате получаем
It is mock method
Теперь выносим User в собственный namespace
<?php
namespace userns;
class User
{
public static function save()
{
echo 'It is not mock method';
}
}
<?php
namespace uservice;
class UserService {
public function createUser()
{
$user = new \userns\User;
$user->save();
}
}
<?php
use AspectMock\Test as test;
class UserServiceTest extends \PHPUnit_Framework_TestCase
{
protected function tearDown()
{
test::clean();
}
function testUserService()
{
$user = test::double('userns\User', [
'save' => function () {echo 'It is mock method';}
]);
$service = new \uservice\UserService;
$service->createUser();
}
}
В результате получаем
It is not mock method
Это баг или я что-то неправильно делаю?