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

TaskValidationServiceSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A generate_task() 0 7 1
B let() 0 25 1
A it_can_validate() 0 8 1
1
<?php
2
3
namespace spec\Todo\Domain\Service;
4
5
use Todo\Domain\Exception\TaskNameIsAlreadyExistedException;
6
use Todo\Domain\Exception\TaskNameIsEmptyException;
7
use Todo\Domain\Exception\TaskNotFoundException;
8
use Todo\Domain\Repository\TaskRepositoryInterface;
9
use Todo\Domain\Service\TaskValidationService;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
use Todo\Domain\Task;
13
14
class TaskValidationServiceSpec extends ObjectBehavior
15
{
16
    protected $taskRepository;
17
18
    /** @var Task */
19
    protected $remainingTask;
20
21
    /** @var Task */
22
    protected $completedTask;
23
24
    function it_is_initializable()
25
    {
26
        $this->shouldHaveType(TaskValidationService::class);
27
    }
28
    function generate_task(string $name) : Task
29
    {
30
        $task = new Task();
31
        $task->setName($name);
32
33
        return $task;
34
    }
35
36
    function let(TaskRepositoryInterface $taskRepository)
37
    {
38
39
        $this->remainingTask = $this->generate_task('Buying sugar');
40
        $this->remainingTask->setId(1);
41
        $this->remainingTask->setStatus(Task::STATUS_REMAINING);
42
43
44
45
        $this->taskRepository = $taskRepository;
46
47
        $this->taskRepository->findByName($this->remainingTask->getName())
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...
48
            ->willReturn($this->remainingTask);
49
50
        $this->taskRepository->findByName('Buying salt')
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...
51
            ->willThrow(TaskNotFoundException::class);
52
        $this->taskRepository->findByName('')
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...
53
            ->willThrow(TaskNotFoundException::class);
54
55
56
57
58
59
        $this->beConstructedWith($this->taskRepository);
60
    }
61
62
    function it_can_validate()
63
    {
64
        $this->shouldThrow(TaskNameIsEmptyException::class)->duringValidateName('');
65
        $this->shouldThrow(TaskNameIsAlreadyExistedException::class)->duringValidateName($this->remainingTask->getName());
66
67
        $this->validateName($this->remainingTask->getName(), $this->remainingTask->getId())->shouldReturn(true);
68
        $this->validateName('Buying salt')->shouldReturn(true);
69
    }
70
}
71