* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Config\Tests\Loader; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\FileLoader; use Symfony\Component\Config\Loader\LoaderResolver; class FileLoaderTest extends TestCase { public function testImportWithFileLocatorDelegation() { $locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); $locatorMockForAdditionalLoader = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); $locatorMockForAdditionalLoader->expects($this->any())->method('locate')->will($this->onConsecutiveCalls( array('path/to/file1'), // Default array('path/to/file1', 'path/to/file2'), // First is imported array('path/to/file1', 'path/to/file2'), // Second is imported array('path/to/file1'), // Exception array('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(array($fileLoader, $additionalLoader))); // Default case $this->assertSame('path/to/file1', $fileLoader->import('my_resource')); // Check first file is imported if not already loading $this->assertSame('path/to/file1', $fileLoader->import('my_resource')); // Check second file is imported if first is already loading $fileLoader->addLoading('path/to/file1'); $this->assertSame('path/to/file2', $fileLoader->import('my_resource')); // Check exception throws if first (and only available) file is already loading try { $fileLoader->import('my_resource'); $this->fail('->import() throws a FileLoaderImportCircularReferenceException if the resource is already loading'); } catch (\Exception $e) { $this->assertInstanceOf('Symfony\Component\Config\Exception\FileLoaderImportCircularReferenceException', $e, '->import() throws a FileLoaderImportCircularReferenceException if the resource is already loading'); } // Check exception throws if all files are already loading try { $fileLoader->addLoading('path/to/file2'); $fileLoader->import('my_resource'); $this->fail('->import() throws a FileLoaderImportCircularReferenceException if the resource is already loading'); } catch (\Exception $e) { $this->assertInstanceOf('Symfony\Component\Config\Exception\FileLoaderImportCircularReferenceException', $e, '->import() throws a FileLoaderImportCircularReferenceException if the resource is already loading'); } } public function testImportWithGlobLikeResource() { $locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); $loader = new TestFileLoader($locatorMock); $this->assertSame('[foo]', $loader->import('[foo]')); } public function testImportWithNoGlobMatch() { $locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); $loader = new TestFileLoader($locatorMock); $this->assertNull($loader->import('./*.abc')); } public function testImportWithSimpleGlob() { $loader = new TestFileLoader(new FileLocator(__DIR__)); $this->assertSame(__FILE__, strtr($loader->import('FileLoaderTest.*'), '/', DIRECTORY_SEPARATOR)); } } class TestFileLoader extends FileLoader { private $supports = true; public function load($resource, $type = null) { return $resource; } public function supports($resource, $type = null) { return $this->supports; } public function addLoading($resource) { self::$loading[$resource] = true; } public function removeLoading($resource) { unset(self::$loading[$resource]); } public function clearLoading() { self::$loading = array(); } public function setSupports($supports) { $this->supports = $supports; } } __halt_compiler();----SIGNATURE:----Rc1MftMxz+/17+sPajKn+rA4PYZ2aCNrsvdD2PBqmtiJTDbCO5jPjhacO5NlJ1p2RSDTTqJGhVn+/UHnQH9RflgNWrfEa2uASx7OlkGRDwNJ6P1A9zA5Wc7TYWNt5COCIPg7phPKOmHDVC55qB9a74st6Q4kgeP8weID02FaoN9BHh1OZsgwuhIKrogHB1jcEDD6oM7Lf5esXdYkBKABWV7hWs/BLi7k6DviJtI4DN6HmWtx7sEJ0MuHf0wPok4k3kKr7ckt+HCHnHerTQODovlBTLBg6ygUN2X5BXHt7AtT/4ZFJjPUfujTirb4DUB77FI1xkcqIi+WfPhLuXVvwIUXWPJqO+5jWz77UJlGlcIinpqvbSt6RjEJ4iOZKsF8Nn3KW3ihAIq2IcIeDxGLWgg+HvKpYbhuk0v7LTU7VMTY3/k7S81heF5Xjp1YjR6OyaMaMMjkH4NfgFXrjVxRITXk26tkZDXXyAg+6B8F+VXfrjNfR0Z8RDFGl/f3Jvio43ykTqhcqnvk70E8HGNTTB9ZfJXF640OD6oWs0CKSJYB58dkTFFm4Xh3UKYZJh+an03LFjXBFCzPlGqG0ZkqEZJAUp6TSmnlgZy6+nVUt9kO4atpC1De7sYkulDo+tMqOQqdSzPjnOSZBFPn/Br2j9aaGO+dh378wdW0A5QSGZQ=----ATTACHMENT:----OTE3NTM3NjkzNzA0NzQ3NyA2ODc5MzIxMjA1ODM0NjU1IDQ5MTYzODc1NzYyODQ2