当我尝试使用诸如shouldBeEqualTo、shouldBeString等PHPSpec匹配器时,我会遇到这个错误,我不知道为什么。
Call to undefined method ProphecyProphecyMethodProphecy::shouldBeEqualTo()
我已经导入了ObjectBehavior,我的规范正在扩展它。我的PHPSpec版本是2.2.1。
<?php
namespace SpecItmoreCoreInteractor;
use ItmoreCoreEntityTask;
use ItmoreCoreEntityTaskDTO;
use ItmoreCoreEntityTaskList;
use ItmoreCoreEntityTaskListDTO;
use ItmoreCoreInteractorAddTask;
use ItmoreCoreRepositoryTaskRepositoryInterface;
use ItmoreCoreRepositoryTasklistRepositoryInterface;
use ItmoreCoreRepositoryUserRepositoryInterface;
use PhpSpecObjectBehavior;
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('ItmoreCoreInteractorSynchronizeTask');
}
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('ItmoreCoreEntityTaskDTO');
}
}
您只能在$this->someMethod()上调用shouldBeEqualTo
,对于存根,您需要使用willReturn
来存根它们的行为,而不是断言它。
$this
是SUS而不是$task
。