Test Failed
Push — master ( 06fcec...ff7c45 )
by Martin
07:58
created

TaskFactorySpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A let() 0 16 1
A it_can_create_task_from_name() 0 13 1
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)
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Todo\Domain\Task>.

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.

Loading history...
37
            ->willReturn($taskExists);
38
39
        $this->taskRepository->findByName($this->nameNotExists)
0 ignored issues
show
Bug introduced by
The method willThrow() does not seem to exist on object<Todo\Domain\Task>.

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.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method shouldBeAnInstanceOf() does not seem to exist on object<Todo\Domain\Task>.

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.

Loading history...
56
        $task->getName()->shouldReturn($this->nameNotExists);
57
        $task->getStatus()->shouldReturn(Task::STATUS_REMAINING);
58
    }
59
}
60