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 DownloadSpec 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_has_a_package_with_all_languages() |
28
|
|
|
{ |
29
|
|
|
$this->setPackage('all.zip'); |
30
|
|
|
$this->getPackage()->shouldReturn('all.zip'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_has_a_package_with_one_language() |
34
|
|
|
{ |
35
|
|
|
$this->setPackage('fr.zip'); |
36
|
|
|
$this->getPackage()->shouldReturn('fr.zip'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_has_a_copy_destination() |
40
|
|
|
{ |
41
|
|
|
$this->setCopyDestination('/tmp/'); |
42
|
|
|
$this->getCopyDestination()->shouldReturn('/tmp/'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
function it_downloads_all_translations(HttpClient $http, Request $request, Response $response) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$this->setCopyDestination('/tmp'); |
48
|
|
|
$this->setPackage('all.zip'); |
49
|
|
|
$http->get('project/akeneo/download/all.zip?key=1234')->willReturn($request); |
50
|
|
|
$request->setResponseBody('/tmp/all.zip')->willReturn($request); |
51
|
|
|
$request->send()->willReturn($response); |
52
|
|
|
$response->getBody(true)->willReturn('bin'); |
53
|
|
|
$this->execute()->shouldBe('bin'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
function it_downloads_french_translations(HttpClient $http, Request $request, Response $response) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$this->setCopyDestination('/tmp'); |
59
|
|
|
$this->setPackage('fr.zip'); |
60
|
|
|
$http->get('project/akeneo/download/fr.zip?key=1234')->willReturn($request); |
61
|
|
|
$request->setResponseBody('/tmp/fr.zip')->willReturn($request); |
62
|
|
|
$request->send()->willReturn($response); |
63
|
|
|
$response->getBody(true)->willReturn('bin'); |
64
|
|
|
$this->execute()->shouldBe('bin'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
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.