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

QuerySpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A generate_task() 0 7 1
B let() 0 24 1
A it_can_get_remaining_tasks() 0 5 1
A it_can_get_completed_tasks() 0 5 1
A it_can_get_task_by_id() 0 4 1
1
<?php
2
3
namespace spec\Todo\Application\Task;
4
5
use Todo\Application\Task\Query;
6
use Todo\Domain\Factory\TaskFactory;
7
use Todo\Domain\Repository\TaskRepositoryInterface;
8
use Todo\Domain\Task;
9
use PhpSpec\ObjectBehavior;
10
use Prophecy\Argument;
11
12
class QuerySpec extends ObjectBehavior
13
{
14
    /** @var  TaskRepositoryInterface */
15
    protected $taskRepository;
16
17
    /** @var  TaskFactory */
18
    protected $taskFactory;
19
20
    protected $remainingTasks;
21
    protected $completedTasks;
22
23
    function it_is_initializable()
24
    {
25
        $this->shouldHaveType(Query::class);
26
    }
27
28
    function generate_task(string $name)
29
    {
30
        $task = new Task();
31
        $task->setName($name);
32
33
        return $task;
34
    }
35
36
    function let(TaskRepositoryInterface $taskRepository)
37
    {
38
        $this->remainingTasks = [
39
            $this->generate_task('Buying sugar'),
40
            $this->generate_task('Buying milk')
41
        ];
42
        $this->completedTasks = [
43
            $this->generate_task('Withdraw money'),
44
            $this->generate_task('Take car')
45
        ];
46
47
        $this->taskRepository = $taskRepository;
48
        $this->taskRepository
49
            ->findAllByStatus(Task::STATUS_REMAINING)
50
            ->willReturn($this->remainingTasks);
51
        $this->taskRepository
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...
52
            ->find(1)
53
            ->willReturn($this->remainingTasks[0]);
54
        $this->taskRepository
55
            ->findAllByStatus(Task::STATUS_COMPLETED)
56
            ->willReturn($this->completedTasks);
57
58
        $this->beConstructedWith($this->taskRepository);
59
    }
60
61
    function it_can_get_remaining_tasks()
62
    {
63
        $this->getAllRemainingTasks()
64
            ->shouldBe($this->remainingTasks);
65
    }
66
67
    function it_can_get_completed_tasks()
68
    {
69
        $this->getAllCompletedTasks()
70
            ->shouldBe($this->completedTasks);
71
    }
72
    function it_can_get_task_by_id()
73
    {
74
        $this->getTaskById(1)->shouldReturn($this->remainingTasks[0]);
75
    }
76
}
77