* * 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:----qfVyN+yUyWFndo8SWh/EATZF8sfN9iGcEemKxQSpD0XD5KWyw5Z3y3HqT9xXGErjsmtmH46AUF8OAi7d4I0hnyRwpomdMrPqE9lCzwhhhxp6aC3DyjHgeQJ2RIFzKLErGYCYogjFtAdGscUY+inscI4QuFsrCTBK9+CGRucgCa6M3MujMuIONAUry0LvU1DlA8b32C/fk5VI9iGwiztCpIUA9kJyj3H/CvFdS/tQoG2JIMAIr6rhF//kUccWI0hEUvDzYLTJzTgz3Vgv6UJuz9D+1A2iWKcBqJE5gXtG1bGrp9X8HFnjc+20gqKEc3VXYQ0GZSWzOn/eV5honIY96jSHWM9mtHw5bnL2HuCBX6+ABbmcg6npMkOknjarmaXIOwjPpXk4hJ7nqHiDg3xdwlHxpwoV/v9Yut4ARt7no1doPLoekooLyDgny3eN+DnF2Obn1A4MFsfu89VNbmnADN5Fdtzj1vZ1+wBC44ccXK34ab6nhPdpinkatrmADEbgfiigCKzko1P4oGszKAuzb91d1bxHl2uh3An3f6arRrjlf/dV1XMKhePbq/ZpMhozidUm3z7JL/VOzlSw3fzkfAu+ND9NJzLDNpi1PMSlNgm+fN39oADOgKgLtwsJcJ5TJ+eqk4R9xOgY/mq76WXKQftRV/xUzC13iRxkN6oWmKs=----ATTACHMENT:----OTE2NjM3MDE2NzM5Nzk5MCA4MzIyMDgwODY3ODE0NjA0IDg1NTk2Mjk4MjU4NTU1