ProviderFactoryTestCase.php
84 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Translation\Test; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\PHPUnit\Framework\TestCase; |
| 5 | use MailPoetVendor\Psr\Log\LoggerInterface; |
| 6 | use MailPoetVendor\Symfony\Component\HttpClient\MockHttpClient; |
| 7 | use MailPoetVendor\Symfony\Component\Translation\Dumper\XliffFileDumper; |
| 8 | use MailPoetVendor\Symfony\Component\Translation\Exception\IncompleteDsnException; |
| 9 | use MailPoetVendor\Symfony\Component\Translation\Exception\UnsupportedSchemeException; |
| 10 | use MailPoetVendor\Symfony\Component\Translation\Loader\LoaderInterface; |
| 11 | use MailPoetVendor\Symfony\Component\Translation\Provider\Dsn; |
| 12 | use MailPoetVendor\Symfony\Component\Translation\Provider\ProviderFactoryInterface; |
| 13 | use MailPoetVendor\Symfony\Contracts\HttpClient\HttpClientInterface; |
| 14 | abstract class ProviderFactoryTestCase extends TestCase |
| 15 | { |
| 16 | protected $client; |
| 17 | protected $logger; |
| 18 | protected $defaultLocale; |
| 19 | protected $loader; |
| 20 | protected $xliffFileDumper; |
| 21 | public abstract function createFactory() : ProviderFactoryInterface; |
| 22 | public static abstract function supportsProvider() : iterable; |
| 23 | public static abstract function createProvider() : iterable; |
| 24 | public static function unsupportedSchemeProvider() : iterable |
| 25 | { |
| 26 | return []; |
| 27 | } |
| 28 | public static function incompleteDsnProvider() : iterable |
| 29 | { |
| 30 | return []; |
| 31 | } |
| 32 | public function testSupports(bool $expected, string $dsn) |
| 33 | { |
| 34 | $factory = $this->createFactory(); |
| 35 | $this->assertSame($expected, $factory->supports(new Dsn($dsn))); |
| 36 | } |
| 37 | public function testCreate(string $expected, string $dsn) |
| 38 | { |
| 39 | $factory = $this->createFactory(); |
| 40 | $provider = $factory->create(new Dsn($dsn)); |
| 41 | $this->assertSame($expected, (string) $provider); |
| 42 | } |
| 43 | public function testUnsupportedSchemeException(string $dsn, ?string $message = null) |
| 44 | { |
| 45 | $factory = $this->createFactory(); |
| 46 | $dsn = new Dsn($dsn); |
| 47 | $this->expectException(UnsupportedSchemeException::class); |
| 48 | if (null !== $message) { |
| 49 | $this->expectExceptionMessage($message); |
| 50 | } |
| 51 | $factory->create($dsn); |
| 52 | } |
| 53 | public function testIncompleteDsnException(string $dsn, ?string $message = null) |
| 54 | { |
| 55 | $factory = $this->createFactory(); |
| 56 | $dsn = new Dsn($dsn); |
| 57 | $this->expectException(IncompleteDsnException::class); |
| 58 | if (null !== $message) { |
| 59 | $this->expectExceptionMessage($message); |
| 60 | } |
| 61 | $factory->create($dsn); |
| 62 | } |
| 63 | protected function getClient() : HttpClientInterface |
| 64 | { |
| 65 | return $this->client ?? ($this->client = new MockHttpClient()); |
| 66 | } |
| 67 | protected function getLogger() : LoggerInterface |
| 68 | { |
| 69 | return $this->logger ?? ($this->logger = $this->createMock(LoggerInterface::class)); |
| 70 | } |
| 71 | protected function getDefaultLocale() : string |
| 72 | { |
| 73 | return $this->defaultLocale ?? ($this->defaultLocale = 'en'); |
| 74 | } |
| 75 | protected function getLoader() : LoaderInterface |
| 76 | { |
| 77 | return $this->loader ?? ($this->loader = $this->createMock(LoaderInterface::class)); |
| 78 | } |
| 79 | protected function getXliffFileDumper() : XliffFileDumper |
| 80 | { |
| 81 | return $this->xliffFileDumper ?? ($this->xliffFileDumper = $this->createMock(XliffFileDumper::class)); |
| 82 | } |
| 83 | } |
| 84 |