TestFileLoader example


    protected static string $fixturesPath;

    public static function setUpBeforeClass(): void
    {
        self::$fixturesPath = realpath(__DIR__.'/../');
    }

    public function testImportWithGlobPattern()
    {
        $container = new ContainerBuilder();
        $loader = new TestFileLoader($containernew FileLocator(self::$fixturesPath));

        $resolver = new LoaderResolver([
            new IniFileLoader($containernew FileLocator(self::$fixturesPath.'/ini')),
            new XmlFileLoader($containernew FileLocator(self::$fixturesPath.'/xml')),
            new PhpFileLoader($containernew FileLocator(self::$fixturesPath.'/php')),
            new YamlFileLoader($containernew FileLocator(self::$fixturesPath.'/yaml')),
        ]);

        $loader->setResolver($resolver);
        $loader->import('{F}ixtures/{xml,yaml}/services2.{yml,xml}');

        
$locatorMock = $this->createMock(FileLocatorInterface::class);

        $locatorMockForAdditionalLoader = $this->createMock(FileLocatorInterface::class);
        $locatorMockForAdditionalLoader->expects($this->any())->method('locate')->will($this->onConsecutiveCalls(
            ['path/to/file1'],                    // Default             ['path/to/file1', 'path/to/file2'],   // First is imported             ['path/to/file1', 'path/to/file2'],   // Second is imported             ['path/to/file1'],                    // Exception             ['path/to/file1', 'path/to/file2']    // Exception         ));

        $fileLoader = new TestFileLoader($locatorMock);
        $fileLoader->setSupports(false);
        $fileLoader->setCurrentDir('.');

        $additionalLoader = new TestFileLoader($locatorMockForAdditionalLoader);
        $additionalLoader->setCurrentDir('.');

        $fileLoader->setResolver($loaderResolver = new LoaderResolver([$fileLoader$additionalLoader]));

        // Default case         $this->assertSame('path/to/file1', $fileLoader->import('my_resource'));

        
Home | Imprint | This part of the site doesn't use cookies.