Completed
Pull Request — master (#31)
by
unknown
03:24
created

UploadTranslationSpec   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 7
Bugs 1 Features 3
Metric Value
wmc 10
c 7
b 1
f 3
lcom 1
cbo 6
dl 0
loc 98
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_should_be_an_api() 0 4 1
A it_should_not_allow_not_existing_translation() 0 4 1
A it_has_translations() 0 5 1
A it_does_not_import_duplicates_by_default() 0 4 1
A it_does_not_import_equal_suggestions_by_default() 0 4 1
A it_does_not_auto_approve_imported_by_default() 0 4 1
A it_should_not_allow_upload_with_no_translation() 0 9 1
A it_should_not_allow_upload_with_no_locale() 0 9 1
B it_uploads_some_translations() 0 36 1
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 UploadTranslationSpec extends ObjectBehavior
14
{
15
    public function let(Client $client, HttpClient $http, FileReader $fileReader)
16
    {
17
        $client->getHttpClient()->willReturn($http);
18
        $client->getProjectIdentifier()->willReturn('sylius');
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_translation()
29
    {
30
        $this->shouldThrow('\InvalidArgumentException')->duringAddTranslation('crowdin/path/file.yml', '/tmp/my-file.yml');
31
    }
32
33
    public function it_has_translations()
34
    {
35
        $this->addTranslation('crowdin/path/file.csv',  'spec/fixtures/messages.en.yml');
36
        $this->getTranslations()->shouldHaveCount(1);
37
    }
38
39
    public function it_does_not_import_duplicates_by_default()
40
    {
41
        $this->areDuplicatesImported()->shouldBe(false);
42
    }
43
44
    public function it_does_not_import_equal_suggestions_by_default()
45
    {
46
        $this->areEqualSuggestionsImported()->shouldBe(false);
47
    }
48
49
    public function it_does_not_auto_approve_imported_by_default()
50
    {
51
        $this->areImportsAutoApproved()->shouldBe(false);
52
    }
53
54
    public function it_should_not_allow_upload_with_no_translation(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...
55
    {
56
        $this->setLocale('fr');
57
        $content = '<xml></xml>';
58
        $response->getBody()->willReturn($content);
59
        $http->post('project/sylius/upload-translation?key=1234')->willReturn($response);
60
61
        $this->shouldThrow('\InvalidArgumentException')->duringExecute();
62
    }
63
64
    public function it_should_not_allow_upload_with_no_locale(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...
65
    {
66
        $this->addTranslation('crowdin/path/file.yml',  'spec/fixtures/messages.en.yml');
67
        $content = '<xml></xml>';
68
        $response->getBody()->willReturn($content);
69
        $http->post('project/sylius/upload-translation?key=1234')->willReturn($response);
70
71
        $this->shouldThrow('\InvalidArgumentException')->duringExecute();
72
    }
73
74
    public function it_uploads_some_translations(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...
75
    {
76
        $localPath = __DIR__ . '/../../../fixtures/messages.en.yml';
77
        $this->addTranslation($localPath, 'spec/fixtures/messages.en.yml');
78
        $this->setLocale('fr');
79
        $content = '<xml></xml>';
80
        $response->getBody()->willReturn($content);
81
        $fakeResource = '[fake resource]';
82
        $fileReader->readStream(Argument::any())->willReturn($fakeResource);
83
        $http->post(
84
            'project/sylius/upload-translation?key=1234',
85
            ['multipart' => [
86
                [
87
                    'name'      => 'import_duplicates',
88
                    'contents'  => 0
89
                ],
90
                [
91
                    'name'      => 'import_eq_suggestions',
92
                    'contents'  => 0
93
                ],
94
                [
95
                    'name'      => 'auto_approve_imported',
96
                    'contents'  => 0
97
                ],
98
                [
99
                    'name'      => 'language',
100
                    'contents'  => 'fr'
101
                ],
102
                [
103
                    'name'      => 'files['.$localPath.']',
104
                    'contents'  => $fakeResource,
105
                ],
106
            ]]
107
        )->willReturn($response);
108
        $this->execute()->shouldBe($content);
109
    }
110
}
111