@@ 16-110 (lines=95) @@ | ||
13 | use Yproximite\Api\Message\Field\FieldPatchMessage; |
|
14 | use Yproximite\Api\Message\Field\FieldOverrideMessage; |
|
15 | ||
16 | class FieldServiceSpec extends ObjectBehavior |
|
17 | { |
|
18 | function it_is_initializable() |
|
19 | { |
|
20 | $this->shouldHaveType(FieldService::class); |
|
21 | } |
|
22 | ||
23 | function let(Client $client, ModelFactory $factory) |
|
24 | { |
|
25 | $this->beConstructedWith($client, $factory); |
|
26 | } |
|
27 | ||
28 | function it_should_get_fields( |
|
29 | Client $client, |
|
30 | ModelFactory $factory, |
|
31 | FieldListMessage $message |
|
32 | ) { |
|
33 | $message->getSiteId()->willReturn(1); |
|
34 | $message->build()->willReturn([]); |
|
35 | ||
36 | $method = 'GET'; |
|
37 | $path = 'sites/1/fields'; |
|
38 | ||
39 | $client->sendRequest($method, $path)->willReturn([]); |
|
40 | $client->sendRequest($method, $path)->shouldBeCalled(); |
|
41 | ||
42 | $factory->createMany(Field::class, [])->willReturn([]); |
|
43 | ||
44 | $this->getFields($message); |
|
45 | } |
|
46 | ||
47 | function it_should_post_field( |
|
48 | Client $client, |
|
49 | ModelFactory $factory, |
|
50 | FieldPostMessage $message, |
|
51 | Field $field |
|
52 | ) { |
|
53 | $message->getSiteId()->willReturn(1); |
|
54 | $message->build()->willReturn([]); |
|
55 | ||
56 | $method = 'POST'; |
|
57 | $path = 'sites/1/fields'; |
|
58 | $data = ['api_field' => []]; |
|
59 | ||
60 | $client->sendRequest($method, $path, $data)->willReturn([]); |
|
61 | $client->sendRequest($method, $path, $data)->shouldBeCalled(); |
|
62 | ||
63 | $factory->create(Field::class, [])->willReturn($field); |
|
64 | ||
65 | $this->postField($message); |
|
66 | } |
|
67 | ||
68 | function it_should_patch_field( |
|
69 | Client $client, |
|
70 | ModelFactory $factory, |
|
71 | FieldPatchMessage $message, |
|
72 | Field $field |
|
73 | ) { |
|
74 | $message->getId()->willReturn(2); |
|
75 | $message->getSiteId()->willReturn(1); |
|
76 | $message->build()->willReturn([]); |
|
77 | ||
78 | $method = 'PATCH'; |
|
79 | $path = 'sites/1/fields/2'; |
|
80 | $data = ['api_field' => []]; |
|
81 | ||
82 | $client->sendRequest($method, $path, $data)->willReturn([]); |
|
83 | $client->sendRequest($method, $path, $data)->shouldBeCalled(); |
|
84 | ||
85 | $factory->create(Field::class, [])->willReturn($field); |
|
86 | ||
87 | $this->patchField($message); |
|
88 | } |
|
89 | ||
90 | function it_should_override_field( |
|
91 | Client $client, |
|
92 | ModelFactory $factory, |
|
93 | FieldOverrideMessage $message, |
|
94 | Field $field |
|
95 | ) { |
|
96 | $message->getId()->willReturn(5); |
|
97 | $message->getSiteId()->willReturn(1); |
|
98 | $message->build()->willReturn([]); |
|
99 | ||
100 | $method = 'GET'; |
|
101 | $path = 'sites/1/fields/5/override'; |
|
102 | ||
103 | $client->sendRequest($method, $path)->willReturn([]); |
|
104 | $client->sendRequest($method, $path)->shouldBeCalled(); |
|
105 | ||
106 | $factory->create(Field::class, [])->willReturn($field); |
|
107 | ||
108 | $this->overrideField($message); |
|
109 | } |
|
110 | } |
|
111 |
@@ 16-110 (lines=95) @@ | ||
13 | use Yproximite\Api\Message\Location\LocationPatchMessage; |
|
14 | use Yproximite\Api\Message\Location\LocationOverrideMessage; |
|
15 | ||
16 | class LocationServiceSpec extends ObjectBehavior |
|
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 |