jkabat /
sendy-bundle
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | declare(strict_types=1); |
||||||
| 4 | |||||||
| 5 | namespace Tests\DependencyInjection; |
||||||
| 6 | |||||||
| 7 | use PHPUnit\Framework\TestCase; |
||||||
| 8 | use Sendy\SendyBundle\DependencyInjection\SendyExtension; |
||||||
| 9 | use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
||||||
| 10 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||||||
| 11 | use Symfony\Component\Yaml\Parser; |
||||||
| 12 | |||||||
| 13 | final class SendyExtensionTest extends TestCase |
||||||
| 14 | { |
||||||
| 15 | public function testConfigLoadThrowsExceptionUnlessApiKeySet(): void |
||||||
| 16 | { |
||||||
| 17 | self::expectException(InvalidConfigurationException::class); |
||||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||||
| 18 | |||||||
| 19 | $config = $this->getEmptyConfig(); |
||||||
| 20 | unset($config['api_key']); |
||||||
| 21 | $extension = new SendyExtension(); |
||||||
| 22 | $extension->load([$config], new ContainerBuilder()); |
||||||
| 23 | } |
||||||
| 24 | |||||||
| 25 | public function testConfigLoadThrowsExceptionUnlessApiHostSet(): void |
||||||
| 26 | { |
||||||
| 27 | self::expectException(InvalidConfigurationException::class); |
||||||
|
0 ignored issues
–
show
The method
PHPUnit\Framework\TestCase::expectException() is not static, but was called statically.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 28 | |||||||
| 29 | $config = $this->getEmptyConfig(); |
||||||
| 30 | unset($config['api_host']); |
||||||
| 31 | $extension = new SendyExtension(); |
||||||
| 32 | $extension->load([$config], new ContainerBuilder()); |
||||||
| 33 | } |
||||||
| 34 | |||||||
| 35 | public function testConfigLoadThrowsExceptionUnlessListIdSet(): void |
||||||
| 36 | { |
||||||
| 37 | self::expectException(InvalidConfigurationException::class); |
||||||
|
0 ignored issues
–
show
The method
PHPUnit\Framework\TestCase::expectException() is not static, but was called statically.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 38 | |||||||
| 39 | $config = $this->getEmptyConfig(); |
||||||
| 40 | unset($config['list_id']); |
||||||
| 41 | $extension = new SendyExtension(); |
||||||
| 42 | $extension->load([$config], new ContainerBuilder()); |
||||||
| 43 | } |
||||||
| 44 | |||||||
| 45 | public function testDefault(): void |
||||||
| 46 | { |
||||||
| 47 | $container = new ContainerBuilder(); |
||||||
| 48 | $extension = new SendyExtension(); |
||||||
| 49 | $extension->load([$this->getEmptyConfig()], $container); |
||||||
| 50 | |||||||
| 51 | self::assertEquals('example_key', $container->getParameter('sendy.api_key')); |
||||||
| 52 | self::assertEquals('https://example.host', $container->getParameter('sendy.api_host')); |
||||||
| 53 | self::assertEquals('example_list', $container->getParameter('sendy.list_id')); |
||||||
| 54 | |||||||
| 55 | self::assertTrue($container->hasDefinition('sendy.sendy_manager'), 'Manager service is loaded'); |
||||||
| 56 | } |
||||||
| 57 | |||||||
| 58 | /** |
||||||
| 59 | * @return array<string, string> |
||||||
| 60 | */ |
||||||
| 61 | private function getEmptyConfig(): array |
||||||
| 62 | { |
||||||
| 63 | $yaml = <<<EOF |
||||||
| 64 | api_key: example_key |
||||||
| 65 | api_host: example.host |
||||||
| 66 | list_id: example_list |
||||||
| 67 | EOF; |
||||||
| 68 | $parser = new Parser(); |
||||||
| 69 | // @phpstan-ignore-next-line |
||||||
| 70 | return $parser->parse($yaml); |
||||||
| 71 | } |
||||||
| 72 | } |
||||||
| 73 |