|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Kreta package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
|
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Spec\Kreta\TaskManager\Domain\Model\Organization; |
|
14
|
|
|
|
|
15
|
|
|
use Kreta\SharedKernel\Domain\Model\CollectionElementAlreadyAddedException; |
|
16
|
|
|
use Kreta\SharedKernel\Domain\Model\CollectionElementAlreadyRemovedException; |
|
17
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\Organization; |
|
18
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\OrganizationId; |
|
19
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\OrganizationName; |
|
20
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\OrganizationParticipant; |
|
21
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\OrganizationSlug; |
|
22
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\Owner; |
|
23
|
|
|
use PhpSpec\ObjectBehavior; |
|
24
|
|
|
|
|
25
|
|
|
class OrganizationSpec extends ObjectBehavior |
|
26
|
|
|
{ |
|
27
|
|
|
function let(OrganizationId $organizationId, OrganizationName $organizationName, OrganizationSlug $organizationSlug, Owner $owner) |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
$organizationId->id()->willReturn('organization-id'); |
|
30
|
|
|
$this->beConstructedWith($organizationId, $organizationName, $organizationSlug, $owner); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function it_is_initializable() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->shouldHaveType(Organization::class); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function it_shows_organization_creator_as_an_owner(Owner $owner) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->owners()->shouldReturnCollection([$owner]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
function it_allows_adding_a_new_owner(Owner $owner, Owner $owner2) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->addOwner($owner2); |
|
46
|
|
|
$this->owners()->shouldReturnCollection([$owner, $owner2]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function it_does_not_allow_to_add_existing_owner(Owner $owner) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->shouldThrow(CollectionElementAlreadyAddedException::class)->during('addOwner', [$owner]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function it_allows_removing_an_owner(Owner $owner, Owner $owner2) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->addOwner($owner2); |
|
57
|
|
|
$this->removeOwner($owner2); |
|
58
|
|
|
|
|
59
|
|
|
$this->owners()->shouldReturnCollection([$owner]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
function it_does_not_allow_removing_unexistent_owner(Owner $owner2) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->shouldThrow(CollectionElementAlreadyRemovedException::class)->during('removeOwner', [$owner2]); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
function it_allows_adding_a_new_participant(OrganizationParticipant $participant) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->addParticipant($participant); |
|
70
|
|
|
$this->participants()->shouldReturnCollection([$participant]); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
function it_does_not_allow_to_add_existing_participant(OrganizationParticipant $participant) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->addParticipant($participant); |
|
76
|
|
|
|
|
77
|
|
|
$this->shouldThrow(CollectionElementAlreadyAddedException::class)->during('addParticipant', [$participant]); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
function it_allows_removing_a_participant(OrganizationParticipant $participant) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->addParticipant($participant); |
|
83
|
|
|
$this->removeParticipant($participant); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
function it_does_not_allow_removing_unexistent_participant(OrganizationParticipant $participant) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->shouldThrow(CollectionElementAlreadyRemovedException::class)->during('removeParticipant', [$participant]); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
function it_gets_id() |
|
92
|
|
|
{ |
|
93
|
|
|
$this->id()->shouldReturnAnInstanceOf(OrganizationId::class); |
|
94
|
|
|
$this->__toString()->shouldReturn('organization-id'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
function it_gets_name(OrganizationName $organizationName) |
|
98
|
|
|
{ |
|
99
|
|
|
$this->name()->shouldReturn($organizationName); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
function it_gets_slug(OrganizationSlug $organizationSlug) |
|
103
|
|
|
{ |
|
104
|
|
|
$this->slug()->shouldReturn($organizationSlug); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.