Debian Codegraph @

lib/3rdParty/composer/symfony/translation/Test/ProviderTestCase.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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\Attributes\DataProvider;
15 use PHPUnit\Framework\MockObject\MockObject;
16 use PHPUnit\Framework\TestCase;
17 use Psr\Log\LoggerInterface;
18 use Psr\Log\NullLogger;
19 use Symfony\Component\HttpClient\MockHttpClient;
20 use Symfony\Component\Translation\Dumper\XliffFileDumper;
21 use Symfony\Component\Translation\Loader\ArrayLoader;
22 use Symfony\Component\Translation\Loader\LoaderInterface;
23 use Symfony\Component\Translation\Provider\ProviderInterface;
24 use Symfony\Component\Translation\TranslatorBag;
25 use Symfony\Component\Translation\TranslatorBagInterface;
26 use Symfony\Contracts\HttpClient\HttpClientInterface;
27
28 /**
29 * A test case to ease testing a translation provider.
30 *
31 * @author Mathieu Santostefano <[email protected]>
32 */
33 abstract class ProviderTestCase extends TestCase
34 {
35 protected HttpClientInterface $client;
36 protected LoggerInterface|MockObject $logger;
37 protected string $defaultLocale;
38 protected LoaderInterface|MockObject $loader;
39 protected XliffFileDumper|MockObject $xliffFileDumper;
40 protected TranslatorBagInterface|MockObject $translatorBag;
41
42 abstract public static function createProvider(HttpClientInterface $client, LoaderInterface $loader, LoggerInterface $logger, string $defaultLocale, string $endpoint): ProviderInterface;
43
44 /**
45 * @return iterable<array{0: ProviderInterface, 1: string}>
46 */
47 abstract public static function toStringProvider(): iterable;
48
49 /**
50 * @dataProvider toStringProvider
51 */
52 #[DataProvider('toStringProvider')]
53 public function testToString(ProviderInterface $provider, string $expected)
54 {
55 $this->assertSame($expected, (string) $provider);
56 }
57
58 protected function getClient(): MockHttpClient
59 {
60 return $this->client ??= new MockHttpClient();
61 }
62
63 protected function getLoader(): LoaderInterface
64 {
65 return $this->loader ??= new ArrayLoader();
66 }
67
68 protected function getLogger(): LoggerInterface
69 {
70 return $this->logger ??= new NullLogger();
71 }
72
73 protected function getDefaultLocale(): string
74 {
75 return $this->defaultLocale ??= 'en';
76 }
77
78 protected function getXliffFileDumper(): XliffFileDumper
79 {
80 return $this->xliffFileDumper ??= new XliffFileDumper();
81 }
82
83 protected function getTranslatorBag(): TranslatorBagInterface
84 {
85 return $this->translatorBag ??= new TranslatorBag();
86 }
87 }