PHPSpec missing matchers

403 views Asked by At

When I try using PHPSpec matchers like shouldBeEqualTo, shouldBeString etc I get this error and I don't know why.

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

I have imported ObjectBehavior and my spec is extending it. My PHPSpec version is 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

There are 1 answers

0
gvf On BEST ANSWER

You can only call shouldBeEqualTo on $this->someMethod(), for stubs you need to use willReturn as you are stubbing their behaviour, not asserting it.

$this is the SUS not $task.