1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Yproximite\Api\Service; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
|
7
|
|
|
use Yproximite\Api\Client\Client; |
8
|
|
|
use Yproximite\Api\Model\Site\Site; |
9
|
|
|
use Yproximite\Api\Service\SiteService; |
10
|
|
|
use Yproximite\Api\Factory\ModelFactory; |
11
|
|
|
use Yproximite\Api\Message\Site\SitePostMessage; |
12
|
|
|
use Yproximite\Api\Message\Site\SiteDeleteMessage; |
13
|
|
|
use Yproximite\Api\Message\Site\PlatformChildrenListMessage; |
14
|
|
|
|
15
|
|
|
class SiteServiceSpec extends ObjectBehavior |
16
|
|
|
{ |
17
|
|
|
function it_is_initializable() |
18
|
|
|
{ |
19
|
|
|
$this->shouldHaveType(SiteService::class); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
function let(Client $client, ModelFactory $factory) |
23
|
|
|
{ |
24
|
|
|
$this->beConstructedWith($client, $factory); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
View Code Duplication |
function it_should_get_sites(Client $client, ModelFactory $factory) |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$method = 'GET'; |
30
|
|
|
$path = 'sites'; |
31
|
|
|
|
32
|
|
|
$client->sendRequest($method, $path)->willReturn([]); |
33
|
|
|
$client->sendRequest($method, $path)->shouldBeCalled(); |
34
|
|
|
|
35
|
|
|
$factory->createMany(Site::class, [])->willReturn([]); |
36
|
|
|
|
37
|
|
|
$this->getSites(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
function it_should_get_site(Client $client, ModelFactory $factory, Site $site) |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
$method = 'GET'; |
43
|
|
|
$path = 'sites/1'; |
44
|
|
|
|
45
|
|
|
$client->sendRequest($method, $path)->willReturn([]); |
46
|
|
|
$client->sendRequest($method, $path)->shouldBeCalled(); |
47
|
|
|
|
48
|
|
|
$factory->create(Site::class, [])->willReturn($site); |
49
|
|
|
|
50
|
|
|
$this->getSite(1); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function it_should_post_site( |
54
|
|
|
Client $client, |
55
|
|
|
ModelFactory $factory, |
56
|
|
|
SitePostMessage $message, |
57
|
|
|
Site $site |
58
|
|
|
) { |
59
|
|
|
$message->getCompanyId()->willReturn(1); |
60
|
|
|
$message->build()->willReturn([]); |
61
|
|
|
|
62
|
|
|
$method = 'POST'; |
63
|
|
|
$path = 'sites'; |
64
|
|
|
$data = ['api_site' => []]; |
65
|
|
|
|
66
|
|
|
$client->sendRequest($method, $path, $data)->willReturn([]); |
67
|
|
|
$client->sendRequest($method, $path, $data)->shouldBeCalled(); |
68
|
|
|
|
69
|
|
|
$factory->create(Site::class, [])->willReturn($site); |
70
|
|
|
|
71
|
|
|
$this->postSite($message); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
function it_should_delete_site(Client $client, SiteDeleteMessage $message) |
75
|
|
|
{ |
76
|
|
|
$message->getId()->willReturn(1); |
77
|
|
|
|
78
|
|
|
$method = 'DELETE'; |
79
|
|
|
$path = 'sites/1'; |
80
|
|
|
|
81
|
|
|
$client->sendRequest($method, $path)->shouldBeCalled(); |
82
|
|
|
|
83
|
|
|
$this->deleteSite($message); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
function it_should_get_platform_children( |
87
|
|
|
Client $client, |
88
|
|
|
ModelFactory $factory, |
89
|
|
|
PlatformChildrenListMessage $message |
90
|
|
|
) { |
91
|
|
|
$message->getSiteId()->willReturn(1); |
92
|
|
|
$message->build()->willReturn([]); |
93
|
|
|
|
94
|
|
|
$method = 'GET'; |
95
|
|
|
$path = 'platform/1/children'; |
96
|
|
|
|
97
|
|
|
$client->sendRequest($method, $path)->willReturn([]); |
98
|
|
|
$client->sendRequest($method, $path)->shouldBeCalled(); |
99
|
|
|
|
100
|
|
|
$factory->createMany(Site::class, [])->willReturn([]); |
101
|
|
|
|
102
|
|
|
$this->getPlatformChildren($message); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.