1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Akeneo\Crowdin\Api; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use Prophecy\Argument; |
7
|
|
|
use Akeneo\Crowdin\Client; |
8
|
|
|
use Guzzle\Http\Client as HttpClient; |
9
|
|
|
use Guzzle\Http\Message\Response; |
10
|
|
|
use Guzzle\Http\Message\Request; |
11
|
|
|
|
12
|
|
|
class UpdateFileSpec extends ObjectBehavior |
13
|
|
|
{ |
14
|
|
|
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
|
|
|
function it_should_be_an_api() |
23
|
|
|
{ |
24
|
|
|
$this->shouldBeAnInstanceOf('Akeneo\Crowdin\Api\AbstractApi'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
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
|
|
|
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
|
|
|
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 |
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
|
|
|
array(), |
56
|
|
|
array("files[crowdin/path/file.yml]" => '@'.__DIR__ . '/../../../fixtures/messages.en.yml') |
57
|
|
|
)->willReturn($request); |
58
|
|
|
$this->execute()->shouldBe($content); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
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(), array( |
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(array('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.