Completed
Push — GIT-5 ( f8a721 )
by
unknown
01:43
created

ChangeDirectorySpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 6
dl 0
loc 62
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_should_be_an_api() 0 4 1
A it_should_have_a_name() 0 4 1
A it_should_set_name() 0 15 1
B it_should_set_data() 0 25 1
1
<?php
2
3
namespace spec\Akeneo\Crowdin\Api;
4
5
use Akeneo\Crowdin\Client;
6
use Guzzle\Http\Client as HttpClient;
7
use Guzzle\Http\EntityBodyInterface;
8
use Guzzle\Http\Message\Request;
9
use Guzzle\Http\Message\Response;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
13
class ChangeDirectorySpec extends ObjectBehavior
14
{
15
    public function let(Client $client, HttpClient $http)
16
    {
17
        $client->getHttpClient()->willReturn($http);
18
        $client->getProjectIdentifier()->willReturn('sylius');
19
        $client->getProjectApiKey()->willReturn('1234');
20
        $this->beConstructedWith($client);
21
    }
22
23
    public function it_should_be_an_api()
24
    {
25
        $this->shouldBeAnInstanceOf('Akeneo\Crowdin\Api\AbstractApi');
26
    }
27
28
    public function it_should_have_a_name()
29
    {
30
        $this->shouldThrow('\InvalidArgumentException')->during('execute', []);
31
    }
32
33
    public function it_should_set_name(
34
        $http,
35
        Request $request,
36
        Response $response,
37
        EntityBodyInterface $body
38
    ) {
39
        $this->setName('myname');
40
        $path = 'project/sylius/change-directory?key=1234';
41
        $data = ['name' => 'myname'];
42
        $http->post($path, [], $data)->willReturn($request);
43
        $request->send()->willReturn($response);
44
        $response->getBody(Argument::any())->willReturn($body);
45
46
        $this->execute()->shouldReturn($body);
47
    }
48
49
    public function it_should_set_data(
50
        $http,
51
        Request $request,
52
        Response $response,
53
        EntityBodyInterface $body
54
    ) {
55
        $this->setName('myName');
56
        $this->setBranch('myBranch');
57
        $this->setExportPattern('myExportPattern');
58
        $this->setTitle('myTitle');
59
        $this->setNewName('myNewName');
60
        $path = 'project/sylius/change-directory?key=1234';
61
        $data = [
62
            'name'           => 'myName',
63
            'branch'         => 'myBranch',
64
            'export_pattern' => 'myExportPattern',
65
            'title'          => 'myTitle',
66
            'new_name'       => 'myNewName'
67
        ];
68
        $http->post($path, [], $data)->willReturn($request);
69
        $request->send()->willReturn($response);
70
        $response->getBody(Argument::any())->willReturn($body);
71
72
        $this->execute()->shouldReturn($body);
73
    }
74
}
75