Completed
Push — master ( eb5568...bc1b58 )
by Nicolas
9s
created

UpdateFileSpec::it_sends_additionnal_parameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 9
nc 1
nop 3
1
<?php
2
3
namespace spec\Akeneo\Crowdin\Api;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
use Akeneo\Crowdin\Client;
8
use Guzzle\Http\Client as HttpClient;
9
use Guzzle\Http\Message\Response;
10
use Guzzle\Http\Message\Request;
11
12
class UpdateFileSpec extends ObjectBehavior
13
{
14
    function let(Client $client, HttpClient $http)
15
    {
16
        $client->getHttpClient()->willReturn($http);
17
        $client->getProjectIdentifier()->willReturn('akeneo');
18
        $client->getProjectApiKey()->willReturn('1234');
19
        $this->beConstructedWith($client);
20
    }
21
22
    function it_should_be_an_api()
23
    {
24
        $this->shouldBeAnInstanceOf('Akeneo\Crowdin\Api\AbstractApi');
25
    }
26
27
    function it_should_not_allow_not_existing_file()
28
    {
29
        $this->shouldThrow('\InvalidArgumentException')->duringAddTranslation('crowdin/path/file.yml', '/tmp/my-file.yml');
30
    }
31
32
    function it_has_files()
33
    {
34
        $this->addTranslation(__DIR__ . '/../../../fixtures/messages.en.yml', 'crowdin/path/file.csv');
35
        $this->getTranslations()->shouldHaveCount(1);
36
    }
37
38
    function it_should_not_allow_update_with_no_file(HttpClient $http, Request $request, Response $response)
39
    {
40
        $content = '<xml></xml>';
41
        $response->getBody(true)->willReturn($content);
42
        $request->send()->willReturn($response);
43
        $http->post('project/akeneo/update-file?key=1234')->willReturn($request);
44
        $this->shouldThrow('\InvalidArgumentException')->duringExecute();
45
    }
46
47 View Code Duplication
    function it_updates_some_translation_files(HttpClient $http, Request $request, Response $response)
0 ignored issues
show
Duplication introduced by
This method 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...
48
    {
49
        $this->addTranslation(__DIR__ . '/../../../fixtures/messages.en.yml', 'crowdin/path/file.yml');
50
        $content = '<xml></xml>';
51
        $response->getBody(true)->willReturn($content);
52
        $request->send()->willReturn($response);
53
        $http->post(
54
            'project/akeneo/update-file?key=1234',
55
            array(),
56
            array("files[crowdin/path/file.yml]" => '@'.__DIR__ . '/../../../fixtures/messages.en.yml')
57
        )->willReturn($request);
58
        $this->execute()->shouldBe($content);
59
    }
60
61
    function it_sends_additionnal_parameters(HttpClient $http, Request $request, Response $response)
62
    {
63
        $request->send()->willReturn($response);
64
65
        $http->post(Argument::any(), Argument::any(), array(
66
            "files[crowdin/path/file.yml]" => '@'.__DIR__ . '/../../../fixtures/messages.en.yml',
67
            'foo' => 'bar',
68
        ))->shouldBeCalled()->willReturn($request);
69
70
        $this->addTranslation(__DIR__ . '/../../../fixtures/messages.en.yml', 'crowdin/path/file.yml');
71
        $this->setParameters(array('foo' => 'bar'));
72
        $this->execute();
73
    }
74
}
75