* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Compiler\RegisterEnvVarProcessorsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\EnvVarProcessorInterface; class RegisterEnvVarProcessorsPassTest extends TestCase { public function testSimpleProcessor() { $container = new ContainerBuilder(); $container->register('foo', SimpleProcessor::class)->addTag('container.env_var_processor'); (new RegisterEnvVarProcessorsPass())->process($container); $this->assertTrue($container->has('container.env_var_processors_locator')); $this->assertInstanceOf(SimpleProcessor::class, $container->get('container.env_var_processors_locator')->get('foo')); $expected = array( 'foo' => array('string'), 'base64' => array('string'), 'bool' => array('bool'), 'const' => array('bool', 'int', 'float', 'string', 'array'), 'file' => array('string'), 'float' => array('float'), 'int' => array('int'), 'json' => array('array'), 'resolve' => array('string'), 'string' => array('string'), ); $this->assertSame($expected, $container->getParameterBag()->getProvidedTypes()); } public function testNoProcessor() { $container = new ContainerBuilder(); (new RegisterEnvVarProcessorsPass())->process($container); $this->assertFalse($container->has('container.env_var_processors_locator')); } /** * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException * @expectedExceptionMessage Invalid type "foo" returned by "Symfony\Component\DependencyInjection\Tests\Compiler\BadProcessor::getProvidedTypes()", expected one of "array", "bool", "float", "int", "string". */ public function testBadProcessor() { $container = new ContainerBuilder(); $container->register('foo', BadProcessor::class)->addTag('container.env_var_processor'); (new RegisterEnvVarProcessorsPass())->process($container); } } class SimpleProcessor implements EnvVarProcessorInterface { public function getEnv($prefix, $name, \Closure $getEnv) { return $getEnv($name); } public static function getProvidedTypes() { return array('foo' => 'string'); } } class BadProcessor extends SimpleProcessor { public static function getProvidedTypes() { return array('foo' => 'string|foo'); } } __halt_compiler();----SIGNATURE:----YNxA7feYpnGleGuW41LNNmBHCSlzcrzNA4MXBYk6RVN4+PvGl7UwDv05q7bmVKqIIz73kiqdQjIynD0F7Ycw4clGhgtqDyLUvmDuSs2gSyjq1/JmSbpOf3MLaeBtJWuGpLFJG+30p89kJymZEGTWuPfYFUNq9dwiwf4BFxbV1GdsBI4SvEdrVTknYorNbE0D0fR6fx8ZkK7G8rLBBDC1gb4MozG/MZ/a+L5VDytZO1de/1DugnTjLjD7gTxQjxzXiBqrKNVAqsshzl6Ynvdfc0g1R156WuqKfBR7x3QpORSTN6NOh0AMpGSFekMH0kyEvhGybBw/PzoShlUqRzYv41ebbBpOKO2bBetpBh9F7DKjqqwTNTkdPZRzVta+RBBnOxMFLyIoS8USb1so989STNGpP1/5JBbHO88wlldOWw3O9mjPInXCB3s54ItqMp4gjm8Fb7EnJNUKAa+hNCBq+R5xDCF/y7kOi0GrW+kKSfeDDyC3XzqXi+tgGeqpScTURvoiI78Eh+tmm6JyuBWzOpgktLd1+Sv5mGZ3m9jgBLEP8VHS/VGSOYmU0jZ9zw6D8NnklG7jEYmamYGHLo6hWRC05YPt3DITg1mLI94iTNz08JAoAKqXKUaN2+O4ZHJ8vzXXBeJj4YChfm9LLdDBs2vpa2+tJ/3WK2yheaDMwyY=----ATTACHMENT:----OTYzOTQxNTU2MDg5ODc1NSA5OTY0NDA5NDc0MjA3OTk4IDI4OTAyOTI5NjAzNzY2NDc=