PHPSpec缺少匹配器

时间:2015-06-26 15:40:14

标签: phpspec

当我尝试使用像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');
}
}

1 个答案:

答案 0 :(得分:1)

你只能在$ this-&gt; someMethod()上调用shouldBeEqualTo,对于你需要使用willReturn的存根,因为你正在抄袭他们的行为,而不是断言它。

$this是SUS而非$task