PHPSpec 缺少匹配器

PHPSpec missing matchers

当我尝试使用 shouldBeEqualTo、shouldBeString 等 PHPSpec 匹配器时,出现此错误,我不知道为什么。

Call to undefined method Prophecy\Prophecy\MethodProphecy::shouldBeEqualTo()

我已经导入了 ObjectBehavior,我的规范正在扩展它。 我的 PHPSpec 版本是 2.2.1.

<?php

namespace Spec\Itmore\Core\Interactor;

use Itmore\Core\Entity\Task;
use Itmore\Core\Entity\TaskDTO;
use Itmore\Core\Entity\TaskList;
use Itmore\Core\Entity\TaskListDTO;
use Itmore\Core\Interactor\AddTask;
use Itmore\Core\Repository\TaskRepositoryInterface;
use Itmore\Core\Repository\TasklistRepositoryInterface;
use Itmore\Core\Repository\UserRepositoryInterface;
use PhpSpec\ObjectBehavior;
use Prophecy;

class SynchronizeTaskSpec extends ObjectBehavior
{
public function let(
    TaskRepositoryInterface $taskRepository,
    TaskListRepositoryInterface $taskListRepository,
    UserRepositoryInterface $userRepository
) {
    $this->beConstructedWith($taskRepository, $taskListRepository, $userRepository);
}
public function it_is_initializable()
{
    $this->shouldHaveType('Itmore\Core\Interactor\SynchronizeTask');
}

public function it_should_throw_exception_when_task_does_not_gave_google_id(
    TaskDTO $taskDTO,
    TaskListDTO $taskListDTO
) {
    $exception = new \ErrorException('not a google task');
    $this->shouldThrow($exception)->duringFromGoogleToApp($taskDTO, $taskListDTO);
}

public function it_should_synchronize_existing_task_from_google_to_app(
    TaskDTO $taskDTO,
    TaskListDTO $taskListDTO,
    Task $task,
    TaskRepositoryInterface $taskRepository
) {
    $taskDTO->getGoogleId()->willReturn('taskId');
    $taskRepository->findOneByGoogleId('taskId')->willReturn($task);
    $taskDTO->getTitle()->willReturn('GoogleTitle');
//        $task->getTitle()->shouldBeEqualTo('GoogleTitle');
    $taskDTO->getTitle()->willReturn('exampleTitle');

    $taskRepository->update()->shouldBeCalled();
    $this->fromGoogleToApp($taskDTO, $taskListDTO)->shouldReturnAnInstanceOf('Itmore\Core\Entity\TaskDTO');
}
}

您只能在 $this->someMethod() 上调用 shouldBeEqualTo,对于存根,您需要使用 willReturn,因为您是在存根它们的行为,而不是断言它。

$this 是 SUS 不是 $task.