【问题标题】:PHPSpec missing matchersPHPSpec 缺少匹配器
【发布时间】:2015-06-26 15:40:14
【问题描述】:

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

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');
}
}

【问题讨论】:

  • 你能添加你的规格吗?

标签: phpspec


【解决方案1】:

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

$this 是 SUS 而不是 $task

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-14
    • 2021-11-29
    • 2020-11-22
    相关资源
    最近更新 更多