|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Todo\Domain\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use Todo\Domain\Exception\TaskNameIsAlreadyExistedException; |
|
6
|
|
|
use Todo\Domain\Exception\TaskNameIsEmptyException; |
|
7
|
|
|
use Todo\Domain\Exception\TaskNotFoundException; |
|
8
|
|
|
use Todo\Domain\Factory\TaskFactory; |
|
9
|
|
|
use Todo\Domain\Repository\TaskRepositoryInterface; |
|
10
|
|
|
use Todo\Domain\Service\TaskValidationService; |
|
11
|
|
|
use Todo\Domain\Task; |
|
12
|
|
|
use PhpSpec\ObjectBehavior; |
|
13
|
|
|
use Prophecy\Argument; |
|
14
|
|
|
|
|
15
|
|
|
class TaskFactorySpec extends ObjectBehavior |
|
16
|
|
|
{ |
|
17
|
|
|
protected $nameExists = 'Buying toys'; |
|
18
|
|
|
protected $nameNotExists = 'Buying caffe'; |
|
19
|
|
|
|
|
20
|
|
|
/** @var TaskRepositoryInterface */ |
|
21
|
|
|
protected $taskRepository; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
function it_is_initializable() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->shouldHaveType(TaskFactory::class); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
function let(TaskRepositoryInterface $taskRepository) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->taskRepository = $taskRepository; |
|
32
|
|
|
|
|
33
|
|
|
$taskExists = new Task(); |
|
34
|
|
|
$taskExists->setId(1); |
|
35
|
|
|
$taskExists->setName($this->nameExists); |
|
36
|
|
|
$this->taskRepository->findByName($this->nameExists) |
|
|
|
|
|
|
37
|
|
|
->willReturn($taskExists); |
|
38
|
|
|
|
|
39
|
|
|
$this->taskRepository->findByName($this->nameNotExists) |
|
|
|
|
|
|
40
|
|
|
->willThrow(TaskNotFoundException::class); |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
$this->beConstructedWith($this->taskRepository); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
function it_can_create_task_from_name() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->shouldThrow(TaskNameIsEmptyException::class) |
|
49
|
|
|
->duringCreateFromName(''); |
|
50
|
|
|
$this->shouldThrow(TaskNameIsAlreadyExistedException::class) |
|
51
|
|
|
->duringCreateFromName($this->nameExists); |
|
52
|
|
|
|
|
53
|
|
|
/** @var Task $task */ |
|
54
|
|
|
$task = $this->createFromName($this->nameNotExists); |
|
55
|
|
|
$task->shouldBeAnInstanceOf(Task::class); |
|
|
|
|
|
|
56
|
|
|
$task->getName()->shouldReturn($this->nameNotExists); |
|
57
|
|
|
$task->getStatus()->shouldReturn(Task::STATUS_REMAINING); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.