Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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\Loader\DelegatingLoader;
use Symfony\Component\Config\Loader\LoaderResolver;
class DelegatingLoaderTest extends TestCase
{
public function testConstructor()
{
new DelegatingLoader($resolver = new LoaderResolver());
$this->assertTrue(true, '__construct() takes a loader resolver as its first argument');
}
public function testGetSetResolver()
{
$resolver = new LoaderResolver();
$loader = new DelegatingLoader($resolver);
$this->assertSame($resolver, $loader->getResolver(), '->getResolver() gets the resolver loader');
$loader->setResolver($resolver = new LoaderResolver());
$this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader');
}
public function testSupports()
{
$loader1 = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$loader1->expects($this->once())->method('supports')->willReturn(true);
$loader = new DelegatingLoader(new LoaderResolver([$loader1]));
$this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable');
$loader1 = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$loader1->expects($this->once())->method('supports')->willReturn(false);
$loader = new DelegatingLoader(new LoaderResolver([$loader1]));
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns false if the resource is not loadable');
}
public function testLoad()
{
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$loader->expects($this->once())->method('supports')->willReturn(true);
$loader->expects($this->once())->method('load');
$resolver = new LoaderResolver([$loader]);
$loader = new DelegatingLoader($resolver);
$loader->load('foo');
}
public function testLoadThrowsAnExceptionIfTheResourceCannotBeLoaded()
{
$this->expectException('Symfony\Component\Config\Exception\FileLoaderLoadException');
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$loader->expects($this->once())->method('supports')->willReturn(false);
$resolver = new LoaderResolver([$loader]);
$loader = new DelegatingLoader($resolver);
$loader->load('foo');
}
}

View File

@@ -0,0 +1,128 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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(
['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'));
// 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 = [];
}
public function setSupports($supports)
{
$this->supports = $supports;
}
}

View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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\Loader\LoaderResolver;
class LoaderResolverTest extends TestCase
{
public function testConstructor()
{
$resolver = new LoaderResolver([
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock(),
]);
$this->assertEquals([$loader], $resolver->getLoaders(), '__construct() takes an array of loaders as its first argument');
}
public function testResolve()
{
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$resolver = new LoaderResolver([$loader]);
$this->assertFalse($resolver->resolve('foo.foo'), '->resolve() returns false if no loader is able to load the resource');
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$loader->expects($this->once())->method('supports')->willReturn(true);
$resolver = new LoaderResolver([$loader]);
$this->assertEquals($loader, $resolver->resolve(function () {}), '->resolve() returns the loader for the given resource');
}
public function testLoaders()
{
$resolver = new LoaderResolver();
$resolver->addLoader($loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock());
$this->assertEquals([$loader], $resolver->getLoaders(), 'addLoader() adds a loader');
}
}

View File

@@ -0,0 +1,116 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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\Loader\Loader;
class LoaderTest extends TestCase
{
public function testGetSetResolver()
{
$resolver = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderResolverInterface')->getMock();
$loader = new ProjectLoader1();
$loader->setResolver($resolver);
$this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader');
}
public function testResolve()
{
$resolvedLoader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$resolver = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderResolverInterface')->getMock();
$resolver->expects($this->once())
->method('resolve')
->with('foo.xml')
->willReturn($resolvedLoader);
$loader = new ProjectLoader1();
$loader->setResolver($resolver);
$this->assertSame($loader, $loader->resolve('foo.foo'), '->resolve() finds a loader');
$this->assertSame($resolvedLoader, $loader->resolve('foo.xml'), '->resolve() finds a loader');
}
public function testResolveWhenResolverCannotFindLoader()
{
$this->expectException('Symfony\Component\Config\Exception\FileLoaderLoadException');
$resolver = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderResolverInterface')->getMock();
$resolver->expects($this->once())
->method('resolve')
->with('FOOBAR')
->willReturn(false);
$loader = new ProjectLoader1();
$loader->setResolver($resolver);
$loader->resolve('FOOBAR');
}
public function testImport()
{
$resolvedLoader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$resolvedLoader->expects($this->once())
->method('load')
->with('foo')
->willReturn('yes');
$resolver = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderResolverInterface')->getMock();
$resolver->expects($this->once())
->method('resolve')
->with('foo')
->willReturn($resolvedLoader);
$loader = new ProjectLoader1();
$loader->setResolver($resolver);
$this->assertEquals('yes', $loader->import('foo'));
}
public function testImportWithType()
{
$resolvedLoader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$resolvedLoader->expects($this->once())
->method('load')
->with('foo', 'bar')
->willReturn('yes');
$resolver = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderResolverInterface')->getMock();
$resolver->expects($this->once())
->method('resolve')
->with('foo', 'bar')
->willReturn($resolvedLoader);
$loader = new ProjectLoader1();
$loader->setResolver($resolver);
$this->assertEquals('yes', $loader->import('foo', 'bar'));
}
}
class ProjectLoader1 extends Loader
{
public function load($resource, $type = null)
{
}
public function supports($resource, $type = null)
{
return \is_string($resource) && 'foo' === pathinfo($resource, \PATHINFO_EXTENSION);
}
public function getType()
{
}
}