it_should_not_allow_not_existing_file()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
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 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 AddFileSpec 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_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_add_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()->willReturn($content);
43
44
        $http->post('project/sylius/add-file?key=1234')->willReturn($response);
45
        $this->shouldThrow('\InvalidArgumentException')->duringExecute();
46
    }
47
48 View Code Duplication
    public function it_adds_a_file(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...
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...
49
    {
50
        $localPath = __DIR__ . '/../../../fixtures/messages.en.yml';
51
        $this->addTranslation($localPath, 'path/to/crowdin.yml');
52
        $content = '<?xml version="1.0" encoding="ISO-8859-1"?><success></success>';
53
        $response->getBody()->willReturn($content);
54
        $fakeResource = '[fake resource]';
55
        $fileReader->readTranslation(Argument::any())->willReturn($fakeResource);
56
        $http->post(
57
            'project/sylius/add-file?key=1234',
58
            ['multipart' => [
59
                [
60
                    'name'     => 'files[path/to/crowdin.yml]',
61
                    'contents' => $fakeResource
62
                ]
63
            ]]
64
        )->willReturn($response);
65
66
        $this->execute()->shouldBe($content);
67
    }
68
}
69