|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Donut Social Network - Yet another experimental social network. |
|
5
|
|
|
* Copyright (C) 2016-2017, Dejan Angelov <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This file is part of Donut Social Network. |
|
8
|
|
|
* |
|
9
|
|
|
* Donut Social Network is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU General Public License as published by |
|
11
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
12
|
|
|
* (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* Donut Social Network is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU General Public License |
|
20
|
|
|
* along with Donut Social Network. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
* @package Donut Social Network |
|
23
|
|
|
* @copyright Copyright (C) 2016-2017, Dejan Angelov <[email protected]> |
|
24
|
|
|
* @license https://github.com/angelov/donut/blob/master/LICENSE |
|
25
|
|
|
* @author Dejan Angelov <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
namespace AppBundle\FeatureContexts\Setup; |
|
29
|
|
|
|
|
30
|
|
|
use Angelov\Donut\Behat\Service\Storage\StorageInterface; |
|
31
|
|
|
use Angelov\Donut\Communities\Commands\JoinCommunityCommand; |
|
32
|
|
|
use Angelov\Donut\Communities\Commands\StoreCommunityCommand; |
|
33
|
|
|
use Angelov\Donut\Communities\Community; |
|
34
|
|
|
use Angelov\Donut\Communities\Repositories\CommunitiesRepositoryInterface; |
|
35
|
|
|
use Angelov\Donut\Core\CommandBus\CommandBusInterface; |
|
36
|
|
|
use Angelov\Donut\Core\UuidGenerator\UuidGeneratorInterface; |
|
37
|
|
|
use Angelov\Donut\Users\User; |
|
38
|
|
|
use Behat\Behat\Context\Context; |
|
39
|
|
|
|
|
40
|
|
|
class CommunitiesContext implements Context |
|
41
|
|
|
{ |
|
42
|
|
|
private $commandBus; |
|
43
|
|
|
private $storage; |
|
44
|
|
|
private $uuidGenerator; |
|
45
|
|
|
private $communities; |
|
46
|
|
|
|
|
47
|
|
|
public function __construct( |
|
48
|
|
|
CommandBusInterface $commandBus, |
|
49
|
|
|
StorageInterface $storage, |
|
50
|
|
|
UuidGeneratorInterface $uuidGenerator, |
|
51
|
|
|
CommunitiesRepositoryInterface $communities |
|
52
|
|
|
) { |
|
53
|
|
|
$this->storage = $storage; |
|
54
|
|
|
$this->uuidGenerator = $uuidGenerator; |
|
55
|
|
|
$this->commandBus = $commandBus; |
|
56
|
|
|
$this->communities = $communities; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @Given there is a community named :name and described as :description |
|
61
|
|
|
* @Given there is a community named :name |
|
62
|
|
|
*/ |
|
63
|
|
|
public function thereIsACommunityNamedAndDescribedAs(string $name, string $description = '') : void |
|
64
|
|
|
{ |
|
65
|
|
|
$logged = $this->storage->get('logged_user'); |
|
66
|
|
|
|
|
67
|
|
|
$this->createCommunity($name, $description, $logged); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @Given he has created the :name community |
|
72
|
|
|
*/ |
|
73
|
|
|
public function heHasCreatedTheCommunity(string $name) : void |
|
74
|
|
|
{ |
|
75
|
|
|
$author = $this->storage->get('last_created_user'); |
|
76
|
|
|
|
|
77
|
|
|
$this->createCommunity($name, '', $author); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
private function createCommunity(string $name, string $description, User $author) : Community |
|
81
|
|
|
{ |
|
82
|
|
|
$id = $this->uuidGenerator->generate(); |
|
83
|
|
|
$this->commandBus->handle(new StoreCommunityCommand($id, $name, $author->getId(), $description)); |
|
84
|
|
|
|
|
85
|
|
|
$community = $this->communities->find($id); |
|
86
|
|
|
|
|
87
|
|
|
$this->storage->set('created_community', $community); |
|
88
|
|
|
$this->storage->set('community_' . $name, $community); |
|
89
|
|
|
|
|
90
|
|
|
return $community; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @Given I have joined the :name community |
|
95
|
|
|
* @Given I have joined it |
|
96
|
|
|
*/ |
|
97
|
|
|
public function iHaveJoinedTheCommunity(string $name = '') : void |
|
98
|
|
|
{ |
|
99
|
|
|
/** @var Community $community */ |
|
100
|
|
|
$community = ($name !== '' ) ? $this->storage->get('community_' . $name) : $this->storage->get('created_community'); |
|
101
|
|
|
|
|
102
|
|
|
/** @var User $logged */ |
|
103
|
|
|
$logged = $this->storage->get('logged_user'); |
|
104
|
|
|
|
|
105
|
|
|
$this->commandBus->handle(new JoinCommunityCommand($logged->getId(), $community->getId())); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @Given I haven't joined it |
|
110
|
|
|
*/ |
|
111
|
|
|
public function iHavenTJoinedIt() : void |
|
112
|
|
|
{ |
|
113
|
|
|
// do nothing |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @Given (s)he has (also) joined it |
|
118
|
|
|
*/ |
|
119
|
|
|
public function heAlsoHasJoinedIt() : void |
|
120
|
|
|
{ |
|
121
|
|
|
/** @var Community $community */ |
|
122
|
|
|
$community = $this->storage->get('created_community'); |
|
123
|
|
|
|
|
124
|
|
|
/** @var User $user */ |
|
125
|
|
|
$user = $this->storage->get('last_created_user'); |
|
126
|
|
|
|
|
127
|
|
|
$this->commandBus->handle(new JoinCommunityCommand($user->getId(), $community->getId())); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @Given nobody hasn't created any community yet |
|
132
|
|
|
*/ |
|
133
|
|
|
public function nobodyHasnTCreatedAnyCommunityYet() : void |
|
134
|
|
|
{ |
|
135
|
|
|
// do nothing |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|