ProviderFactoryTestCase.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\MockObject\MockObject;
  12. use Psr\Log\LoggerInterface;
  13. use Symfony\Component\HttpClient\MockHttpClient;
  14. use Symfony\Component\Translation\Dumper\XliffFileDumper;
  15. use Symfony\Component\Translation\Loader\LoaderInterface;
  16. use Symfony\Component\Translation\TranslatorBagInterface;
  17. use Symfony\Contracts\HttpClient\HttpClientInterface;
  18. /**
  19. * A test case to ease testing a translation provider factory.
  20. *
  21. * @author Mathieu Santostefano <msantostefano@protonmail.com>
  22. *
  23. * @deprecated since Symfony 7.2, use AbstractProviderFactoryTestCase instead
  24. */
  25. abstract class ProviderFactoryTestCase extends AbstractProviderFactoryTestCase
  26. {
  27. use IncompleteDsnTestTrait;
  28. protected HttpClientInterface $client;
  29. protected LoggerInterface|MockObject $logger;
  30. protected string $defaultLocale;
  31. protected LoaderInterface|MockObject $loader;
  32. protected XliffFileDumper|MockObject $xliffFileDumper;
  33. protected TranslatorBagInterface|MockObject $translatorBag;
  34. /**
  35. * @return iterable<array{0: string, 1?: string|null}>
  36. */
  37. public static function unsupportedSchemeProvider(): iterable
  38. {
  39. return [];
  40. }
  41. /**
  42. * @return iterable<array{0: string, 1?: string|null}>
  43. */
  44. public static function incompleteDsnProvider(): iterable
  45. {
  46. return [];
  47. }
  48. protected function getClient(): HttpClientInterface
  49. {
  50. return $this->client ??= new MockHttpClient();
  51. }
  52. protected function getLogger(): LoggerInterface
  53. {
  54. return $this->logger ??= $this->createMock(LoggerInterface::class);
  55. }
  56. protected function getDefaultLocale(): string
  57. {
  58. return $this->defaultLocale ??= 'en';
  59. }
  60. protected function getLoader(): LoaderInterface
  61. {
  62. return $this->loader ??= $this->createMock(LoaderInterface::class);
  63. }
  64. protected function getXliffFileDumper(): XliffFileDumper
  65. {
  66. return $this->xliffFileDumper ??= $this->createMock(XliffFileDumper::class);
  67. }
  68. protected function getTranslatorBag(): TranslatorBagInterface
  69. {
  70. return $this->translatorBag ??= $this->createMock(TranslatorBagInterface::class);
  71. }
  72. }