首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHPSpec缺失匹配器

PHPSpec缺失匹配器
EN

Stack Overflow用户
提问于 2015-06-26 15:40:14
回答 1查看 331关注 0票数 1

当我尝试使用PHPSpec匹配器(如shouldBeEqualTo、shouldBeString等)时,我会得到这个错误,我不知道为什么。

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

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

代码语言:javascript
复制
<?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');
}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-26 16:30:12

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

$this是SUS而不是$task

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31077202

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档