Я пытаюсь создать фиктивный объект и передать его конструктору. Я получаю сообщение об ошибке
Users
✘ GetUser ItShouldThrowAnExceptionIfUserDoesNotExist
┐
├ Failed asserting that exception of type "TypeError" matches expected exception "Foo\Exceptions\UserNotFoundException". Message was: "Argument 2 passed to Foo\Clients\Users::__construct() must be an instance of Foo\Api\UsersApi, instance of Mockery_0__UsersApi given, called in /Users/tomcaflisch/myproject/tests/Clients/UsersTest.php on line 25" at
├ /Users/tomcaflisch/myproject/lib/Clients/Users.php:26
├ /Users/tomcaflisch/myproject/tests/Clients/UsersTest.php:25
├ .
┴
Согласно документам это должно работать.
Класс пользователей
class Users
{
public function __construct(?string $secret, UsersApi $usersApi = null)
{
}
Класс UsersTest
use Mockery\Adapter\Phpunit\MockeryTestCase;
class UsersTest extends MockeryTestCase
{
public function testGetUser_ItShouldThrowAnExceptionIfUserDoesNotExist()
{
$this->expectException(UserNotFoundException::class);
$this->expectExceptionMessage("User with id, email, or username foo@bar.com not found");
$usersApi = Mockery::mock('UsersApi');
$usersApi->shouldReceive('get')
->andThrow(new UserNotFoundException("User with id, email, or username foo@bar.com not found"));
$usersClient = new Users(null, $usersApi);
}