| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the Symfony package.
|
|
|
5 |
*
|
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
7 |
*
|
|
|
8 |
* For the full copyright and license information, please view the LICENSE
|
|
|
9 |
* file that was distributed with this source code.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\Translation\Test;
|
|
|
13 |
|
|
|
14 |
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
15 |
use PHPUnit\Framework\TestCase;
|
|
|
16 |
use Psr\Log\LoggerInterface;
|
|
|
17 |
use Symfony\Component\HttpClient\MockHttpClient;
|
|
|
18 |
use Symfony\Component\Translation\Dumper\XliffFileDumper;
|
|
|
19 |
use Symfony\Component\Translation\Loader\LoaderInterface;
|
|
|
20 |
use Symfony\Component\Translation\Provider\ProviderInterface;
|
|
|
21 |
use Symfony\Component\Translation\TranslatorBagInterface;
|
|
|
22 |
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* A test case to ease testing a translation provider.
|
|
|
26 |
*
|
|
|
27 |
* @author Mathieu Santostefano <msantostefano@protonmail.com>
|
|
|
28 |
*
|
|
|
29 |
* @internal
|
|
|
30 |
*/
|
|
|
31 |
abstract class ProviderTestCase extends TestCase
|
|
|
32 |
{
|
|
|
33 |
protected HttpClientInterface $client;
|
|
|
34 |
protected LoggerInterface|MockObject $logger;
|
|
|
35 |
protected string $defaultLocale;
|
|
|
36 |
protected LoaderInterface|MockObject $loader;
|
|
|
37 |
protected XliffFileDumper|MockObject $xliffFileDumper;
|
|
|
38 |
protected TranslatorBagInterface|MockObject $translatorBag;
|
|
|
39 |
|
| 688 |
lars |
40 |
abstract public static function createProvider(HttpClientInterface $client, LoaderInterface $loader, LoggerInterface $logger, string $defaultLocale, string $endpoint): ProviderInterface;
|
| 148 |
lars |
41 |
|
|
|
42 |
/**
|
| 688 |
lars |
43 |
* @return iterable<array{0: ProviderInterface, 1: string}>
|
| 148 |
lars |
44 |
*/
|
| 688 |
lars |
45 |
abstract public static function toStringProvider(): iterable;
|
| 148 |
lars |
46 |
|
|
|
47 |
/**
|
|
|
48 |
* @dataProvider toStringProvider
|
|
|
49 |
*/
|
|
|
50 |
public function testToString(ProviderInterface $provider, string $expected)
|
|
|
51 |
{
|
|
|
52 |
$this->assertSame($expected, (string) $provider);
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
protected function getClient(): MockHttpClient
|
|
|
56 |
{
|
|
|
57 |
return $this->client ??= new MockHttpClient();
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
protected function getLoader(): LoaderInterface
|
|
|
61 |
{
|
|
|
62 |
return $this->loader ??= $this->createMock(LoaderInterface::class);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
protected function getLogger(): LoggerInterface
|
|
|
66 |
{
|
|
|
67 |
return $this->logger ??= $this->createMock(LoggerInterface::class);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
protected function getDefaultLocale(): string
|
|
|
71 |
{
|
|
|
72 |
return $this->defaultLocale ??= 'en';
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
protected function getXliffFileDumper(): XliffFileDumper
|
|
|
76 |
{
|
|
|
77 |
return $this->xliffFileDumper ??= $this->createMock(XliffFileDumper::class);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
protected function getTranslatorBag(): TranslatorBagInterface
|
|
|
81 |
{
|
|
|
82 |
return $this->translatorBag ??= $this->createMock(TranslatorBagInterface::class);
|
|
|
83 |
}
|
|
|
84 |
}
|