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\Request; |
8
|
|
|
use Guzzle\Http\Message\Response; |
9
|
|
|
use PhpSpec\ObjectBehavior; |
10
|
|
|
use Prophecy\Argument; |
11
|
|
|
|
12
|
|
|
class UpdateFileSpec extends ObjectBehavior |
13
|
|
|
{ |
14
|
|
|
public 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
|
|
|
public function it_should_be_an_api() |
23
|
|
|
{ |
24
|
|
|
$this->shouldBeAnInstanceOf('Akeneo\Crowdin\Api\AbstractApi'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public 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
|
|
|
public 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
|
|
|
public 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
|
|
View Code Duplication |
public 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
|
|
|
[], |
56
|
|
|
["files[crowdin/path/file.yml]" => '@'.__DIR__ . '/../../../fixtures/messages.en.yml'] |
57
|
|
|
)->willReturn($request); |
58
|
|
|
$this->execute()->shouldBe($content); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public 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(), [ |
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(['foo' => 'bar']); |
72
|
|
|
$this->execute(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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.