|
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()) |
|
|
|
|
|
|
48
|
|
|
->willReturn($this->remainingTask); |
|
49
|
|
|
|
|
50
|
|
|
$this->taskRepository->findByName('Buying salt') |
|
|
|
|
|
|
51
|
|
|
->willThrow(TaskNotFoundException::class); |
|
52
|
|
|
$this->taskRepository->findByName('') |
|
|
|
|
|
|
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
|
|
|
|
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.