|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace Tests\Cases\DI; |
| 4 | + |
| 5 | +use Contributte\Tester\Toolkit; |
| 6 | +use Contributte\Tester\Utils\ContainerBuilder; |
| 7 | +use Contributte\Tester\Utils\Neonkit; |
| 8 | +use Doctrine\DBAL\Connection; |
| 9 | +use Doctrine\DBAL\Types\Type; |
| 10 | +use Doctrine\ORM\Configuration; |
| 11 | +use Nette\DI\Compiler; |
| 12 | +use Nette\DI\Container; |
| 13 | +use Nettrine\Extensions\Oroinc\DI\OroincBehaviorExtension; |
| 14 | +use ReflectionClass; |
| 15 | +use Tester\Assert; |
| 16 | + |
| 17 | +require __DIR__ . '/../../bootstrap.php'; |
| 18 | + |
| 19 | +Toolkit::setUp(static function (): void { |
| 20 | + $rc = new ReflectionClass(Type::class); |
| 21 | + $rc->setStaticPropertyValue('typeRegistry', null); |
| 22 | +}); |
| 23 | + |
| 24 | +// Nothing |
| 25 | +Toolkit::test(static function (): void { |
| 26 | + $container = ContainerBuilder::of() |
| 27 | + ->withCompiler(static function (Compiler $compiler): void { |
| 28 | + $compiler->addExtension('nettrine.extensions.oroinc', new OroincBehaviorExtension()); |
| 29 | + })->build(); |
| 30 | + |
| 31 | + $container->initialize(); |
| 32 | + Assert::notNull($container->getByType(Container::class)); |
| 33 | +}); |
| 34 | + |
| 35 | +// MySQL |
| 36 | +Toolkit::test(static function (): void { |
| 37 | + $container = ContainerBuilder::of() |
| 38 | + ->withCompiler(static function (Compiler $compiler): void { |
| 39 | + $compiler->addExtension('nettrine.extensions.oroinc', new OroincBehaviorExtension()); |
| 40 | + $compiler->addConfig([ |
| 41 | + 'services' => [ |
| 42 | + Configuration::class, |
| 43 | + ], |
| 44 | + 'nettrine.extensions.oroinc' => [ |
| 45 | + 'driver' => 'pdo_mysql', |
| 46 | + ], |
| 47 | + ]); |
| 48 | + })->build(); |
| 49 | + |
| 50 | + $container->initialize(); |
| 51 | + Assert::notNull($container->getByType(Configuration::class)); |
| 52 | +}); |
| 53 | + |
| 54 | +// PostgreSQL |
| 55 | +Toolkit::test(static function (): void { |
| 56 | + $container = ContainerBuilder::of() |
| 57 | + ->withCompiler(static function (Compiler $compiler): void { |
| 58 | + $compiler->addExtension('nettrine.extensions.oroinc', new OroincBehaviorExtension()); |
| 59 | + $compiler->addConfig([ |
| 60 | + 'services' => [ |
| 61 | + Configuration::class, |
| 62 | + ], |
| 63 | + 'nettrine.extensions.oroinc' => [ |
| 64 | + 'driver' => 'pdo_pgsql', |
| 65 | + ], |
| 66 | + ]); |
| 67 | + })->build(); |
| 68 | + |
| 69 | + $container->initialize(); |
| 70 | + Assert::notNull($container->getByType(Configuration::class)); |
| 71 | +}); |
| 72 | + |
| 73 | +// Types |
| 74 | +Toolkit::test(static function (): void { |
| 75 | + $container = ContainerBuilder::of() |
| 76 | + ->withCompiler(static function (Compiler $compiler): void { |
| 77 | + $compiler->addExtension('nettrine.extensions.oroinc', new OroincBehaviorExtension()); |
| 78 | + $compiler->addConfig(Neonkit::load(<<<'NEON' |
| 79 | + services: |
| 80 | + - Doctrine\DBAL\Connection( |
| 81 | + [], |
| 82 | + Doctrine\DBAL\Driver\SQLite3\Driver() |
| 83 | + ) |
| 84 | + NEON |
| 85 | + )); |
| 86 | + })->build(); |
| 87 | + |
| 88 | + $container->initialize(); |
| 89 | + Assert::notNull($container->getByType(Connection::class)); |
| 90 | +}); |
0 commit comments