Exemple #1
0
 public function testExtensions()
 {
     $container = new ContainerBuilder();
     $container->registerExtension(new \ProjectExtension());
     $container->registerExtension(new \ProjectWithXsdExtension());
     $loader = new ProjectLoader2($container, self::$fixturesPath . '/xml');
     // extension without an XSD
     $loader->load('extensions/services1.xml');
     $container->freeze();
     $services = $container->getDefinitions();
     $parameters = $container->getParameterBag()->all();
     $this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements');
     $this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements');
     $this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
     $this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
     // extension with an XSD
     $container = new ContainerBuilder();
     $container->registerExtension(new \ProjectExtension());
     $container->registerExtension(new \ProjectWithXsdExtension());
     $loader = new ProjectLoader2($container, self::$fixturesPath . '/xml');
     $loader->load('extensions/services2.xml');
     $container->freeze();
     $services = $container->getDefinitions();
     $parameters = $container->getParameterBag()->all();
     $this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements');
     $this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements');
     $this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
     $this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
     $loader = new ProjectLoader2(new ContainerBuilder(), self::$fixturesPath . '/xml');
     // extension with an XSD (does not validate)
     try {
         $loader->load('extensions/services3.xml');
         $this->fail('->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
         $this->assertRegexp('/The attribute \'bar\' is not allowed/', $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
     }
     // non-registered extension
     try {
         $loader->load('extensions/services4.xml');
         $this->fail('->load() throws an InvalidArgumentException if the tag is not valid');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag is not valid');
         $this->assertStringStartsWith('There is no extension able to load the configuration for "project:bar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid');
     }
 }
Exemple #2
0
 public function testLoadInterfaceInjectors()
 {
     $container = new ContainerBuilder();
     $loader = new ProjectLoader2($container, self::$fixturesPath . '/xml');
     $loader->load('interfaces1.xml');
     $interfaces = $container->getInterfaceInjectors('FooClass');
     $this->assertEquals(1, count($interfaces), '->load() parses <interface> elements');
     $interface = $interfaces['FooClass'];
     $this->assertTrue($interface->hasMethodCall('setBar'), '->load() applies method calls correctly');
 }