1 | <?php |
||
28 | class LocoTest extends TestCase |
||
29 | { |
||
30 | /** |
||
31 | * @var LocoClient |
||
32 | */ |
||
33 | private $client; |
||
34 | |||
35 | /** |
||
36 | * @var HttpClient|MockObject |
||
37 | */ |
||
38 | private $httpClient; |
||
39 | |||
40 | /** |
||
41 | * @var Hydrator|MockObject |
||
42 | */ |
||
43 | private $hydrator; |
||
44 | |||
45 | protected function setUp(): void |
||
46 | { |
||
47 | $this->httpClient = $this->createMock(HttpClient::class); |
||
48 | $this->hydrator = $this->createMock(Hydrator::class); |
||
49 | $this->client = new LocoClient($this->httpClient, $this->hydrator); |
||
50 | } |
||
51 | |||
52 | public function testOverridesTheDefaultLocaleWhenUsingTranslationKeys(): void |
||
53 | { |
||
54 | $locoProject = new LocoProject('main', ['api_key' => 'FooBar', 'index_parameter' => 'id']); |
||
55 | $loco = new Loco($this->client, [$locoProject]); |
||
56 | |||
57 | $catalogue = new MessageCatalogue('nl', []); |
||
58 | |||
59 | $response = $this->createMock(ResponseInterface::class); |
||
60 | $this->httpClient |
||
61 | ->method('sendRequest') |
||
62 | ->with( |
||
63 | $this->callback( |
||
64 | // Capture the request body so we can make assertions on it later on |
||
65 | function (RequestInterface $argument) use (&$body): bool { |
||
66 | $body = $argument->getBody()->__toString(); |
||
67 | |||
68 | return true; |
||
69 | } |
||
70 | ) |
||
71 | ) |
||
72 | ->willReturn($response); |
||
73 | |||
74 | $stream = $this->createMock(StreamInterface::class); |
||
75 | $response->method('getBody')->willReturn($stream); |
||
76 | $stream->method('__toString')->willReturn('{}'); |
||
77 | $response->method('getStatusCode')->willReturn(201); |
||
78 | |||
79 | $loco->import($catalogue); |
||
80 | |||
81 | $this->assertStringContainsString( |
||
82 | '<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="x-id" trgLang="nl">', |
||
83 | $body |
||
84 | ); |
||
85 | } |
||
86 | } |
||
87 |