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\Media\Media; |
9
|
|
|
use Yproximite\Api\Factory\ModelFactory; |
10
|
|
|
use Yproximite\Api\Service\MediaService; |
11
|
|
|
use Yproximite\Api\Message\Media\MediaUploadMessage; |
12
|
|
|
use Yproximite\Api\Message\Media\MediaDynamicUrlMessage; |
13
|
|
|
|
14
|
|
|
class MediaServiceSpec extends ObjectBehavior |
15
|
|
|
{ |
16
|
|
|
function it_is_initializable() |
17
|
|
|
{ |
18
|
|
|
$this->shouldHaveType(MediaService::class); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
function let(Client $client, ModelFactory $factory) |
22
|
|
|
{ |
23
|
|
|
$this->beConstructedWith($client, $factory); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
function it_should_get_media_dynamic_url(Client $client, MediaDynamicUrlMessage $message) |
27
|
|
|
{ |
28
|
|
|
$message->getSiteId()->willReturn(1); |
29
|
|
|
$message->getId()->willReturn(2); |
30
|
|
|
$message->getFormat()->willReturn('Sw160'); |
31
|
|
|
|
32
|
|
|
$method = 'GET'; |
33
|
|
|
$path = 'sites/1/media/2/dynamic_url/Sw160'; |
34
|
|
|
|
35
|
|
|
$client->sendRequest($method, $path)->willReturn(['url' => 'bar']); |
36
|
|
|
$client->sendRequest($method, $path)->shouldBeCalled(); |
37
|
|
|
|
38
|
|
|
$this->getMediaDynamicUrl($message)->shouldReturn('bar'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function it_should_upload_medias( |
42
|
|
|
Client $client, |
43
|
|
|
ModelFactory $factory, |
44
|
|
|
MediaUploadMessage $message |
45
|
|
|
) { |
46
|
|
|
$method = 'POST'; |
47
|
|
|
$path = 'sites/1/uploads/media'; |
48
|
|
|
$body = null; |
49
|
|
|
$headers = ['foo' => 'bar']; |
50
|
|
|
|
51
|
|
|
$message->getSiteId()->willReturn(1); |
52
|
|
|
$message->build()->willReturn($body); |
53
|
|
|
$message->buildHeaders()->willReturn($headers); |
54
|
|
|
$message->initBuilder()->shouldBeCalled(); |
55
|
|
|
|
56
|
|
|
$client->sendRequest($method, $path, $body, $headers)->willReturn([]); |
57
|
|
|
$client->sendRequest($method, $path, $body, $headers)->shouldBeCalled(); |
58
|
|
|
|
59
|
|
|
$factory->createMany(Media::class, [])->willReturn([]); |
60
|
|
|
|
61
|
|
|
$this->uploadMedias($message); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|