|
| 1 | +<?php declare (strict_types = 1); |
| 2 | + |
| 3 | +namespace Tests\Cases\DI; |
| 4 | + |
| 5 | +use Contributte\Elastica\Client; |
| 6 | +use Contributte\Elastica\DI\ElasticaExtension; |
| 7 | +use Contributte\Elastica\Diagnostics\Panel; |
| 8 | +use Contributte\Tester\Utils\ContainerBuilder; |
| 9 | +use Nette\DI\Compiler; |
| 10 | +use Nette\DI\MissingServiceException; |
| 11 | +use Tester\Assert; |
| 12 | +use Tester\TestCase; |
| 13 | + |
| 14 | +require_once __DIR__ . '/../../bootstrap.php'; |
| 15 | + |
| 16 | +class ElasticaExtensionTest extends TestCase |
| 17 | +{ |
| 18 | + |
| 19 | + public function testRegisterServicesWithTracyPanel(): void |
| 20 | + { |
| 21 | + $container = ContainerBuilder::of() |
| 22 | + ->withCompiler(static function (Compiler $compiler): void { |
| 23 | + $compiler->addExtension('elastica', new ElasticaExtension()); |
| 24 | + $compiler->addConfig(['elastica' => ['debug' => true]]); |
| 25 | + }) |
| 26 | + ->build(); |
| 27 | + |
| 28 | + Assert::type(Client::class, $container->getService('elastica.client')); |
| 29 | + Assert::type(Panel::class, $container->getService('elastica.panel')); |
| 30 | + } |
| 31 | + |
| 32 | + public function testWithoutTracyPanel(): void |
| 33 | + { |
| 34 | + Assert::exception(static function (): void { |
| 35 | + $container = ContainerBuilder::of() |
| 36 | + ->withCompiler(static function (Compiler $compiler): void { |
| 37 | + $compiler->addExtension('elastica', new ElasticaExtension()); |
| 38 | + }) |
| 39 | + ->build(); |
| 40 | + |
| 41 | + $container->getService('elastica.panel'); |
| 42 | + }, MissingServiceException::class); |
| 43 | + } |
| 44 | + |
| 45 | +} |
| 46 | + |
| 47 | +(new ElasticaExtensionTest())->run(); |
0 commit comments