LocationServiceSpec::it_is_initializable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Factory\ModelFactory;
9
use Yproximite\Api\Model\Location\Location;
10
use Yproximite\Api\Service\LocationService;
11
use Yproximite\Api\Message\Location\LocationListMessage;
12
use Yproximite\Api\Message\Location\LocationPostMessage;
13
use Yproximite\Api\Message\Location\LocationPatchMessage;
14
use Yproximite\Api\Message\Location\LocationOverrideMessage;
15
16 View Code Duplication
class LocationServiceSpec extends ObjectBehavior
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
17
{
18
    function it_is_initializable()
19
    {
20
        $this->shouldHaveType(LocationService::class);
21
    }
22
23
    function let(Client $client, ModelFactory $factory)
24
    {
25
        $this->beConstructedWith($client, $factory);
26
    }
27
28
    function it_should_get_locations(
29
        Client $client,
30
        ModelFactory $factory,
31
        LocationListMessage $message
32
    ) {
33
        $message->getSiteId()->willReturn(1);
34
        $message->build()->willReturn([]);
35
36
        $method = 'GET';
37
        $path   = 'sites/1/locations';
38
39
        $client->sendRequest($method, $path)->willReturn([]);
40
        $client->sendRequest($method, $path)->shouldBeCalled();
41
42
        $factory->createMany(Location::class, [])->willReturn([]);
43
44
        $this->getLocations($message);
45
    }
46
47
    function it_should_post_location(
48
        Client $client,
49
        ModelFactory $factory,
50
        LocationPostMessage $message,
51
        Location $location
52
    ) {
53
        $message->getSiteId()->willReturn(1);
54
        $message->build()->willReturn([]);
55
56
        $method = 'POST';
57
        $path   = 'sites/1/locations';
58
        $data   = ['api_location' => []];
59
60
        $client->sendRequest($method, $path, $data)->willReturn([]);
61
        $client->sendRequest($method, $path, $data)->shouldBeCalled();
62
63
        $factory->create(Location::class, [])->willReturn($location);
64
65
        $this->postLocation($message);
66
    }
67
68
    function it_should_patch_location(
69
        Client $client,
70
        ModelFactory $factory,
71
        LocationPatchMessage $message,
72
        Location $location
73
    ) {
74
        $message->getId()->willReturn(2);
75
        $message->getSiteId()->willReturn(1);
76
        $message->build()->willReturn([]);
77
78
        $method = 'PATCH';
79
        $path   = 'sites/1/locations/2';
80
        $data   = ['api_location' => []];
81
82
        $client->sendRequest($method, $path, $data)->willReturn([]);
83
        $client->sendRequest($method, $path, $data)->shouldBeCalled();
84
85
        $factory->create(Location::class, [])->willReturn($location);
86
87
        $this->patchLocation($message);
88
    }
89
90
    function it_should_override_location(
91
        Client $client,
92
        ModelFactory $factory,
93
        LocationOverrideMessage $message,
94
        Location $location
95
    ) {
96
        $message->getId()->willReturn(5);
97
        $message->getSiteId()->willReturn(1);
98
        $message->build()->willReturn([]);
99
100
        $method = 'GET';
101
        $path   = 'sites/1/locations/5/override';
102
103
        $client->sendRequest($method, $path)->willReturn([]);
104
        $client->sendRequest($method, $path)->shouldBeCalled();
105
106
        $factory->create(Location::class, [])->willReturn($location);
107
108
        $this->overrideLocation($message);
109
    }
110
}
111