it_updates_some_translation_files()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 14

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
dl 19
loc 19
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 4
1
<?php
2
3
namespace spec\Akeneo\Crowdin\Api;
4
5
use Akeneo\Crowdin\Client;
6
use Akeneo\Crowdin\FileReader;
7
use GuzzleHttp\Client as HttpClient;
8
use GuzzleHttp\Psr7\Request;
9
use GuzzleHttp\Psr7\Response;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
13
class UpdateFileSpec extends ObjectBehavior
14
{
15
    public function let(Client $client, HttpClient $http, FileReader $fileReader)
16
    {
17
        $client->getHttpClient()->willReturn($http);
18
        $client->getProjectIdentifier()->willReturn('akeneo');
19
        $client->getProjectApiKey()->willReturn('1234');
20
        $this->beConstructedWith($client, $fileReader);
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_not_allow_not_existing_file()
29
    {
30
        $this->shouldThrow('\InvalidArgumentException')->duringAddTranslation('crowdin/path/file.yml', '/tmp/my-file.yml');
31
    }
32
33
    public function it_has_files()
34
    {
35
        $this->addTranslation(__DIR__ . '/../../../fixtures/messages.en.yml', 'crowdin/path/file.csv');
36
        $this->getTranslations()->shouldHaveCount(1);
37
    }
38
39
    public function it_should_not_allow_update_with_no_file(HttpClient $http, Request $request, Response $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
    {
41
        $content = '<xml></xml>';
42
        $response->getBody(true)->willReturn($content);
43
        $http->post('project/akeneo/update-file?key=1234')->willReturn($response);
44
        $this->shouldThrow('\InvalidArgumentException')->duringExecute();
45
    }
46
47 View Code Duplication
    public function it_updates_some_translation_files($fileReader, HttpClient $http, Request $request, Response $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
        $localPath = __DIR__ . '/../../../fixtures/messages.en.yml';
50
        $this->addTranslation($localPath, 'path/to/crowdin.yml');
51
        $content = '<xml></xml>';
52
        $response->getBody()->willReturn($content);
53
        $fakeResource = '[fake resource]';
54
        $fileReader->readTranslation(Argument::any())->willReturn($fakeResource);
55
        $http->post(
56
            'project/akeneo/update-file?key=1234',
57
            ['multipart' => [
58
                [
59
                    'name'      => "files[path/to/crowdin.yml]",
60
                    'contents'  => $fakeResource
61
                ]
62
            ]]
63
        )->willReturn($response);
64
        $this->execute()->shouldBe($content);
65
    }
66
67
    public function it_sends_additionnal_parameters(FileReader $fileReader, HttpClient $http, Request $request, Response $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
    {
69
        $fakeResource = '[fake resource]';
70
        $fileReader->readTranslation(Argument::any())->willReturn($fakeResource);
71
72
        $http->post(
73
            Argument::any(),
74
            ['multipart' => [
75
                'foo' => 'bar',
76
                [
77
                    'name'      => "files[path/to/crowdin.yml]",
78
                    'contents'  => $fakeResource
79
                ]
80
            ]]
81
        )->shouldBeCalled()->willReturn($response);
82
83
        $this->addTranslation(__DIR__ . '/../../../fixtures/messages.en.yml', 'path/to/crowdin.yml');
84
        $this->setParameters(['foo' => 'bar']);
85
        $this->execute();
86
    }
87
}
88