Esempio n. 1
0
 public function testAddService()
 {
     $container = (include self::$fixturesPath . '/containers/container9.php');
     $dumper = new XmlDumper($container);
     $this->assertEquals($dumper->dump(), str_replace('%path%', self::$fixturesPath . '/includes', file_get_contents(self::$fixturesPath . '/xml/services9.xml')), '->dump() dumps services');
     $dumper = new XmlDumper($container = new Builder());
     $container->register('foo', 'FooClass')->addArgument(new \stdClass());
     try {
         $dumper->dump();
         $this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
     } catch (\RuntimeException $e) {
     }
 }
Esempio n. 2
0
 public function testAddService()
 {
     $container = (include self::$fixturesPath . '/containers/container9.php');
     $dumper = new XmlDumper($container);
     $this->assertEquals(str_replace('%path%', self::$fixturesPath . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath . '/xml/services9.xml')), $dumper->dump(), '->dump() dumps services');
     $dumper = new XmlDumper($container = new Builder());
     $container->register('foo', 'FooClass')->addArgument(new \stdClass());
     try {
         $dumper->dump();
         $this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
         $this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
     }
 }
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\DependencyInjection\Builder;
use Symfony\Components\DependencyInjection\Dumper\XmlDumper;
$t = new LimeTest(4);
$fixturesPath = realpath(__DIR__ . '/../../../../../fixtures/Symfony/Components/DependencyInjection/');
// ->dump()
$t->diag('->dump()');
$dumper = new XmlDumper($container = new Builder());
$t->is($dumper->dump(), file_get_contents($fixturesPath . '/xml/services1.xml'), '->dump() dumps an empty container as an empty XML file');
$container = new Builder();
$dumper = new XmlDumper($container);
// ->addParameters()
$t->diag('->addParameters()');
$container = (include $fixturesPath . '//containers/container8.php');
$dumper = new XmlDumper($container);
$t->is($dumper->dump(), file_get_contents($fixturesPath . '/xml/services8.xml'), '->dump() dumps parameters');
// ->addService()
$t->diag('->addService()');
$container = (include $fixturesPath . '/containers/container9.php');
$dumper = new XmlDumper($container);
$t->is($dumper->dump(), str_replace('%path%', $fixturesPath . '/includes', file_get_contents($fixturesPath . '/xml/services9.xml')), '->dump() dumps services');
$dumper = new XmlDumper($container = new Builder());
$container->register('foo', 'FooClass')->addArgument(new stdClass());
try {
    $dumper->dump();
    $t->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (RuntimeException $e) {
    $t->pass('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}