Esempio n. 1
0
    def testResolve(self):
        """
        @covers Symfony\Component\Config\Loader\Loader.resolve

        """

        loader1 = LoaderInterfaceMock1()
        resolver = LoaderResolver([loader1])
        loader = ProjectLoader1()
        loader.setResolver(resolver)

        self.assertEqual(loader, loader.resolve('foo.foo'),
                         '->resolve() finds a loader')
        self.assertEqual(loader1, loader.resolve('foo.xml'),
                         '->resolve() finds a loader')

        loader1 = LoaderInterfaceMock2()
        resolver = LoaderResolver([loader1])
        loader = ProjectLoader1()
        loader.setResolver(resolver)
        try:
            loader.resolve('FOOBAR')
            self.fail(
                '->resolve() raise a FileLoaderLoadException if the resource cannot be loaded'
            )
        except FileLoaderLoadException as e:
            self.assertTrue(
                isinstance(e, FileLoaderLoadException),
                '->resolve() raise a FileLoaderLoadException if the resource cannot be loaded'
            )
    def testLoaders(self):
        """
        @covers Symfony\Component\Config\Loader\LoaderResolver.getLoaders
        @covers Symfony\Component\Config\Loader\LoaderResolver.addLoader

        """

        resolver = LoaderResolver();
        loader = LoaderInterfaceMock1();
        resolver.addLoader(loader);

        self.assertEqual([loader], resolver.getLoaders(), 'addLoader() adds a loader');
    def testConstructor(self):
        """
        @covers Symfony\Component\Config\Loader\LoaderResolver.__construct

        """

        loader = LoaderInterfaceMock1();
        resolver = LoaderResolver([
            loader
        ]);

        self.assertEqual([loader], resolver.getLoaders(), '__init__() takes an array of loaders as its first argument');
    def testResolve(self):
        """
        @covers Symfony\Component\Config\Loader\LoaderResolver.resolve

        """

        loader = LoaderInterfaceMock1();
        resolver = LoaderResolver([loader]);
        self.assertFalse(resolver.resolve('foo.foo'), '->resolve() returns False if no loader is able to load the resource');

        loader = LoaderInterfaceMock2();
        resolver = LoaderResolver([loader]);
        self.assertEqual(loader, resolver.resolve(lambda: None), '->resolve() returns the loader for the given resource');
    def testGetSetResolver(self):
        """
        @covers Symfony\Component\Config\Loader\DelegatingLoader.getResolver
        @covers Symfony\Component\Config\Loader\DelegatingLoader.setResolver

        """

        resolver = LoaderResolver()
        loader = DelegatingLoader(resolver)
        self.assertEqual(resolver, loader.getResolver(),
                         '->getResolver() gets the resolver loader')
        resolver = LoaderResolver()
        loader.setResolver(resolver)
        self.assertEqual(resolver, loader.getResolver(),
                         '->setResolver() sets the resolver loader')
    def testSupports(self):
        """
        @covers Symfony\Component\Config\Loader\DelegatingLoader.supports

        """

        loader1 = LoaderInterfaceMock1()
        loader = DelegatingLoader(LoaderResolver([loader1]))
        self.assertTrue(
            loader.supports('foo.xml'),
            '->supports() returns True if the resource is loadable')

        loader1 = LoaderInterfaceMock2()
        loader = DelegatingLoader(LoaderResolver([loader1]))
        self.assertFalse(
            loader.supports('foo.foo'),
            '->supports() returns False if the resource is not loadable')
Esempio n. 7
0
 def _getContainerLoader(self, container):
     assert isinstance(container, ContainerInterface)
     locator = FileLocator(self)
     resolver = LoaderResolver([
         IniFileLoader(container, locator),
         JsonFileLoader(container, locator),
         YamlFileLoader(container, locator),
     ])
     return DelegatingLoader(resolver)
    def testConstructor(self):
        """
        @covers Symfony\Component\Config\Loader\DelegatingLoader.__construct

        """

        resolver = LoaderResolver()
        loader = DelegatingLoader(resolver)
        self.assertTrue(
            True, '__init__() takes a loader resolver as its first argument')
    def testLoad(self):
        """
        @covers Symfony\Component\Config\Loader\DelegatingLoader.load

        """

        loader = LoaderInterfaceMock1()
        resolver = LoaderResolver([loader])
        loader = DelegatingLoader(resolver)

        loader.load('foo')
Esempio n. 10
0
    def testGetSetResolver(self):
        """
        @covers Symfony\Component\Config\Loader\Loader.getResolver
        @covers Symfony\Component\Config\Loader\Loader.setResolver

        """

        resolver = LoaderResolver()
        loader = ProjectLoader1()
        loader.setResolver(resolver)
        self.assertEqual(resolver, loader.getResolver(),
                         '->setResolver() sets the resolver loader')
    def testLoadThrowsAnExceptionIfTheResourceCannotBeLoaded(self):
        """@expectedException Symfony\Component\Config\Exception\FileLoaderLoadException

        """

        try:
            loader = LoaderInterfaceMock2()
            resolver = LoaderResolver([loader])
            loader = DelegatingLoader(resolver)

            loader.load('foo')

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, FileLoaderLoadException))