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

it_should_not_allow_not_existing_file()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Message\Response;
8
use Guzzle\Http\Message\Request;
9
use PhpSpec\ObjectBehavior;
10
11
class AddFileSpec extends ObjectBehavior
12
{
13
    function let(Client $client, HttpClient $http)
14
    {
15
        $client->getHttpClient()->willReturn($http);
16
        $client->getProjectIdentifier()->willReturn('sylius');
17
        $client->getProjectApiKey()->willReturn('1234');
18
        $this->beConstructedWith($client);
19
    }
20
21
    function it_should_be_an_api()
22
    {
23
        $this->shouldBeAnInstanceOf('Akeneo\Crowdin\Api\AbstractApi');
24
    }
25
26
    function it_should_not_allow_not_existing_file()
27
    {
28
        $this->shouldThrow('\InvalidArgumentException')->duringAddTranslation('crowdin/path/file.yml', '/tmp/my-file.yml');
29
    }
30
31
    function it_has_files()
32
    {
33
        $this->addTranslation(__DIR__ . '/../../../fixtures/messages.en.yml', 'crowdin/path/file.csv');
34
        $this->getTranslations()->shouldHaveCount(1);
35
    }
36
37
    function it_should_not_add_with_no_file(HttpClient $http, Request $request, Response $response)
38
    {
39
        $content = '<xml></xml>';
40
        $response->getBody(true)->willReturn($content);
41
        $request->send()->willReturn($response);
42
43
        $http->post('project/sylius/add-file?key=1234')->willReturn($request);
44
        $this->shouldThrow('\InvalidArgumentException')->duringExecute();
45
    }
46
47 View Code Duplication
    function it_adds_a_file(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', 'path/to/crowdin.yml');
50
        $content = '<?xml version="1.0" encoding="ISO-8859-1"?><success></success>';
51
        $response->getBody(true)->willReturn($content);
52
        $request->send()->willReturn($response);
53
        $http->post(
54
            'project/sylius/add-file?key=1234',
55
            array(),
56
            array('files[path/to/crowdin.yml]' => '@' . __DIR__ . '/../../../fixtures/messages.en.yml')
57
        )->willReturn($request);
58
59
        $this->execute()->shouldBe($content);
60
    }
61
}