Completed
Push — add-branch ( 88ebbf...f15293 )
by
unknown
02:08
created

it_updates_some_translation_files()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

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 11
nc 1
nop 3
1
<?php
2
3
namespace spec\Crowdin\Api;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
use 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('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
    function it_updates_some_translation_files(HttpClient $http, Request $request, Response $response)
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