You are here

class ResolveDefinitionTemplatesPassTest in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/dependency-injection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php \Symfony\Component\DependencyInjection\Tests\Compiler\ResolveDefinitionTemplatesPassTest

Hierarchy

  • class \Symfony\Component\DependencyInjection\Tests\Compiler\ResolveDefinitionTemplatesPassTest extends \Symfony\Component\DependencyInjection\Tests\Compiler\PHPUnit_Framework_TestCase

Expanded class hierarchy of ResolveDefinitionTemplatesPassTest

File

vendor/symfony/dependency-injection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php, line 19

Namespace

Symfony\Component\DependencyInjection\Tests\Compiler
View source
class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase {
  public function testProcess() {
    $container = new ContainerBuilder();
    $container
      ->register('parent', 'foo')
      ->setArguments(array(
      'moo',
      'b',
    ))
      ->setProperty('foo', 'moo');
    $container
      ->setDefinition('child', new DefinitionDecorator('parent'))
      ->replaceArgument(0, 'a')
      ->setProperty('foo', 'bar')
      ->setClass('bar');
    $this
      ->process($container);
    $def = $container
      ->getDefinition('child');
    $this
      ->assertNotInstanceOf('Symfony\\Component\\DependencyInjection\\DefinitionDecorator', $def);
    $this
      ->assertEquals('bar', $def
      ->getClass());
    $this
      ->assertEquals(array(
      'a',
      'b',
    ), $def
      ->getArguments());
    $this
      ->assertEquals(array(
      'foo' => 'bar',
    ), $def
      ->getProperties());
  }
  public function testProcessAppendsMethodCallsAlways() {
    $container = new ContainerBuilder();
    $container
      ->register('parent')
      ->addMethodCall('foo', array(
      'bar',
    ));
    $container
      ->setDefinition('child', new DefinitionDecorator('parent'))
      ->addMethodCall('bar', array(
      'foo',
    ));
    $this
      ->process($container);
    $def = $container
      ->getDefinition('child');
    $this
      ->assertEquals(array(
      array(
        'foo',
        array(
          'bar',
        ),
      ),
      array(
        'bar',
        array(
          'foo',
        ),
      ),
    ), $def
      ->getMethodCalls());
  }
  public function testProcessDoesNotCopyAbstract() {
    $container = new ContainerBuilder();
    $container
      ->register('parent')
      ->setAbstract(true);
    $container
      ->setDefinition('child', new DefinitionDecorator('parent'));
    $this
      ->process($container);
    $def = $container
      ->getDefinition('child');
    $this
      ->assertFalse($def
      ->isAbstract());
  }
  public function testProcessDoesNotCopyScope() {
    $container = new ContainerBuilder();
    $container
      ->register('parent')
      ->setScope('foo');
    $container
      ->setDefinition('child', new DefinitionDecorator('parent'));
    $this
      ->process($container);
    $def = $container
      ->getDefinition('child');
    $this
      ->assertEquals(ContainerInterface::SCOPE_CONTAINER, $def
      ->getScope());
  }
  public function testProcessDoesNotCopyTags() {
    $container = new ContainerBuilder();
    $container
      ->register('parent')
      ->addTag('foo');
    $container
      ->setDefinition('child', new DefinitionDecorator('parent'));
    $this
      ->process($container);
    $def = $container
      ->getDefinition('child');
    $this
      ->assertEquals(array(), $def
      ->getTags());
  }
  public function testProcessDoesNotCopyDecoratedService() {
    $container = new ContainerBuilder();
    $container
      ->register('parent')
      ->setDecoratedService('foo');
    $container
      ->setDefinition('child', new DefinitionDecorator('parent'));
    $this
      ->process($container);
    $def = $container
      ->getDefinition('child');
    $this
      ->assertNull($def
      ->getDecoratedService());
  }
  public function testProcessHandlesMultipleInheritance() {
    $container = new ContainerBuilder();
    $container
      ->register('parent', 'foo')
      ->setArguments(array(
      'foo',
      'bar',
      'c',
    ));
    $container
      ->setDefinition('child2', new DefinitionDecorator('child1'))
      ->replaceArgument(1, 'b');
    $container
      ->setDefinition('child1', new DefinitionDecorator('parent'))
      ->replaceArgument(0, 'a');
    $this
      ->process($container);
    $def = $container
      ->getDefinition('child2');
    $this
      ->assertEquals(array(
      'a',
      'b',
      'c',
    ), $def
      ->getArguments());
    $this
      ->assertEquals('foo', $def
      ->getClass());
  }
  public function testSetLazyOnServiceHasParent() {
    $container = new ContainerBuilder();
    $container
      ->register('parent', 'stdClass');
    $container
      ->setDefinition('child1', new DefinitionDecorator('parent'))
      ->setLazy(true);
    $this
      ->process($container);
    $this
      ->assertTrue($container
      ->getDefinition('child1')
      ->isLazy());
  }
  public function testSetLazyOnServiceIsParent() {
    $container = new ContainerBuilder();
    $container
      ->register('parent', 'stdClass')
      ->setLazy(true);
    $container
      ->setDefinition('child1', new DefinitionDecorator('parent'));
    $this
      ->process($container);
    $this
      ->assertTrue($container
      ->getDefinition('child1')
      ->isLazy());
  }
  public function testSetDecoratedServiceOnServiceHasParent() {
    $container = new ContainerBuilder();
    $container
      ->register('parent', 'stdClass');
    $container
      ->setDefinition('child1', new DefinitionDecorator('parent'))
      ->setDecoratedService('foo', 'foo_inner');
    $this
      ->process($container);
    $this
      ->assertEquals(array(
      'foo',
      'foo_inner',
    ), $container
      ->getDefinition('child1')
      ->getDecoratedService());
  }
  protected function process(ContainerBuilder $container) {
    $pass = new ResolveDefinitionTemplatesPass();
    $pass
      ->process($container);
  }

}

Members