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) |
|
|
|
|
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) |
|
|
|
|
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
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.