def testProcess(self):

        container = ContainerBuilder()
        container.register('a').addArgument(Reference('b'))
        container.register('b')

        self._process(container)
    def testProcess(self):

        container = ContainerBuilder()
        container._ContainerBuilder__definitions = OrderedDict()
        ref1 = Reference('b')
        a = container.register('a').addArgument(ref1)

        ref2 = Reference('a')
        b = container.register('b').addMethodCall('setA', [ref2])

        ref3 = Reference('a')
        ref4 = Reference('b')
        c = container.register('c').addArgument(ref3).addArgument(ref4)

        ref5 = Reference('b')
        d = container.register('d').setProperty('foo', ref5)

        ref6 = Reference('b')
        e = container.register('e').setConfigurator([ref6, 'methodName'])

        graph = self._process(container)

        edges = graph.getNode('b').getInEdges()
        self.assertEqual(4, len(edges))
        self.assertEqual(ref1, edges[0].getValue())
        self.assertEqual(ref4, edges[1].getValue())
        self.assertEqual(ref5, edges[2].getValue())
        self.assertEqual(ref6, edges[3].getValue())
    def testProcess(self):

        container = ContainerBuilder();
        container.register('a').addArgument(Reference('b'));
        container.register('b');

        self._process(container);
    def testProcess(self):

        container = ContainerBuilder();
        container._ContainerBuilder__definitions = OrderedDict();
        ref1 = Reference('b');
        a = container.register('a').addArgument(ref1);

        ref2 = Reference('a');
        b = container.register('b').addMethodCall('setA', [ref2]);


        ref3 = Reference('a');
        ref4 = Reference('b');
        c = container.register('c').addArgument(ref3).addArgument(ref4);

        ref5 = Reference('b');
        d = container.register('d').setProperty('foo', ref5);

        ref6 = Reference('b');
        e = container.register('e').setConfigurator([ref6, 'methodName']);

        graph = self._process(container);

        edges = graph.getNode('b').getInEdges();
        self.assertEqual(4, len(edges));
        self.assertEqual(ref1, edges[0].getValue());
        self.assertEqual(ref4, edges[1].getValue());
        self.assertEqual(ref5, edges[2].getValue());
        self.assertEqual(ref6, edges[3].getValue());
    def testProcessIgnoresScopeWideningIfNonStrictReference(self):

        container = ContainerBuilder();
        container.register('a').addArgument(Reference('b', ContainerInterface.EXCEPTION_ON_INVALID_REFERENCE, False));
        container.register('b').setScope('prototype');

        self._process(container);
    def testProcessIgnoresMethodCalls(self):

        container = ContainerBuilder();
        container.register('a').addArgument(Reference('b'));
        container.register('b').addMethodCall('setA', [Reference('a')]);

        self._process(container);
    def testProcessIgnoresMethodCalls(self):

        container = ContainerBuilder()
        container.register('a').addArgument(Reference('b'))
        container.register('b').addMethodCall('setA', [Reference('a')])

        self._process(container)
    def testProcessIgnoresScopeWideningIfNonStrictReference(self):

        container = ContainerBuilder()
        container.register('a').addArgument(
            Reference('b', ContainerInterface.EXCEPTION_ON_INVALID_REFERENCE,
                      False))
        container.register('b').setScope('prototype')

        self._process(container)
    def testProcessIgnoresCrossScopeHierarchyReferenceIfNotStrict(self):

        container = ContainerBuilder();
        container.addScope(Scope('a'));
        container.addScope(Scope('b'));

        container.register('a').setScope('a').addArgument(Reference('b', ContainerInterface.EXCEPTION_ON_INVALID_REFERENCE, False));
        container.register('b').setScope('b');

        self._process(container);
    def testProcessRemovesUnusedDefinitionsRecursively(self):

        container = ContainerBuilder();
        container.register('foo').setPublic(False);
        container.register('bar').setArguments([Reference('foo')])\
            .setPublic(False);

        self._process(container);

        self.assertFalse(container.hasDefinition('foo'));
        self.assertFalse(container.hasDefinition('bar'));
    def testStrictFlagIsPreserved(self):

        container = ContainerBuilder()
        container.register('bar')
        defi = container\
            .register('foo')\
            .addArgument(Reference('bar', ContainerInterface.NULL_ON_INVALID_REFERENCE, False))\

        self._process(container)

        self.assertFalse(defi.getArgument(0).isStrict())
    def testProcessRemovesUnusedDefinitionsRecursively(self):

        container = ContainerBuilder()
        container.register('foo').setPublic(False)
        container.register('bar').setArguments([Reference('foo')])\
            .setPublic(False)

        self._process(container)

        self.assertFalse(container.hasDefinition('foo'))
        self.assertFalse(container.hasDefinition('bar'))
    def testProcessIgnoresCrossScopeHierarchyReferenceIfNotStrict(self):

        container = ContainerBuilder()
        container.addScope(Scope('a'))
        container.addScope(Scope('b'))

        container.register('a').setScope('a').addArgument(
            Reference('b', ContainerInterface.EXCEPTION_ON_INVALID_REFERENCE,
                      False))
        container.register('b').setScope('b')

        self._process(container)
    def testStrictFlagIsPreserved(self):

        container = ContainerBuilder();
        container.register('bar');
        defi = container\
            .register('foo')\
            .addArgument(Reference('bar', ContainerInterface.NULL_ON_INVALID_REFERENCE, False))\
        ;

        self._process(container);

        self.assertFalse(defi.getArgument(0).isStrict());
    def testProcess(self):

        container = ContainerBuilder();
        container.register('foo').setPublic(False);
        container.register('bar').setPublic(False);
        container.register('moo').setArguments([Reference('bar')]);

        self._process(container);

        self.assertFalse(container.hasDefinition('foo'));
        self.assertTrue(container.hasDefinition('bar'));
        self.assertTrue(container.hasDefinition('moo'));
    def testProcess(self):

        container = ContainerBuilder()
        container.register('foo').setPublic(False)
        container.register('bar').setPublic(False)
        container.register('moo').setArguments([Reference('bar')])

        self._process(container)

        self.assertFalse(container.hasDefinition('foo'))
        self.assertTrue(container.hasDefinition('bar'))
        self.assertTrue(container.hasDefinition('moo'))
    def testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass(self):
        """@expectedException RuntimeException

        """

        try:
            container = ContainerBuilder()
            container.register('a').setSynthetic(False).setAbstract(False)

            self._process(container)

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, RuntimeException))
    def testProcessDetectsReferencesFromInlinedDefinitions(self):

        container = ContainerBuilder()

        container.register('a')

        ref = Reference('a')
        container.register('b').addArgument(Definition(None, [ref]))

        graph = self._process(container)

        refs = graph.getNode('a').getInEdges()
        self.assertEqual(1, len(refs))
        self.assertEqual(ref, refs[0].getValue())
    def testProcessDoesNotSaveDuplicateReferences(self):

        container = ContainerBuilder()

        container.register('a')

        ref1 = Reference('a')
        ref2 = Reference('a')
        container.register('b').addArgument(Definition(None, [ref1]))\
            .addArgument(Definition(None, [ref2]))

        graph = self._process(container)

        self.assertEqual(2, len(graph.getNode('a').getInEdges()))
    def testProcess(self):
        """@expectedException RuntimeException

        """

        try:
            container = ContainerBuilder();
            container.register('a').addArgument(Reference('b'));
            container.register('b').addArgument(Reference('a'));

            self._process(container);
            self.fail("")
        except Exception as e:
            self.assertTrue(isinstance(e, RuntimeException));
    def testProcessDoesNotSaveDuplicateReferences(self):

        container = ContainerBuilder();

        container.register('a');

        ref1 = Reference('a');
        ref2 = Reference('a');
        container.register('b').addArgument(Definition(None, [ref1]))\
            .addArgument(Definition(None, [ref2]));

        graph = self._process(container);

        self.assertEqual(2, len(graph.getNode('a').getInEdges()));
    def testProcessDetectsSyntheticPrototypeDefinitions(self):
        """@expectedException RuntimeException

        """

        try:
            container = ContainerBuilder();
            container.register('a').setSynthetic(True).setScope(ContainerInterface.SCOPE_PROTOTYPE);

            self._process(container);

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, RuntimeException));
    def testProcessDetectsReferencesFromInlinedDefinitions(self):

        container = ContainerBuilder();

        container.register('a');

        ref = Reference('a');
        container.register('b').addArgument(Definition(None, [ref]));

        graph = self._process(container);

        refs = graph.getNode('a').getInEdges();
        self.assertEqual(1, len(refs));
        self.assertEqual(ref, refs[0].getValue());
    def testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass(self):
        """@expectedException RuntimeException

        """

        try:
            container = ContainerBuilder();
            container.register('a').setSynthetic(False).setAbstract(False);

            self._process(container);

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, RuntimeException));
    def testProcess(self):
        """@expectedException RuntimeException

        """

        try:
            container = ContainerBuilder()
            container.register('a').addArgument(Reference('b'))
            container.register('b').addArgument(Reference('a'))

            self._process(container)
            self.fail("")
        except Exception as e:
            self.assertTrue(isinstance(e, RuntimeException))
    def testProcessThrowsExceptionOnInvalidReference(self):
        """@expectedException Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException

        """

        try:
            container = ContainerBuilder()

            container.register('a', 'object').addArgument(Reference('b'))

            self.__process(container)

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, ServiceNotFoundException))
    def testProcessDetectsScopeWidening(self):
        """@expectedException RuntimeException

        """

        try:
            container = ContainerBuilder()
            container.register('a').addArgument(Reference('b'))
            container.register('b').setScope('prototype')

            self._process(container)

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, RuntimeException))
    def testProcessDetectsScopeWidening(self):
        """@expectedException RuntimeException

        """

        try:
            container = ContainerBuilder();
            container.register('a').addArgument(Reference('b'));
            container.register('b').setScope('prototype');

            self._process(container);

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, RuntimeException));
    def testProcessDetectsSyntheticPrototypeDefinitions(self):
        """@expectedException RuntimeException

        """

        try:
            container = ContainerBuilder()
            container.register('a').setSynthetic(True).setScope(
                ContainerInterface.SCOPE_PROTOTYPE)

            self._process(container)

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, RuntimeException))
    def testProcessThrowsExceptionOnInvalidReference(self):
        """@expectedException Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException

        """

        try:
            container = ContainerBuilder();

            container.register('a', 'object').addArgument(Reference('b'));

            self.__process(container);

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, ServiceNotFoundException));
    def testProcess(self):

        container = ContainerBuilder();
        container.register('a', 'class');
        container.register('b', 'class').setSynthetic(True).setPublic(True);
        container.register('c', 'class').setAbstract(True);
        container.register('d', 'class').setSynthetic(True);

        self._process(container);
    def testProcess(self):

        container = ContainerBuilder()
        container.register('a', 'class')
        container.register('b', 'class').setSynthetic(True).setPublic(True)
        container.register('c', 'class').setAbstract(True)
        container.register('d', 'class').setSynthetic(True)

        self._process(container)
    def testProcessDetectsReferenceToAbstractDefinition(self):
        """@expectedException RuntimeException

        """

        try:

            container = ContainerBuilder()

            container.register('a').setAbstract(True)
            container.register('b').addArgument(Reference('a'))

            self._process(container)

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, RuntimeException))
    def testProcessDetectsReferenceToAbstractDefinition(self):
        """@expectedException RuntimeException

        """

        try:

            container = ContainerBuilder();

            container.register('a').setAbstract(True);
            container.register('b').addArgument(Reference('a'));

            self._process(container);

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, RuntimeException));
    def testProcess(self):

        container = ContainerBuilder();
        container.register('parent', 'foo').setArguments(['moo', 'b']).setProperty('foo', 'moo');
        container.setDefinition('child', DefinitionDecorator('parent'))\
            .replaceArgument(0, 'a')\
            .setProperty('foo', 'bar')\
            .setClass('bar')\
        ;

        self._process(container);

        definition = container.getDefinition('child');
        self.assertFalse(isinstance(object, DefinitionDecorator));
        self.assertEqual('bar', definition.getClass());
        self.assertEqual(['a', 'b'], definition.getArguments());
        self.assertEqual({'foo': 'bar'}, definition.getProperties());
    def testProcess(self):

        container = ContainerBuilder()
        container.register('parent',
                           'foo').setArguments(['moo', 'b'
                                                ]).setProperty('foo', 'moo')
        container.setDefinition('child', DefinitionDecorator('parent'))\
            .replaceArgument(0, 'a')\
            .setProperty('foo', 'bar')\
            .setClass('bar')\

        self._process(container)

        definition = container.getDefinition('child')
        self.assertFalse(isinstance(object, DefinitionDecorator))
        self.assertEqual('bar', definition.getClass())
        self.assertEqual(['a', 'b'], definition.getArguments())
        self.assertEqual({'foo': 'bar'}, definition.getProperties())
    def testProcess(self):

        container = ContainerBuilder();

        container.register('a', 'object');

        bDefinition = Definition('object');
        bDefinition.setPublic(False);
        container.setDefinition('b', bDefinition);

        container.setAlias('a_alias', 'a');
        container.setAlias('b_alias', 'b');

        self._process(container);

        self.assertTrue(container.has('a'), '->process() does nothing to public definitions.');
        self.assertTrue(container.hasAlias('a_alias'));
        self.assertFalse(container.has('b'), '->process() removes non-public definitions.');
        self.assertTrue(
            container.has('b_alias') and not container.hasAlias('b_alias'),
            '->process() replaces alias to actual.'
        );
    def testProcess(self):

        container = ContainerBuilder()

        container.register('a', 'object')

        bDefinition = Definition('object')
        bDefinition.setPublic(False)
        container.setDefinition('b', bDefinition)

        container.setAlias('a_alias', 'a')
        container.setAlias('b_alias', 'b')

        self._process(container)

        self.assertTrue(container.has('a'),
                        '->process() does nothing to public definitions.')
        self.assertTrue(container.hasAlias('a_alias'))
        self.assertFalse(container.has('b'),
                         '->process() removes non-public definitions.')
        self.assertTrue(
            container.has('b_alias') and not container.hasAlias('b_alias'),
            '->process() replaces alias to actual.')
    def testProcess(self):

        container = ContainerBuilder();

        container.register('a', 'object').addArgument(Reference('b'));
        container.register('b', 'object');
    def testProcess(self):

        container = ContainerBuilder()

        container.register('a', 'object').addArgument(Reference('b'))
        container.register('b', 'object')