IncompleteDsnTestTrait.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 Symfony\Component\Translation\Exception\IncompleteDsnException;
  13. use Symfony\Component\Translation\Provider\Dsn;
  14. trait IncompleteDsnTestTrait
  15. {
  16. /**
  17. * @return iterable<array{0: string, 1?: string|null}>
  18. */
  19. abstract public static function incompleteDsnProvider(): iterable;
  20. /**
  21. * @dataProvider incompleteDsnProvider
  22. */
  23. #[DataProvider('incompleteDsnProvider')]
  24. public function testIncompleteDsnException(string $dsn, ?string $message = null)
  25. {
  26. $factory = $this->createFactory();
  27. $dsn = new Dsn($dsn);
  28. $this->expectException(IncompleteDsnException::class);
  29. if (null !== $message) {
  30. $this->expectExceptionMessage($message);
  31. }
  32. $factory->create($dsn);
  33. }
  34. }