AbstractProviderFactoryTestCase.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Translation\Test;
  11. use PHPUnit\Framework\Attributes\DataProvider;
  12. use PHPUnit\Framework\TestCase;
  13. use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
  14. use Symfony\Component\Translation\Provider\Dsn;
  15. use Symfony\Component\Translation\Provider\ProviderFactoryInterface;
  16. abstract class AbstractProviderFactoryTestCase extends TestCase
  17. {
  18. abstract public function createFactory(): ProviderFactoryInterface;
  19. /**
  20. * @return iterable<array{0: bool, 1: string}>
  21. */
  22. abstract public static function supportsProvider(): iterable;
  23. /**
  24. * @return iterable<array{0: string, 1: string}>
  25. */
  26. abstract public static function createProvider(): iterable;
  27. /**
  28. * @return iterable<array{0: string, 1?: string|null}>
  29. */
  30. abstract public static function unsupportedSchemeProvider(): iterable;
  31. /**
  32. * @dataProvider supportsProvider
  33. */
  34. #[DataProvider('supportsProvider')]
  35. public function testSupports(bool $expected, string $dsn)
  36. {
  37. $factory = $this->createFactory();
  38. $this->assertSame($expected, $factory->supports(new Dsn($dsn)));
  39. }
  40. /**
  41. * @dataProvider createProvider
  42. */
  43. #[DataProvider('createProvider')]
  44. public function testCreate(string $expected, string $dsn)
  45. {
  46. $factory = $this->createFactory();
  47. $provider = $factory->create(new Dsn($dsn));
  48. $this->assertSame($expected, (string) $provider);
  49. }
  50. /**
  51. * @dataProvider unsupportedSchemeProvider
  52. */
  53. #[DataProvider('unsupportedSchemeProvider')]
  54. public function testUnsupportedSchemeException(string $dsn, ?string $message = null)
  55. {
  56. $factory = $this->createFactory();
  57. $dsn = new Dsn($dsn);
  58. $this->expectException(UnsupportedSchemeException::class);
  59. if (null !== $message) {
  60. $this->expectExceptionMessage($message);
  61. }
  62. $factory->create($dsn);
  63. }
  64. }