Debian Codegraph @

lib/3rdParty/composer/symfony/translation/Test/AbstractProviderFactoryTestCase.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\TestCase;
16 use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
17 use Symfony\Component\Translation\Provider\Dsn;
18 use Symfony\Component\Translation\Provider\ProviderFactoryInterface;
19
20 abstract class AbstractProviderFactoryTestCase extends TestCase
21 {
22 abstract public function createFactory(): ProviderFactoryInterface;
23
24 /**
25 * @return iterable<array{0: bool, 1: string}>
26 */
27 abstract public static function supportsProvider(): iterable;
28
29 /**
30 * @return iterable<array{0: string, 1: string}>
31 */
32 abstract public static function createProvider(): iterable;
33
34 /**
35 * @return iterable<array{0: string, 1?: string|null}>
36 */
37 abstract public static function unsupportedSchemeProvider(): iterable;
38
39 /**
40 * @dataProvider supportsProvider
41 */
42 #[DataProvider('supportsProvider')]
43 public function testSupports(bool $expected, string $dsn)
44 {
45 $factory = $this->createFactory();
46
47 $this->assertSame($expected, $factory->supports(new Dsn($dsn)));
48 }
49
50 /**
51 * @dataProvider createProvider
52 */
53 #[DataProvider('createProvider')]
54 public function testCreate(string $expected, string $dsn)
55 {
56 $factory = $this->createFactory();
57 $provider = $factory->create(new Dsn($dsn));
58
59 $this->assertSame($expected, (string) $provider);
60 }
61
62 /**
63 * @dataProvider unsupportedSchemeProvider
64 */
65 #[DataProvider('unsupportedSchemeProvider')]
66 public function testUnsupportedSchemeException(string $dsn, ?string $message = null)
67 {
68 $factory = $this->createFactory();
69
70 $dsn = new Dsn($dsn);
71
72 $this->expectException(UnsupportedSchemeException::class);
73 if (null !== $message) {
74 $this->expectExceptionMessage($message);
75 }
76
77 $factory->create($dsn);
78 }
79 }