composer updated
propel installed but not integrated yet new autoload process including classMap
This commit is contained in:
2
core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/.gitattributes
vendored
Normal file
2
core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/Tests export-ignore
|
||||
phpunit.xml.dist export-ignore
|
||||
@@ -20,6 +20,7 @@ class ClassCollectionLoader
|
||||
{
|
||||
private static $loaded;
|
||||
private static $seen;
|
||||
private static $useTokenizer = true;
|
||||
|
||||
/**
|
||||
* Loads a list of classes and caches them in one big file.
|
||||
@@ -135,7 +136,11 @@ class ClassCollectionLoader
|
||||
*/
|
||||
public static function fixNamespaceDeclarations($source)
|
||||
{
|
||||
if (!function_exists('token_get_all')) {
|
||||
if (!function_exists('token_get_all') || !self::$useTokenizer) {
|
||||
if (preg_match('/namespace(.*?)\s*;/', $source)) {
|
||||
$source = preg_replace('/namespace(.*?)\s*;/', "namespace$1\n{", $source)."}\n";
|
||||
}
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
||||
@@ -317,4 +322,12 @@ class ClassCollectionLoader
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is only useful for testing.
|
||||
*/
|
||||
public static function enableTokenizer($bool)
|
||||
{
|
||||
self::$useTokenizer = (Boolean) $bool;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,192 +0,0 @@
|
||||
<?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\ClassLoader\Tests;
|
||||
|
||||
use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
|
||||
|
||||
class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!extension_loaded('apc')) {
|
||||
$this->markTestSkipped('The apc extension is not available.');
|
||||
}
|
||||
|
||||
if (!(ini_get('apc.enabled') && ini_get('apc.enable_cli'))) {
|
||||
$this->markTestSkipped('The apc extension is available, but not enabled.');
|
||||
} else {
|
||||
apc_clear_cache('user');
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (ini_get('apc.enabled') && ini_get('apc.enable_cli')) {
|
||||
apc_clear_cache('user');
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.');
|
||||
$loader->registerNamespace('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
|
||||
$this->assertEquals($loader->findFile('\Apc\Namespaced\FooBar'), apc_fetch('test.prefix.\Apc\Namespaced\FooBar'), '__construct() takes a prefix as its first argument');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassTests
|
||||
*/
|
||||
public function testLoadClass($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.');
|
||||
$loader->registerNamespace('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerPrefix('Apc_Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Apc\\Namespaced\\Foo', '\\Apc\\Namespaced\\Foo', '->loadClass() loads Apc\Namespaced\Foo class'),
|
||||
array('Apc_Pearlike_Foo', 'Apc_Pearlike_Foo', '->loadClass() loads Apc_Pearlike_Foo class'),
|
||||
array('\\Apc\\Namespaced\\Bar', '\\Apc\\Namespaced\\Bar', '->loadClass() loads Apc\Namespaced\Bar class with a leading slash'),
|
||||
array('Apc_Pearlike_Bar', '\\Apc_Pearlike_Bar', '->loadClass() loads Apc_Pearlike_Bar class with a leading slash'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassFromFallbackTests
|
||||
*/
|
||||
public function testLoadClassFromFallback($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.fallback');
|
||||
$loader->registerNamespace('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerPrefix('Apc_Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerNamespaceFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/fallback'));
|
||||
$loader->registerPrefixFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/fallback'));
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassFromFallbackTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Apc\\Namespaced\\Baz', '\\Apc\\Namespaced\\Baz', '->loadClass() loads Apc\Namespaced\Baz class'),
|
||||
array('Apc_Pearlike_Baz', 'Apc_Pearlike_Baz', '->loadClass() loads Apc_Pearlike_Baz class'),
|
||||
array('\\Apc\\Namespaced\\FooBar', '\\Apc\\Namespaced\\FooBar', '->loadClass() loads Apc\Namespaced\Baz class from fallback dir'),
|
||||
array('Apc_Pearlike_FooBar', 'Apc_Pearlike_FooBar', '->loadClass() loads Apc_Pearlike_Baz class from fallback dir'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassNamespaceCollisionTests
|
||||
*/
|
||||
public function testLoadClassNamespaceCollision($namespaces, $className, $message)
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.collision.');
|
||||
$loader->registerNamespaces($namespaces);
|
||||
|
||||
$loader->loadClass($className);
|
||||
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassNamespaceCollisionTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
),
|
||||
'\Apc\NamespaceCollision\A\Foo',
|
||||
'->loadClass() loads NamespaceCollision\A\Foo from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
),
|
||||
'\Apc\NamespaceCollision\A\Bar',
|
||||
'->loadClass() loads NamespaceCollision\A\Bar from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
),
|
||||
'\Apc\NamespaceCollision\A\B\Foo',
|
||||
'->loadClass() loads NamespaceCollision\A\B\Foo from beta.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
|
||||
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
|
||||
),
|
||||
'\Apc\NamespaceCollision\A\B\Bar',
|
||||
'->loadClass() loads NamespaceCollision\A\B\Bar from beta.',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassPrefixCollisionTests
|
||||
*/
|
||||
public function testLoadClassPrefixCollision($prefixes, $className, $message)
|
||||
{
|
||||
$loader = new ApcUniversalClassLoader('test.prefix.collision.');
|
||||
$loader->registerPrefixes($prefixes);
|
||||
|
||||
$loader->loadClass($className);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassPrefixCollisionTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
'ApcPrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
|
||||
),
|
||||
'ApcPrefixCollision_A_Foo',
|
||||
'->loadClass() loads ApcPrefixCollision_A_Foo from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'ApcPrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
|
||||
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
),
|
||||
'ApcPrefixCollision_A_Bar',
|
||||
'->loadClass() loads ApcPrefixCollision_A_Bar from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
'ApcPrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
|
||||
),
|
||||
'ApcPrefixCollision_A_B_Foo',
|
||||
'->loadClass() loads ApcPrefixCollision_A_B_Foo from beta.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'ApcPrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
|
||||
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
|
||||
),
|
||||
'ApcPrefixCollision_A_B_Bar',
|
||||
'->loadClass() loads ApcPrefixCollision_A_B_Bar from beta.',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
<?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\ClassLoader\Tests;
|
||||
|
||||
use Symfony\Component\ClassLoader\ClassCollectionLoader;
|
||||
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/GInterface.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/CInterface.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/B.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/A.php';
|
||||
|
||||
class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getDifferentOrders
|
||||
*/
|
||||
public function testClassReordering(array $classes)
|
||||
{
|
||||
$expected = array(
|
||||
'ClassesWithParents\\GInterface',
|
||||
'ClassesWithParents\\CInterface',
|
||||
'ClassesWithParents\\B',
|
||||
'ClassesWithParents\\A',
|
||||
);
|
||||
|
||||
$r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
|
||||
$m = $r->getMethod('getOrderedClasses');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
|
||||
|
||||
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
|
||||
}
|
||||
|
||||
public function getDifferentOrders()
|
||||
{
|
||||
return array(
|
||||
array(array(
|
||||
'ClassesWithParents\\A',
|
||||
'ClassesWithParents\\CInterface',
|
||||
'ClassesWithParents\\GInterface',
|
||||
'ClassesWithParents\\B',
|
||||
)),
|
||||
array(array(
|
||||
'ClassesWithParents\\B',
|
||||
'ClassesWithParents\\A',
|
||||
'ClassesWithParents\\CInterface',
|
||||
)),
|
||||
array(array(
|
||||
'ClassesWithParents\\CInterface',
|
||||
'ClassesWithParents\\B',
|
||||
'ClassesWithParents\\A',
|
||||
)),
|
||||
array(array(
|
||||
'ClassesWithParents\\A',
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getDifferentOrdersForTraits
|
||||
*/
|
||||
public function testClassWithTraitsReordering(array $classes)
|
||||
{
|
||||
if (version_compare(phpversion(), '5.4.0', '<')) {
|
||||
$this->markTestSkipped('Requires PHP > 5.4.0.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/ATrait.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/BTrait.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/CTrait.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/D.php';
|
||||
require_once __DIR__.'/Fixtures/ClassesWithParents/E.php';
|
||||
|
||||
$expected = array(
|
||||
'ClassesWithParents\\GInterface',
|
||||
'ClassesWithParents\\CInterface',
|
||||
'ClassesWithParents\\CTrait',
|
||||
'ClassesWithParents\\ATrait',
|
||||
'ClassesWithParents\\BTrait',
|
||||
'ClassesWithParents\\B',
|
||||
'ClassesWithParents\\A',
|
||||
'ClassesWithParents\\D',
|
||||
'ClassesWithParents\\E',
|
||||
);
|
||||
|
||||
$r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
|
||||
$m = $r->getMethod('getOrderedClasses');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
|
||||
|
||||
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
|
||||
}
|
||||
|
||||
public function getDifferentOrdersForTraits()
|
||||
{
|
||||
return array(
|
||||
array(array(
|
||||
'ClassesWithParents\\E',
|
||||
'ClassesWithParents\\ATrait',
|
||||
)),
|
||||
array(array(
|
||||
'ClassesWithParents\\E',
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
public function testFixNamespaceDeclarations()
|
||||
{
|
||||
$source = <<<EOF
|
||||
<?php
|
||||
|
||||
namespace Foo;
|
||||
class Foo {}
|
||||
namespace Bar ;
|
||||
class Foo {}
|
||||
namespace Foo\Bar;
|
||||
class Foo {}
|
||||
namespace Foo\Bar\Bar
|
||||
{
|
||||
class Foo {}
|
||||
}
|
||||
namespace
|
||||
{
|
||||
class Foo {}
|
||||
}
|
||||
EOF;
|
||||
|
||||
$expected = <<<EOF
|
||||
<?php
|
||||
|
||||
namespace Foo
|
||||
{
|
||||
class Foo {}
|
||||
}
|
||||
namespace Bar
|
||||
{
|
||||
class Foo {}
|
||||
}
|
||||
namespace Foo\Bar
|
||||
{
|
||||
class Foo {}
|
||||
}
|
||||
namespace Foo\Bar\Bar
|
||||
{
|
||||
class Foo {}
|
||||
}
|
||||
namespace
|
||||
{
|
||||
class Foo {}
|
||||
}
|
||||
EOF;
|
||||
|
||||
$this->assertEquals($expected, ClassCollectionLoader::fixNamespaceDeclarations($source));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testUnableToLoadClassException()
|
||||
{
|
||||
ClassCollectionLoader::load(array('SomeNotExistingClass'), '', 'foo', false);
|
||||
}
|
||||
|
||||
public function testLoadTwiceClass()
|
||||
{
|
||||
ClassCollectionLoader::load(array('Foo'), '', 'foo', false);
|
||||
ClassCollectionLoader::load(array('Foo'), '', 'foo', false);
|
||||
}
|
||||
}
|
||||
@@ -1,214 +0,0 @@
|
||||
<?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\ClassLoader\Tests;
|
||||
|
||||
use Symfony\Component\ClassLoader\ClassLoader;
|
||||
|
||||
class ClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetPrefixes()
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Bar', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Bas', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$prefixes = $loader->getPrefixes();
|
||||
$this->assertArrayHasKey('Foo', $prefixes);
|
||||
$this->assertArrayNotHasKey('Foo1', $prefixes);
|
||||
$this->assertArrayHasKey('Bar', $prefixes);
|
||||
$this->assertArrayHasKey('Bas', $prefixes);
|
||||
}
|
||||
|
||||
public function testGetFallbackDirs()
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix(null, __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix(null, __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$fallback_dirs = $loader->getFallbackDirs();
|
||||
$this->assertCount(2, $fallback_dirs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassTests
|
||||
*/
|
||||
public function testLoadClass($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Namespaced2\\', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Pearlike2_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Namespaced2\\Foo', 'Namespaced2\\Foo', '->loadClass() loads Namespaced2\Foo class'),
|
||||
array('\\Pearlike2_Foo', 'Pearlike2_Foo', '->loadClass() loads Pearlike2_Foo class'),
|
||||
array('\\Namespaced2\\Bar', '\\Namespaced2\\Bar', '->loadClass() loads Namespaced2\Bar class with a leading slash'),
|
||||
array('\\Pearlike2_Bar', '\\Pearlike2_Bar', '->loadClass() loads Pearlike2_Bar class with a leading slash'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadNonexistentClassTests
|
||||
*/
|
||||
public function testLoadNonexistentClass($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Namespaced2\\', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Pearlike2_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertFalse(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadNonexistentClassTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Pearlike3_Bar', '\\Pearlike3_Bar', '->loadClass() loads non exising Pearlike3_Bar class with a leading slash'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testAddPrefix()
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$prefixes = $loader->getPrefixes();
|
||||
$this->assertArrayHasKey('Foo', $prefixes);
|
||||
$this->assertCount(2, $prefixes['Foo']);
|
||||
}
|
||||
|
||||
public function testUseIncludePath()
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$this->assertFalse($loader->getUseIncludePath());
|
||||
|
||||
$this->assertNull($loader->findFile('Foo'));
|
||||
|
||||
$includePath = get_include_path();
|
||||
|
||||
$loader->setUseIncludePath(true);
|
||||
$this->assertTrue($loader->getUseIncludePath());
|
||||
|
||||
set_include_path(__DIR__.'/Fixtures/includepath' . PATH_SEPARATOR . $includePath);
|
||||
|
||||
$this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'includepath'.DIRECTORY_SEPARATOR.'Foo.php', $loader->findFile('Foo'));
|
||||
|
||||
set_include_path($includePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassFromFallbackTests
|
||||
*/
|
||||
public function testLoadClassFromFallback($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefix('Namespaced2\\', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('Pearlike2_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->addPrefix('', array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback'));
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassFromFallbackTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Namespaced2\\Baz', 'Namespaced2\\Baz', '->loadClass() loads Namespaced2\Baz class'),
|
||||
array('\\Pearlike2_Baz', 'Pearlike2_Baz', '->loadClass() loads Pearlike2_Baz class'),
|
||||
array('\\Namespaced2\\FooBar', 'Namespaced2\\FooBar', '->loadClass() loads Namespaced2\Baz class from fallback dir'),
|
||||
array('\\Pearlike2_FooBar', 'Pearlike2_FooBar', '->loadClass() loads Pearlike2_Baz class from fallback dir'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassNamespaceCollisionTests
|
||||
*/
|
||||
public function testLoadClassNamespaceCollision($namespaces, $className, $message)
|
||||
{
|
||||
$loader = new ClassLoader();
|
||||
$loader->addPrefixes($namespaces);
|
||||
|
||||
$loader->loadClass($className);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassNamespaceCollisionTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'NamespaceCollision\\C' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'NamespaceCollision\\C\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
),
|
||||
'NamespaceCollision\C\Foo',
|
||||
'->loadClass() loads NamespaceCollision\C\Foo from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'NamespaceCollision\\C\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'NamespaceCollision\\C' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
),
|
||||
'NamespaceCollision\C\Bar',
|
||||
'->loadClass() loads NamespaceCollision\C\Bar from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'NamespaceCollision\\C' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'NamespaceCollision\\C\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
),
|
||||
'NamespaceCollision\C\B\Foo',
|
||||
'->loadClass() loads NamespaceCollision\C\B\Foo from beta.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'NamespaceCollision\\C\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'NamespaceCollision\\C' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
),
|
||||
'NamespaceCollision\C\B\Bar',
|
||||
'->loadClass() loads NamespaceCollision\C\B\Bar from beta.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'PrefixCollision_C_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'PrefixCollision_C_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
),
|
||||
'PrefixCollision_C_Foo',
|
||||
'->loadClass() loads PrefixCollision_C_Foo from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'PrefixCollision_C_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'PrefixCollision_C_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
),
|
||||
'PrefixCollision_C_Bar',
|
||||
'->loadClass() loads PrefixCollision_C_Bar from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'PrefixCollision_C_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'PrefixCollision_C_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
),
|
||||
'PrefixCollision_C_B_Foo',
|
||||
'->loadClass() loads PrefixCollision_C_B_Foo from beta.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'PrefixCollision_C_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'PrefixCollision_C_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
),
|
||||
'PrefixCollision_C_B_Bar',
|
||||
'->loadClass() loads PrefixCollision_C_B_Bar from beta.',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
<?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\ClassLoader\Tests;
|
||||
|
||||
use Symfony\Component\ClassLoader\ClassMapGenerator;
|
||||
|
||||
class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var string $workspace
|
||||
*/
|
||||
private $workspace = null;
|
||||
|
||||
public function prepare_workspace()
|
||||
{
|
||||
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().rand(0, 1000);
|
||||
mkdir($this->workspace, 0777, true);
|
||||
$this->workspace = realpath($this->workspace);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
*/
|
||||
private function clean($file)
|
||||
{
|
||||
if (is_dir($file) && !is_link($file)) {
|
||||
$dir = new \FilesystemIterator($file);
|
||||
foreach ($dir as $childFile) {
|
||||
$this->clean($childFile);
|
||||
}
|
||||
|
||||
rmdir($file);
|
||||
} else {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestCreateMapTests
|
||||
*/
|
||||
public function testDump($directory, $expected)
|
||||
{
|
||||
$this->prepare_workspace();
|
||||
|
||||
$file = $this->workspace.'/file';
|
||||
|
||||
$generator = new ClassMapGenerator();
|
||||
$generator->dump($directory, $file);
|
||||
$this->assertFileExists($file);
|
||||
|
||||
$this->clean($this->workspace);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestCreateMapTests
|
||||
*/
|
||||
public function testCreateMap($directory, $expected)
|
||||
{
|
||||
$this->assertEqualsNormalized($expected, ClassMapGenerator::createMap($directory));
|
||||
}
|
||||
|
||||
public function getTestCreateMapTests()
|
||||
{
|
||||
$data = array(
|
||||
array(__DIR__.'/Fixtures/Namespaced', array(
|
||||
'Namespaced\\Bar' => realpath(__DIR__).'/Fixtures/Namespaced/Bar.php',
|
||||
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
|
||||
'Namespaced\\Baz' => realpath(__DIR__).'/Fixtures/Namespaced/Baz.php',
|
||||
)
|
||||
),
|
||||
array(__DIR__.'/Fixtures/beta/NamespaceCollision', array(
|
||||
'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Bar.php',
|
||||
'NamespaceCollision\\A\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Foo.php',
|
||||
'NamespaceCollision\\C\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/C/B/Bar.php',
|
||||
'NamespaceCollision\\C\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/C/B/Foo.php',
|
||||
)),
|
||||
array(__DIR__.'/Fixtures/Pearlike', array(
|
||||
'Pearlike_Foo' => realpath(__DIR__).'/Fixtures/Pearlike/Foo.php',
|
||||
'Pearlike_Bar' => realpath(__DIR__).'/Fixtures/Pearlike/Bar.php',
|
||||
'Pearlike_Baz' => realpath(__DIR__).'/Fixtures/Pearlike/Baz.php',
|
||||
)),
|
||||
array(__DIR__.'/Fixtures/classmap', array(
|
||||
'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
|
||||
'Foo\\Bar\\B' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
|
||||
'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Alpha\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Beta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Beta\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'ClassMap\\SomeInterface' => realpath(__DIR__).'/Fixtures/classmap/SomeInterface.php',
|
||||
'ClassMap\\SomeParent' => realpath(__DIR__).'/Fixtures/classmap/SomeParent.php',
|
||||
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
|
||||
)),
|
||||
);
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.4', '>=')) {
|
||||
$data[] = array(__DIR__.'/Fixtures/php5.4', array(
|
||||
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\TBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\IBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\TFooBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\CBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
));
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testCreateMapFinderSupport()
|
||||
{
|
||||
if (!class_exists('Symfony\\Component\\Finder\\Finder')) {
|
||||
$this->markTestSkipped('Finder component is not available');
|
||||
}
|
||||
|
||||
$finder = new \Symfony\Component\Finder\Finder();
|
||||
$finder->files()->in(__DIR__ . '/Fixtures/beta/NamespaceCollision');
|
||||
|
||||
$this->assertEqualsNormalized(array(
|
||||
'NamespaceCollision\\A\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Bar.php',
|
||||
'NamespaceCollision\\A\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/A/B/Foo.php',
|
||||
'NamespaceCollision\\C\\B\\Bar' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/C/B/Bar.php',
|
||||
'NamespaceCollision\\C\\B\\Foo' => realpath(__DIR__).'/Fixtures/beta/NamespaceCollision/C/B/Foo.php',
|
||||
), ClassMapGenerator::createMap($finder));
|
||||
}
|
||||
|
||||
protected function assertEqualsNormalized($expected, $actual, $message = null)
|
||||
{
|
||||
foreach ($expected as $ns => $path) {
|
||||
$expected[$ns] = strtr($path, '\\', '/');
|
||||
}
|
||||
foreach ($actual as $ns => $path) {
|
||||
$actual[$ns] = strtr($path, '\\', '/');
|
||||
}
|
||||
$this->assertEquals($expected, $actual, $message);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Apc\Namespaced;
|
||||
|
||||
class Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Apc\Namespaced;
|
||||
|
||||
class Baz
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Apc\Namespaced;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Apc\Namespaced;
|
||||
|
||||
class FooBar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Apc_Pearlike_Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Apc_Pearlike_Baz
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Apc_Pearlike_Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ApcPrefixCollision_A_Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ApcPrefixCollision_A_Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Apc\NamespaceCollision\A;
|
||||
|
||||
class Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Apc\NamespaceCollision\A;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ApcPrefixCollision_A_B_Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ApcPrefixCollision_A_B_Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Apc\NamespaceCollision\A\B;
|
||||
|
||||
class Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Apc\NamespaceCollision\A\B;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Apc_Pearlike_FooBar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Apc\Namespaced;
|
||||
|
||||
class FooBar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
class A extends B {}
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
trait ATrait
|
||||
{
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
class B implements CInterface {}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
trait BTrait
|
||||
{
|
||||
use ATrait;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
interface CInterface extends GInterface
|
||||
{
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
trait CTrait
|
||||
{
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
class D extends A
|
||||
{
|
||||
use BTrait;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
class E extends D
|
||||
{
|
||||
use CTrait;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ClassesWithParents;
|
||||
|
||||
interface GInterface
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Namespaced;
|
||||
|
||||
class Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Namespaced;
|
||||
|
||||
class Baz
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Namespaced;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Namespaced2;
|
||||
|
||||
class Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Namespaced2;
|
||||
|
||||
class Baz
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Namespaced2;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Pearlike_Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Pearlike_Baz
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Pearlike_Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Pearlike2_Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Pearlike2_Baz
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Pearlike2_Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 NamespaceCollision\A;
|
||||
|
||||
class Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 NamespaceCollision\A;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace NamespaceCollision\C;
|
||||
|
||||
class Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace NamespaceCollision\C;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class PrefixCollision_A_Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class PrefixCollision_A_Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class PrefixCollision_C_Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class PrefixCollision_C_Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 NamespaceCollision\A\B;
|
||||
|
||||
class Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 NamespaceCollision\A\B;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace NamespaceCollision\C\B;
|
||||
|
||||
class Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace NamespaceCollision\C\B;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class PrefixCollision_A_B_Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class PrefixCollision_A_B_Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class PrefixCollision_C_B_Bar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class PrefixCollision_C_B_Foo
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 ClassMap;
|
||||
|
||||
class SomeClass extends SomeParent implements SomeInterface
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 ClassMap;
|
||||
|
||||
interface SomeInterface
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 ClassMap;
|
||||
|
||||
abstract class SomeParent
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
namespace {
|
||||
class A {}
|
||||
}
|
||||
|
||||
namespace Alpha {
|
||||
class A {}
|
||||
class B {}
|
||||
}
|
||||
|
||||
namespace Beta {
|
||||
class A {}
|
||||
class B {}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
$a = new stdClass();
|
||||
@@ -1 +0,0 @@
|
||||
This file should be skipped.
|
||||
@@ -1,15 +0,0 @@
|
||||
<?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 Foo\Bar;
|
||||
|
||||
class A {}
|
||||
class B {}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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 Namespaced;
|
||||
|
||||
class FooBar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Namespaced2;
|
||||
|
||||
class FooBar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Pearlike_FooBar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Pearlike2_FooBar
|
||||
{
|
||||
public static $loaded = true;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Foo
|
||||
{
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
namespace {
|
||||
trait TFoo
|
||||
{
|
||||
}
|
||||
|
||||
class CFoo
|
||||
{
|
||||
use TFoo;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Foo {
|
||||
trait TBar
|
||||
{
|
||||
}
|
||||
|
||||
interface IBar
|
||||
{
|
||||
}
|
||||
|
||||
trait TFooBar
|
||||
{
|
||||
}
|
||||
|
||||
class CBar implements IBar
|
||||
{
|
||||
use TBar, TFooBar;
|
||||
}
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
<?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\ClassLoader\Tests;
|
||||
|
||||
use Symfony\Component\ClassLoader\UniversalClassLoader;
|
||||
|
||||
class UniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getLoadClassTests
|
||||
*/
|
||||
public function testLoadClass($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->registerNamespace('Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerPrefix('Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Namespaced\\Foo', 'Namespaced\\Foo', '->loadClass() loads Namespaced\Foo class'),
|
||||
array('\\Pearlike_Foo', 'Pearlike_Foo', '->loadClass() loads Pearlike_Foo class'),
|
||||
array('\\Namespaced\\Bar', '\\Namespaced\\Bar', '->loadClass() loads Namespaced\Bar class with a leading slash'),
|
||||
array('\\Pearlike_Bar', '\\Pearlike_Bar', '->loadClass() loads Pearlike_Bar class with a leading slash'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testUseIncludePath()
|
||||
{
|
||||
$loader = new UniversalClassLoader();
|
||||
$this->assertFalse($loader->getUseIncludePath());
|
||||
|
||||
$this->assertNull($loader->findFile('Foo'));
|
||||
|
||||
$includePath = get_include_path();
|
||||
|
||||
$loader->useIncludePath(true);
|
||||
$this->assertTrue($loader->getUseIncludePath());
|
||||
|
||||
set_include_path(__DIR__.'/Fixtures/includepath' . PATH_SEPARATOR . $includePath);
|
||||
|
||||
$this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'includepath'.DIRECTORY_SEPARATOR.'Foo.php', $loader->findFile('Foo'));
|
||||
|
||||
set_include_path($includePath);
|
||||
}
|
||||
|
||||
public function testGetNamespaces()
|
||||
{
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->registerNamespace('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerNamespace('Bar', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerNamespace('Bas', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$namespaces = $loader->getNamespaces();
|
||||
$this->assertArrayHasKey('Foo', $namespaces);
|
||||
$this->assertArrayNotHasKey('Foo1', $namespaces);
|
||||
$this->assertArrayHasKey('Bar', $namespaces);
|
||||
$this->assertArrayHasKey('Bas', $namespaces);
|
||||
}
|
||||
|
||||
public function testGetPrefixes()
|
||||
{
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->registerPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerPrefix('Bar', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerPrefix('Bas', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$prefixes = $loader->getPrefixes();
|
||||
$this->assertArrayHasKey('Foo', $prefixes);
|
||||
$this->assertArrayNotHasKey('Foo1', $prefixes);
|
||||
$this->assertArrayHasKey('Bar', $prefixes);
|
||||
$this->assertArrayHasKey('Bas', $prefixes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassFromFallbackTests
|
||||
*/
|
||||
public function testLoadClassFromFallback($className, $testClassName, $message)
|
||||
{
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->registerNamespace('Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerPrefix('Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
|
||||
$loader->registerNamespaceFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback'));
|
||||
$loader->registerPrefixFallbacks(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback'));
|
||||
$loader->loadClass($testClassName);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassFromFallbackTests()
|
||||
{
|
||||
return array(
|
||||
array('\\Namespaced\\Baz', 'Namespaced\\Baz', '->loadClass() loads Namespaced\Baz class'),
|
||||
array('\\Pearlike_Baz', 'Pearlike_Baz', '->loadClass() loads Pearlike_Baz class'),
|
||||
array('\\Namespaced\\FooBar', 'Namespaced\\FooBar', '->loadClass() loads Namespaced\Baz class from fallback dir'),
|
||||
array('\\Pearlike_FooBar', 'Pearlike_FooBar', '->loadClass() loads Pearlike_Baz class from fallback dir'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testRegisterPrefixFallback()
|
||||
{
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->registerPrefixFallback(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback');
|
||||
$this->assertEquals(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/fallback'), $loader->getPrefixFallbacks());
|
||||
}
|
||||
|
||||
public function testRegisterNamespaceFallback()
|
||||
{
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->registerNamespaceFallback(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/Namespaced/fallback');
|
||||
$this->assertEquals(array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/Namespaced/fallback'), $loader->getNamespaceFallbacks());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassNamespaceCollisionTests
|
||||
*/
|
||||
public function testLoadClassNamespaceCollision($namespaces, $className, $message)
|
||||
{
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->registerNamespaces($namespaces);
|
||||
|
||||
$loader->loadClass($className);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassNamespaceCollisionTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
),
|
||||
'NamespaceCollision\A\Foo',
|
||||
'->loadClass() loads NamespaceCollision\A\Foo from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
),
|
||||
'NamespaceCollision\A\Bar',
|
||||
'->loadClass() loads NamespaceCollision\A\Bar from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
),
|
||||
'NamespaceCollision\A\B\Foo',
|
||||
'->loadClass() loads NamespaceCollision\A\B\Foo from beta.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
),
|
||||
'NamespaceCollision\A\B\Bar',
|
||||
'->loadClass() loads NamespaceCollision\A\B\Bar from beta.',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadClassPrefixCollisionTests
|
||||
*/
|
||||
public function testLoadClassPrefixCollision($prefixes, $className, $message)
|
||||
{
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->registerPrefixes($prefixes);
|
||||
|
||||
$loader->loadClass($className);
|
||||
$this->assertTrue(class_exists($className), $message);
|
||||
}
|
||||
|
||||
public function getLoadClassPrefixCollisionTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'PrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'PrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
),
|
||||
'PrefixCollision_A_Foo',
|
||||
'->loadClass() loads PrefixCollision_A_Foo from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'PrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'PrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
),
|
||||
'PrefixCollision_A_Bar',
|
||||
'->loadClass() loads PrefixCollision_A_Bar from alpha.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'PrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
'PrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
),
|
||||
'PrefixCollision_A_B_Foo',
|
||||
'->loadClass() loads PrefixCollision_A_B_Foo from beta.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'PrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/beta',
|
||||
'PrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/alpha',
|
||||
),
|
||||
'PrefixCollision_A_B_Bar',
|
||||
'->loadClass() loads PrefixCollision_A_B_Bar from beta.',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
spl_autoload_register(function ($class) {
|
||||
if (0 === strpos(ltrim($class, '/'), 'Symfony\Component\ClassLoader')) {
|
||||
if (file_exists($file = __DIR__.'/../'.substr(str_replace('\\', '/', $class), strlen('Symfony\Component\ClassLoader')).'.php')) {
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (file_exists($loader = __DIR__.'/../vendor/autoload.php')) {
|
||||
require_once $loader;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="Tests/bootstrap.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Symfony ClassLoader Component Test Suite">
|
||||
<directory>./Tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./</directory>
|
||||
<exclude>
|
||||
<directory>./Resources</directory>
|
||||
<directory>./Tests</directory>
|
||||
<directory>./vendor</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
2
core/vendor/symfony/config/Symfony/Component/Config/.gitattributes
vendored
Normal file
2
core/vendor/symfony/config/Symfony/Component/Config/.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/Tests export-ignore
|
||||
phpunit.xml.dist export-ignore
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Config\Definition\Builder;
|
||||
|
||||
use Symfony\Component\Config\Definition\NodeInterface;
|
||||
use Symfony\Component\Config\Definition\ArrayNode;
|
||||
use Symfony\Component\Config\Definition\PrototypedArrayNode;
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
|
||||
|
||||
@@ -89,14 +89,14 @@ class Processor
|
||||
*
|
||||
* Here is an example.
|
||||
*
|
||||
* The configuration is XML:
|
||||
* The configuration in XML:
|
||||
*
|
||||
* <twig:extension id="twig.extension.foo" />
|
||||
* <twig:extension id="twig.extension.bar" />
|
||||
* <twig:extension>twig.extension.foo</twig:extension>
|
||||
* <twig:extension>twig.extension.bar</twig:extension>
|
||||
*
|
||||
* And the same configuration in YAML:
|
||||
*
|
||||
* twig.extensions: ['twig.extension.foo', 'twig.extension.bar']
|
||||
* extensions: ['twig.extension.foo', 'twig.extension.bar']
|
||||
*
|
||||
* @param array $config A config array
|
||||
* @param string $key The key to normalize
|
||||
|
||||
@@ -242,11 +242,11 @@ class PrototypedArrayNode extends ArrayNode
|
||||
|
||||
$value = $this->remapXml($value);
|
||||
|
||||
$isAssoc = array_keys($value) === range(0, count($value) -1);
|
||||
$isAssoc = array_keys($value) !== range(0, count($value) -1);
|
||||
$normalized = array();
|
||||
foreach ($value as $k => $v) {
|
||||
if (null !== $this->keyAttribute && is_array($v)) {
|
||||
if (!isset($v[$this->keyAttribute]) && is_int($k) && $isAssoc) {
|
||||
if (!isset($v[$this->keyAttribute]) && is_int($k) && !$isAssoc) {
|
||||
$msg = sprintf('The attribute "%s" must be set for path "%s".', $this->keyAttribute, $this->getPath());
|
||||
$ex = new InvalidConfigurationException($msg);
|
||||
$ex->setPath($this->getPath());
|
||||
@@ -276,7 +276,7 @@ class PrototypedArrayNode extends ArrayNode
|
||||
}
|
||||
|
||||
$this->prototype->setName($k);
|
||||
if (null !== $this->keyAttribute) {
|
||||
if (null !== $this->keyAttribute || $isAssoc) {
|
||||
$normalized[$k] = $this->prototype->normalize($v);
|
||||
} else {
|
||||
$normalized[] = $this->prototype->normalize($v);
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
<?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\Definition;
|
||||
|
||||
use Symfony\Component\Config\Definition\ArrayNode;
|
||||
|
||||
class ArrayNodeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidTypeException
|
||||
*/
|
||||
public function testNormalizeThrowsExceptionWhenFalseIsNotAllowed()
|
||||
{
|
||||
$node = new ArrayNode('root');
|
||||
$node->normalize(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* normalize() should protect against child values with no corresponding node
|
||||
*/
|
||||
public function testExceptionThrownOnUnrecognizedChild()
|
||||
{
|
||||
$node = new ArrayNode('root');
|
||||
|
||||
try {
|
||||
$node->normalize(array('foo' => 'bar'));
|
||||
$this->fail('An exception should have been throw for a bad child node');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException', $e);
|
||||
$this->assertEquals('Unrecognized options "foo" under "root"', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that no exception is thrown for an unrecognized child if the
|
||||
* ignoreExtraKeys option is set to true.
|
||||
*
|
||||
* Related to testExceptionThrownOnUnrecognizedChild
|
||||
*/
|
||||
public function testIgnoreExtraKeysNoException()
|
||||
{
|
||||
$node = new ArrayNode('roo');
|
||||
$node->setIgnoreExtraKeys(true);
|
||||
|
||||
$node->normalize(array('foo' => 'bar'));
|
||||
$this->assertTrue(true, 'No exception was thrown when setIgnoreExtraKeys is true');
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?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\Definition;
|
||||
|
||||
use Symfony\Component\Config\Definition\BooleanNode;
|
||||
|
||||
class BooleanNodeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getValidValues
|
||||
*/
|
||||
public function testNormalize($value)
|
||||
{
|
||||
$node = new BooleanNode('test');
|
||||
$this->assertSame($value, $node->normalize($value));
|
||||
}
|
||||
|
||||
public function getValidValues()
|
||||
{
|
||||
return array(
|
||||
array(false),
|
||||
array(true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidValues
|
||||
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidTypeException
|
||||
*/
|
||||
public function testNormalizeThrowsExceptionOnInvalidValues($value)
|
||||
{
|
||||
$node = new BooleanNode('test');
|
||||
$node->normalize($value);
|
||||
}
|
||||
|
||||
public function getInvalidValues()
|
||||
{
|
||||
return array(
|
||||
array(null),
|
||||
array(''),
|
||||
array('foo'),
|
||||
array(0),
|
||||
array(1),
|
||||
array(0.0),
|
||||
array(0.1),
|
||||
array(array()),
|
||||
array(array('foo' => 'bar')),
|
||||
array(new \stdClass()),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
<?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\Definition\Builder;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
|
||||
|
||||
class ArrayNodeDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAppendingSomeNode()
|
||||
{
|
||||
$parent = new ArrayNodeDefinition('root');
|
||||
$child = new ScalarNodeDefinition('child');
|
||||
|
||||
$parent
|
||||
->children()
|
||||
->scalarNode('foo')->end()
|
||||
->scalarNode('bar')->end()
|
||||
->end()
|
||||
->append($child);
|
||||
|
||||
$this->assertCount(3, $this->getField($parent, 'children'));
|
||||
$this->assertTrue(in_array($child, $this->getField($parent, 'children')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
|
||||
* @dataProvider providePrototypeNodeSpecificCalls
|
||||
*/
|
||||
public function testPrototypeNodeSpecificOption($method, $args)
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
|
||||
call_user_func_array(array($node, $method), $args);
|
||||
|
||||
$node->getNode();
|
||||
}
|
||||
|
||||
public function providePrototypeNodeSpecificCalls()
|
||||
{
|
||||
return array(
|
||||
array('defaultValue', array(array())),
|
||||
array('addDefaultChildrenIfNoneSet', array()),
|
||||
array('requiresAtLeastOneElement', array()),
|
||||
array('useAttributeAsKey', array('foo'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
|
||||
*/
|
||||
public function testConcreteNodeSpecificOption()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node->addDefaultsIfNotSet()->prototype('array');
|
||||
$node->getNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
|
||||
*/
|
||||
public function testPrototypeNodesCantHaveADefaultValueWhenUsingDefaultChildren()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->defaultValue(array())
|
||||
->addDefaultChildrenIfNoneSet('foo')
|
||||
->prototype('array')
|
||||
;
|
||||
$node->getNode();
|
||||
}
|
||||
|
||||
public function testPrototypedArrayNodeDefaultWhenUsingDefaultChildren()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->addDefaultChildrenIfNoneSet()
|
||||
->prototype('array')
|
||||
;
|
||||
$tree = $node->getNode();
|
||||
$this->assertEquals(array(array()), $tree->getDefaultValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providePrototypedArrayNodeDefaults
|
||||
*/
|
||||
public function testPrototypedArrayNodeDefault($args, $shouldThrowWhenUsingAttrAsKey, $shouldThrowWhenNotUsingAttrAsKey, $defaults)
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->addDefaultChildrenIfNoneSet($args)
|
||||
->prototype('array')
|
||||
;
|
||||
|
||||
try {
|
||||
$tree = $node->getNode();
|
||||
$this->assertFalse($shouldThrowWhenNotUsingAttrAsKey);
|
||||
$this->assertEquals($defaults, $tree->getDefaultValue());
|
||||
} catch (InvalidDefinitionException $e) {
|
||||
$this->assertTrue($shouldThrowWhenNotUsingAttrAsKey);
|
||||
}
|
||||
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->useAttributeAsKey('attr')
|
||||
->addDefaultChildrenIfNoneSet($args)
|
||||
->prototype('array')
|
||||
;
|
||||
|
||||
try {
|
||||
$tree = $node->getNode();
|
||||
$this->assertFalse($shouldThrowWhenUsingAttrAsKey);
|
||||
$this->assertEquals($defaults, $tree->getDefaultValue());
|
||||
} catch (InvalidDefinitionException $e) {
|
||||
$this->assertTrue($shouldThrowWhenUsingAttrAsKey);
|
||||
}
|
||||
}
|
||||
|
||||
public function providePrototypedArrayNodeDefaults()
|
||||
{
|
||||
return array(
|
||||
array(null, true, false, array(array())),
|
||||
array(2, true, false, array(array(), array())),
|
||||
array('2', false, true, array('2' => array())),
|
||||
array('foo', false, true, array('foo' => array())),
|
||||
array(array('foo'), false, true, array('foo' => array())),
|
||||
array(array('foo', 'bar'), false, true, array('foo' => array(), 'bar' => array())),
|
||||
);
|
||||
}
|
||||
|
||||
public function testNestedPrototypedArrayNodes()
|
||||
{
|
||||
$node = new ArrayNodeDefinition('root');
|
||||
$node
|
||||
->addDefaultChildrenIfNoneSet()
|
||||
->prototype('array')
|
||||
->prototype('array')
|
||||
;
|
||||
$node->getNode();
|
||||
}
|
||||
|
||||
protected function getField($object, $field)
|
||||
{
|
||||
$reflection = new \ReflectionProperty($object, $field);
|
||||
$reflection->setAccessible(true);
|
||||
|
||||
return $reflection->getValue($object);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Config\Tests\Definition\Builder;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\EnumNodeDefinition;
|
||||
|
||||
class EnumNodeDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage ->values() must be called with at least two distinct values.
|
||||
*/
|
||||
public function testNoDistinctValues()
|
||||
{
|
||||
$def = new EnumNodeDefinition('foo');
|
||||
$def->values(array('foo', 'foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage You must call ->values() on enum nodes.
|
||||
*/
|
||||
public function testNoValuesPassed()
|
||||
{
|
||||
$def = new EnumNodeDefinition('foo');
|
||||
$def->getNode();
|
||||
}
|
||||
|
||||
public function testGetNode()
|
||||
{
|
||||
$def = new EnumNodeDefinition('foo');
|
||||
$def->values(array('foo', 'bar'));
|
||||
|
||||
$node = $def->getNode();
|
||||
$this->assertEquals(array('foo', 'bar'), $node->getValues());
|
||||
}
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
<?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\Definition\Builder;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
|
||||
class ExprBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testAlwaysExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->always($this->returnClosure('new_value'))
|
||||
->end();
|
||||
|
||||
$this->assertFinalizedValueIs('new_value', $test);
|
||||
}
|
||||
|
||||
public function testIfTrueExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifTrue()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test, array('key'=>true));
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifTrue( function($v){ return true; })
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test);
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifTrue( function($v){ return false; })
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('value',$test);
|
||||
}
|
||||
|
||||
public function testIfStringExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifString()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test);
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifString()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs(45, $test, array('key'=>45));
|
||||
|
||||
}
|
||||
|
||||
public function testIfNullExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifNull()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test, array('key'=>null));
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifNull()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('value', $test);
|
||||
}
|
||||
|
||||
public function testIfArrayExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifArray()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test, array('key'=>array()));
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifArray()
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('value', $test);
|
||||
}
|
||||
|
||||
public function testIfInArrayExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifInArray(array('foo', 'bar', 'value'))
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test);
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifInArray(array('foo', 'bar'))
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('value', $test);
|
||||
}
|
||||
|
||||
public function testIfNotInArrayExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifNotInArray(array('foo', 'bar'))
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test);
|
||||
|
||||
$test = $this->getTestBuilder()
|
||||
->ifNotInArray(array('foo', 'bar', 'value_from_config' ))
|
||||
->then($this->returnClosure('new_value'))
|
||||
->end();
|
||||
$this->assertFinalizedValueIs('new_value', $test);
|
||||
}
|
||||
|
||||
public function testThenEmptyArrayExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifString()
|
||||
->thenEmptyArray()
|
||||
->end();
|
||||
$this->assertFinalizedValueIs(array(), $test);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
*/
|
||||
public function testThenInvalid()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifString()
|
||||
->thenInvalid('Invalid value')
|
||||
->end();
|
||||
$this->finalizeTestBuilder($test);
|
||||
}
|
||||
|
||||
public function testThenUnsetExpression()
|
||||
{
|
||||
$test = $this->getTestBuilder()
|
||||
->ifString()
|
||||
->thenUnset()
|
||||
->end();
|
||||
$this->assertEquals(array(), $this->finalizeTestBuilder($test));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a test treebuilder with a variable node, and init the validation
|
||||
* @return TreeBuilder
|
||||
*/
|
||||
protected function getTestBuilder()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
|
||||
return $builder
|
||||
->root('test')
|
||||
->children()
|
||||
->variableNode('key')
|
||||
->validate()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the validation process and finalize with the given config
|
||||
* @param TreeBuilder $testBuilder The tree builder to finalize
|
||||
* @param array $config The config you want to use for the finalization, if nothing provided
|
||||
* a simple array('key'=>'value') will be used
|
||||
* @return array The finalized config values
|
||||
*/
|
||||
protected function finalizeTestBuilder($testBuilder, $config=null)
|
||||
{
|
||||
return $testBuilder
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
->finalize($config === null ? array('key'=>'value') : $config)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a closure that will return the given value
|
||||
* @param $val The value that the closure must return
|
||||
* @return Closure
|
||||
*/
|
||||
protected function returnClosure($val)
|
||||
{
|
||||
return function($v) use ($val) {
|
||||
return $val;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given test builder, will return the given value
|
||||
* @param mixed $value The value to test
|
||||
* @param TreeBuilder $treeBuilder The tree builder to finalize
|
||||
* @param mixed $config The config values that new to be finalized
|
||||
*/
|
||||
protected function assertFinalizedValueIs($value, $treeBuilder, $config=null)
|
||||
{
|
||||
$this->assertEquals(array('key'=>$value), $this->finalizeTestBuilder($treeBuilder, $config));
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
<?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\Definition\Builder;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\NodeBuilder as BaseNodeBuilder;
|
||||
use Symfony\Component\Config\Definition\Builder\VariableNodeDefinition as BaseVariableNodeDefinition;
|
||||
|
||||
class NodeBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testThrowsAnExceptionWhenTryingToCreateANonRegisteredNodeType()
|
||||
{
|
||||
$builder = new BaseNodeBuilder();
|
||||
$builder->node('', 'foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testThrowsAnExceptionWhenTheNodeClassIsNotFound()
|
||||
{
|
||||
$builder = new BaseNodeBuilder();
|
||||
$builder
|
||||
->setNodeClass('noclasstype', '\\foo\\bar\\noclass')
|
||||
->node('', 'noclasstype');
|
||||
}
|
||||
|
||||
public function testAddingANewNodeType()
|
||||
{
|
||||
$class = __NAMESPACE__.'\\SomeNodeDefinition';
|
||||
|
||||
$builder = new BaseNodeBuilder();
|
||||
$node = $builder
|
||||
->setNodeClass('newtype', $class)
|
||||
->node('', 'newtype');
|
||||
|
||||
$this->assertEquals(get_class($node), $class);
|
||||
}
|
||||
|
||||
public function testOverridingAnExistingNodeType()
|
||||
{
|
||||
$class = __NAMESPACE__.'\\SomeNodeDefinition';
|
||||
|
||||
$builder = new BaseNodeBuilder();
|
||||
$node = $builder
|
||||
->setNodeClass('variable', $class)
|
||||
->node('', 'variable');
|
||||
|
||||
$this->assertEquals(get_class($node), $class);
|
||||
}
|
||||
|
||||
public function testNodeTypesAreNotCaseSensitive()
|
||||
{
|
||||
$builder = new BaseNodeBuilder();
|
||||
|
||||
$node1 = $builder->node('', 'VaRiAbLe');
|
||||
$node2 = $builder->node('', 'variable');
|
||||
|
||||
$this->assertEquals(get_class($node1), get_class($node2));
|
||||
|
||||
$builder->setNodeClass('CuStOm', __NAMESPACE__.'\\SomeNodeDefinition');
|
||||
|
||||
$node1 = $builder->node('', 'CUSTOM');
|
||||
$node2 = $builder->node('', 'custom');
|
||||
|
||||
$this->assertEquals(get_class($node1), get_class($node2));
|
||||
}
|
||||
}
|
||||
|
||||
class SomeNodeDefinition extends BaseVariableNodeDefinition
|
||||
{
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
<?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\Definition\Builder;
|
||||
|
||||
use Symfony\Component\Config\Tests\Definition\Builder\NodeBuilder as CustomNodeBuilder;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
|
||||
|
||||
require __DIR__.'/../../Fixtures/Builder/NodeBuilder.php';
|
||||
require __DIR__.'/../../Fixtures/Builder/BarNodeDefinition.php';
|
||||
require __DIR__.'/../../Fixtures/Builder/VariableNodeDefinition.php';
|
||||
|
||||
class TreeBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testUsingACustomNodeBuilder()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$root = $builder->root('custom', 'array', new CustomNodeBuilder());
|
||||
|
||||
$nodeBuilder = $root->children();
|
||||
|
||||
$this->assertEquals(get_class($nodeBuilder), 'Symfony\Component\Config\Tests\Definition\Builder\NodeBuilder');
|
||||
|
||||
$nodeBuilder = $nodeBuilder->arrayNode('deeper')->children();
|
||||
|
||||
$this->assertEquals(get_class($nodeBuilder), 'Symfony\Component\Config\Tests\Definition\Builder\NodeBuilder');
|
||||
}
|
||||
|
||||
public function testOverrideABuiltInNodeType()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$root = $builder->root('override', 'array', new CustomNodeBuilder());
|
||||
|
||||
$definition = $root->children()->variableNode('variable');
|
||||
|
||||
$this->assertEquals(get_class($definition), 'Symfony\Component\Config\Tests\Definition\Builder\VariableNodeDefinition');
|
||||
}
|
||||
|
||||
public function testAddANodeType()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$root = $builder->root('override', 'array', new CustomNodeBuilder());
|
||||
|
||||
$definition = $root->children()->barNode('variable');
|
||||
|
||||
$this->assertEquals(get_class($definition), 'Symfony\Component\Config\Tests\Definition\Builder\BarNodeDefinition');
|
||||
}
|
||||
|
||||
public function testCreateABuiltInNodeTypeWithACustomNodeBuilder()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$root = $builder->root('builtin', 'array', new CustomNodeBuilder());
|
||||
|
||||
$definition = $root->children()->booleanNode('boolean');
|
||||
|
||||
$this->assertEquals(get_class($definition), 'Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition');
|
||||
}
|
||||
|
||||
public function testPrototypedArrayNodeUseTheCustomNodeBuilder()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$root = $builder->root('override', 'array', new CustomNodeBuilder());
|
||||
|
||||
$root->prototype('bar')->end();
|
||||
}
|
||||
|
||||
public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
|
||||
$builder->root('propagation')
|
||||
->children()
|
||||
->setNodeClass('extended', 'Symfony\Component\Config\Tests\Definition\Builder\VariableNodeDefinition')
|
||||
->node('foo', 'extended')->end()
|
||||
->arrayNode('child')
|
||||
->children()
|
||||
->node('foo', 'extended')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end();
|
||||
}
|
||||
|
||||
public function testDefinitionInfoGetsTransferredToNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
|
||||
$builder->root('test')->info('root info')
|
||||
->children()
|
||||
->node('child', 'variable')->info('child info')->defaultValue('default')
|
||||
->end()
|
||||
->end();
|
||||
|
||||
$tree = $builder->buildTree();
|
||||
$children = $tree->getChildren();
|
||||
|
||||
$this->assertEquals('root info', $tree->getInfo());
|
||||
$this->assertEquals('child info', $children['child']->getInfo());
|
||||
}
|
||||
|
||||
public function testDefinitionExampleGetsTransferredToNode()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
|
||||
$builder->root('test')
|
||||
->example(array('key' => 'value'))
|
||||
->children()
|
||||
->node('child', 'variable')->info('child info')->defaultValue('default')->example('example')
|
||||
->end()
|
||||
->end();
|
||||
|
||||
$tree = $builder->buildTree();
|
||||
$children = $tree->getChildren();
|
||||
|
||||
$this->assertTrue(is_array($tree->getExample()));
|
||||
$this->assertEquals('example', $children['child']->getExample());
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?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\Definition;
|
||||
|
||||
use Symfony\Component\Config\Definition\EnumNode;
|
||||
|
||||
class EnumNodeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFinalizeValue()
|
||||
{
|
||||
$node = new EnumNode('foo', null, array('foo', 'bar'));
|
||||
$this->assertSame('foo', $node->finalize('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testConstructionWithOneValue()
|
||||
{
|
||||
new EnumNode('foo', null, array('foo', 'foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
* @expectedExceptionMessage The value "foobar" is not allowed for path "foo". Permissible values: "foo", "bar"
|
||||
*/
|
||||
public function testFinalizeWithInvalidValue()
|
||||
{
|
||||
$node = new EnumNode('foo', null, array('foo', 'bar'));
|
||||
$node->finalize('foobar');
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?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\Definition;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
use Symfony\Component\Config\Definition\NodeInterface;
|
||||
|
||||
class FinalizationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testUnsetKeyWithDeepHierarchy()
|
||||
{
|
||||
$tb = new TreeBuilder();
|
||||
$tree = $tb
|
||||
->root('config', 'array')
|
||||
->children()
|
||||
->node('level1', 'array')
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->node('level2', 'array')
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->node('somevalue', 'scalar')->end()
|
||||
->node('anothervalue', 'scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->node('level1_scalar', 'scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
;
|
||||
|
||||
$a = array(
|
||||
'level1' => array(
|
||||
'level2' => array(
|
||||
'somevalue' => 'foo',
|
||||
'anothervalue' => 'bar',
|
||||
),
|
||||
'level1_scalar' => 'foo',
|
||||
),
|
||||
);
|
||||
|
||||
$b = array(
|
||||
'level1' => array(
|
||||
'level2' => false,
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'level1' => array(
|
||||
'level1_scalar' => 'foo',
|
||||
),
|
||||
), $this->process($tree, array($a, $b)));
|
||||
}
|
||||
|
||||
protected function process(NodeInterface $tree, array $configs)
|
||||
{
|
||||
$processor = new Processor();
|
||||
|
||||
return $processor->process($tree, $configs);
|
||||
}
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
<?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\Definition;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
|
||||
class MergeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException Symfony\Component\Config\Definition\Exception\ForbiddenOverwriteException
|
||||
*/
|
||||
public function testForbiddenOverwrite()
|
||||
{
|
||||
$tb = new TreeBuilder();
|
||||
$tree = $tb
|
||||
->root('root', 'array')
|
||||
->children()
|
||||
->node('foo', 'scalar')
|
||||
->cannotBeOverwritten()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
;
|
||||
|
||||
$a = array(
|
||||
'foo' => 'bar',
|
||||
);
|
||||
|
||||
$b = array(
|
||||
'foo' => 'moo',
|
||||
);
|
||||
|
||||
$tree->merge($a, $b);
|
||||
}
|
||||
|
||||
public function testUnsetKey()
|
||||
{
|
||||
$tb = new TreeBuilder();
|
||||
$tree = $tb
|
||||
->root('root', 'array')
|
||||
->children()
|
||||
->node('foo', 'scalar')->end()
|
||||
->node('bar', 'scalar')->end()
|
||||
->node('unsettable', 'array')
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->node('foo', 'scalar')->end()
|
||||
->node('bar', 'scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->node('unsetted', 'array')
|
||||
->canBeUnset()
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
;
|
||||
|
||||
$a = array(
|
||||
'foo' => 'bar',
|
||||
'unsettable' => array(
|
||||
'foo' => 'a',
|
||||
'bar' => 'b',
|
||||
),
|
||||
'unsetted' => false,
|
||||
);
|
||||
|
||||
$b = array(
|
||||
'foo' => 'moo',
|
||||
'bar' => 'b',
|
||||
'unsettable' => false,
|
||||
'unsetted' => array('a', 'b'),
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'foo' => 'moo',
|
||||
'bar' => 'b',
|
||||
'unsettable' => false,
|
||||
'unsetted' => array('a', 'b'),
|
||||
), $tree->merge($a, $b));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
*/
|
||||
public function testDoesNotAllowNewKeysInSubsequentConfigs()
|
||||
{
|
||||
$tb = new TreeBuilder();
|
||||
$tree = $tb
|
||||
->root('config', 'array')
|
||||
->children()
|
||||
->node('test', 'array')
|
||||
->disallowNewKeysInSubsequentConfigs()
|
||||
->useAttributeAsKey('key')
|
||||
->prototype('array')
|
||||
->children()
|
||||
->node('value', 'scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree();
|
||||
|
||||
$a = array(
|
||||
'test' => array(
|
||||
'a' => array('value' => 'foo')
|
||||
)
|
||||
);
|
||||
|
||||
$b = array(
|
||||
'test' => array(
|
||||
'b' => array('value' => 'foo')
|
||||
)
|
||||
);
|
||||
|
||||
$tree->merge($a, $b);
|
||||
}
|
||||
|
||||
public function testPerformsNoDeepMerging()
|
||||
{
|
||||
$tb = new TreeBuilder();
|
||||
|
||||
$tree = $tb
|
||||
->root('config', 'array')
|
||||
->children()
|
||||
->node('no_deep_merging', 'array')
|
||||
->performNoDeepMerging()
|
||||
->children()
|
||||
->node('foo', 'scalar')->end()
|
||||
->node('bar', 'scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
;
|
||||
|
||||
$a = array(
|
||||
'no_deep_merging' => array(
|
||||
'foo' => 'a',
|
||||
'bar' => 'b',
|
||||
),
|
||||
);
|
||||
|
||||
$b = array(
|
||||
'no_deep_merging' => array(
|
||||
'c' => 'd',
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'no_deep_merging' => array(
|
||||
'c' => 'd',
|
||||
)
|
||||
), $tree->merge($a, $b));
|
||||
}
|
||||
|
||||
public function testPrototypeWithoutAKeyAttribute()
|
||||
{
|
||||
$tb = new TreeBuilder();
|
||||
|
||||
$tree = $tb
|
||||
->root('config', 'array')
|
||||
->children()
|
||||
->arrayNode('append_elements')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
;
|
||||
|
||||
$a = array(
|
||||
'append_elements' => array('a', 'b'),
|
||||
);
|
||||
|
||||
$b = array(
|
||||
'append_elements' => array('c', 'd'),
|
||||
);
|
||||
|
||||
$this->assertEquals(array('append_elements' => array('a', 'b', 'c', 'd')), $tree->merge($a, $b));
|
||||
}
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
<?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\Definition;
|
||||
|
||||
use Symfony\Component\Config\Definition\NodeInterface;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
|
||||
class NormalizerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getEncoderTests
|
||||
*/
|
||||
public function testNormalizeEncoders($denormalized)
|
||||
{
|
||||
$tb = new TreeBuilder();
|
||||
$tree = $tb
|
||||
->root('root_name', 'array')
|
||||
->fixXmlConfig('encoder')
|
||||
->children()
|
||||
->node('encoders', 'array')
|
||||
->useAttributeAsKey('class')
|
||||
->prototype('array')
|
||||
->beforeNormalization()->ifString()->then(function($v) { return array('algorithm' => $v); })->end()
|
||||
->children()
|
||||
->node('algorithm', 'scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
;
|
||||
|
||||
$normalized = array(
|
||||
'encoders' => array(
|
||||
'foo' => array('algorithm' => 'plaintext'),
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertNormalized($tree, $denormalized, $normalized);
|
||||
}
|
||||
|
||||
public function getEncoderTests()
|
||||
{
|
||||
$configs = array();
|
||||
|
||||
// XML
|
||||
$configs[] = array(
|
||||
'encoder' => array(
|
||||
array('class' => 'foo', 'algorithm' => 'plaintext'),
|
||||
),
|
||||
);
|
||||
|
||||
// XML when only one element of this type
|
||||
$configs[] = array(
|
||||
'encoder' => array('class' => 'foo', 'algorithm' => 'plaintext'),
|
||||
);
|
||||
|
||||
// YAML/PHP
|
||||
$configs[] = array(
|
||||
'encoders' => array(
|
||||
array('class' => 'foo', 'algorithm' => 'plaintext'),
|
||||
),
|
||||
);
|
||||
|
||||
// YAML/PHP
|
||||
$configs[] = array(
|
||||
'encoders' => array(
|
||||
'foo' => 'plaintext',
|
||||
),
|
||||
);
|
||||
|
||||
// YAML/PHP
|
||||
$configs[] = array(
|
||||
'encoders' => array(
|
||||
'foo' => array('algorithm' => 'plaintext'),
|
||||
),
|
||||
);
|
||||
|
||||
return array_map(function($v) {
|
||||
return array($v);
|
||||
}, $configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAnonymousKeysTests
|
||||
*/
|
||||
public function testAnonymousKeysArray($denormalized)
|
||||
{
|
||||
$tb = new TreeBuilder();
|
||||
$tree = $tb
|
||||
->root('root', 'array')
|
||||
->children()
|
||||
->node('logout', 'array')
|
||||
->fixXmlConfig('handler')
|
||||
->children()
|
||||
->node('handlers', 'array')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
;
|
||||
|
||||
$normalized = array('logout' => array('handlers' => array('a', 'b', 'c')));
|
||||
|
||||
$this->assertNormalized($tree, $denormalized, $normalized);
|
||||
}
|
||||
|
||||
public function getAnonymousKeysTests()
|
||||
{
|
||||
$configs = array();
|
||||
|
||||
$configs[] = array(
|
||||
'logout' => array(
|
||||
'handlers' => array('a', 'b', 'c'),
|
||||
),
|
||||
);
|
||||
|
||||
$configs[] = array(
|
||||
'logout' => array(
|
||||
'handler' => array('a', 'b', 'c'),
|
||||
),
|
||||
);
|
||||
|
||||
return array_map(function($v) { return array($v); }, $configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getNumericKeysTests
|
||||
*/
|
||||
public function testNumericKeysAsAttributes($denormalized)
|
||||
{
|
||||
$normalized = array(
|
||||
'thing' => array(42 => array('foo', 'bar'), 1337 => array('baz', 'qux')),
|
||||
);
|
||||
|
||||
$this->assertNormalized($this->getNumericKeysTestTree(), $denormalized, $normalized);
|
||||
}
|
||||
|
||||
public function getNumericKeysTests()
|
||||
{
|
||||
$configs = array();
|
||||
|
||||
$configs[] = array(
|
||||
'thing' => array(
|
||||
42 => array('foo', 'bar'), 1337 => array('baz', 'qux'),
|
||||
),
|
||||
);
|
||||
|
||||
$configs[] = array(
|
||||
'thing' => array(
|
||||
array('foo', 'bar', 'id' => 42), array('baz', 'qux', 'id' => 1337),
|
||||
),
|
||||
);
|
||||
|
||||
return array_map(function($v) { return array($v); }, $configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
* @expectedExceptionMessage The attribute "id" must be set for path "root.thing".
|
||||
*/
|
||||
public function testNonAssociativeArrayThrowsExceptionIfAttributeNotSet()
|
||||
{
|
||||
$denormalized = array(
|
||||
'thing' => array(
|
||||
array('foo', 'bar'), array('baz', 'qux')
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertNormalized($this->getNumericKeysTestTree(), $denormalized, array());
|
||||
}
|
||||
|
||||
public static function assertNormalized(NodeInterface $tree, $denormalized, $normalized)
|
||||
{
|
||||
self::assertSame($normalized, $tree->normalize($denormalized));
|
||||
}
|
||||
|
||||
private function getNumericKeysTestTree()
|
||||
{
|
||||
$tb = new TreeBuilder();
|
||||
$tree = $tb
|
||||
->root('root', 'array')
|
||||
->children()
|
||||
->node('thing', 'array')
|
||||
->useAttributeAsKey('id')
|
||||
->prototype('array')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->buildTree()
|
||||
;
|
||||
|
||||
return $tree;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?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\Definition;
|
||||
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
|
||||
class ProcessorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getKeyNormalizationTests
|
||||
*/
|
||||
public function testNormalizeKeys($denormalized, $normalized)
|
||||
{
|
||||
$this->assertSame($normalized, Processor::normalizeKeys($denormalized));
|
||||
}
|
||||
|
||||
public function getKeyNormalizationTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('foo-bar' => 'foo'),
|
||||
array('foo_bar' => 'foo'),
|
||||
),
|
||||
array(
|
||||
array('foo-bar_moo' => 'foo'),
|
||||
array('foo-bar_moo' => 'foo'),
|
||||
),
|
||||
array(
|
||||
array('foo-bar' => null, 'foo_bar' => 'foo'),
|
||||
array('foo-bar' => null, 'foo_bar' => 'foo'),
|
||||
),
|
||||
array(
|
||||
array('foo-bar' => array('foo-bar' => 'foo')),
|
||||
array('foo_bar' => array('foo_bar' => 'foo')),
|
||||
),
|
||||
array(
|
||||
array('foo_bar' => array('foo-bar' => 'foo')),
|
||||
array('foo_bar' => array('foo_bar' => 'foo')),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
<?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\Definition;
|
||||
|
||||
use Symfony\Component\Config\Definition\PrototypedArrayNode;
|
||||
use Symfony\Component\Config\Definition\ArrayNode;
|
||||
use Symfony\Component\Config\Definition\ScalarNode;
|
||||
|
||||
class PrototypedArrayNodeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testGetDefaultValueReturnsAnEmptyArrayForPrototypes()
|
||||
{
|
||||
$node = new PrototypedArrayNode('root');
|
||||
$prototype = new ArrayNode(null, $node);
|
||||
$node->setPrototype($prototype);
|
||||
$this->assertEmpty($node->getDefaultValue());
|
||||
}
|
||||
|
||||
public function testGetDefaultValueReturnsDefaultValueForPrototypes()
|
||||
{
|
||||
$node = new PrototypedArrayNode('root');
|
||||
$prototype = new ArrayNode(null, $node);
|
||||
$node->setPrototype($prototype);
|
||||
$node->setDefaultValue(array ('test'));
|
||||
$this->assertEquals(array ('test'), $node->getDefaultValue());
|
||||
}
|
||||
|
||||
// a remapped key (e.g. "mapping" -> "mappings") should be unset after being used
|
||||
public function testRemappedKeysAreUnset()
|
||||
{
|
||||
$node = new ArrayNode('root');
|
||||
$mappingsNode = new PrototypedArrayNode('mappings');
|
||||
$node->addChild($mappingsNode);
|
||||
|
||||
// each item under mappings is just a scalar
|
||||
$prototype = new ScalarNode(null, $mappingsNode);
|
||||
$mappingsNode->setPrototype($prototype);
|
||||
|
||||
$remappings = array();
|
||||
$remappings[] = array('mapping', 'mappings');
|
||||
$node->setXmlRemappings($remappings);
|
||||
|
||||
$normalized = $node->normalize(array('mapping' => array('foo', 'bar')));
|
||||
$this->assertEquals(array('mappings' => array('foo', 'bar')), $normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that when a key attribute is mapped, that key is removed from the array:
|
||||
*
|
||||
* <things>
|
||||
* <option id="option1" value="foo">
|
||||
* <option id="option2" value="bar">
|
||||
* </things>
|
||||
*
|
||||
* The above should finally be mapped to an array that looks like this
|
||||
* (because "id" is the key attribute).
|
||||
*
|
||||
* array(
|
||||
* 'things' => array(
|
||||
* 'option1' => 'foo',
|
||||
* 'option2' => 'bar',
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function testMappedAttributeKeyIsRemoved()
|
||||
{
|
||||
$node = new PrototypedArrayNode('root');
|
||||
$node->setKeyAttribute('id', true);
|
||||
|
||||
// each item under the root is an array, with one scalar item
|
||||
$prototype = new ArrayNode(null, $node);
|
||||
$prototype->addChild(new ScalarNode('foo'));
|
||||
$node->setPrototype($prototype);
|
||||
|
||||
$children = array();
|
||||
$children[] = array('id' => 'item_name', 'foo' => 'bar');
|
||||
$normalized = $node->normalize($children);
|
||||
|
||||
$expected = array();
|
||||
$expected['item_name'] = array('foo' => 'bar');
|
||||
$this->assertEquals($expected, $normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the opposite of the testMappedAttributeKeyIsRemoved because
|
||||
* the removal can be toggled with an option.
|
||||
*/
|
||||
public function testMappedAttributeKeyNotRemoved()
|
||||
{
|
||||
$node = new PrototypedArrayNode('root');
|
||||
$node->setKeyAttribute('id', false);
|
||||
|
||||
// each item under the root is an array, with two scalar items
|
||||
$prototype = new ArrayNode(null, $node);
|
||||
$prototype->addChild(new ScalarNode('foo'));
|
||||
$prototype->addChild(new ScalarNode('id')); // the key attribute will remain
|
||||
$node->setPrototype($prototype);
|
||||
|
||||
$children = array();
|
||||
$children[] = array('id' => 'item_name', 'foo' => 'bar');
|
||||
$normalized = $node->normalize($children);
|
||||
|
||||
$expected = array();
|
||||
$expected['item_name'] = array('id' => 'item_name', 'foo' => 'bar');
|
||||
$this->assertEquals($expected, $normalized);
|
||||
}
|
||||
|
||||
public function testAddDefaultChildren()
|
||||
{
|
||||
$node = $this->getPrototypeNodeWithDefaultChildren();
|
||||
$node->setAddChildrenIfNoneSet();
|
||||
$this->assertTrue($node->hasDefaultValue());
|
||||
$this->assertEquals(array(array('foo' => 'bar')), $node->getDefaultValue());
|
||||
|
||||
$node = $this->getPrototypeNodeWithDefaultChildren();
|
||||
$node->setKeyAttribute('foobar');
|
||||
$node->setAddChildrenIfNoneSet();
|
||||
$this->assertTrue($node->hasDefaultValue());
|
||||
$this->assertEquals(array('defaults' => array('foo' => 'bar')), $node->getDefaultValue());
|
||||
|
||||
$node = $this->getPrototypeNodeWithDefaultChildren();
|
||||
$node->setKeyAttribute('foobar');
|
||||
$node->setAddChildrenIfNoneSet('defaultkey');
|
||||
$this->assertTrue($node->hasDefaultValue());
|
||||
$this->assertEquals(array('defaultkey' => array('foo' => 'bar')), $node->getDefaultValue());
|
||||
|
||||
$node = $this->getPrototypeNodeWithDefaultChildren();
|
||||
$node->setKeyAttribute('foobar');
|
||||
$node->setAddChildrenIfNoneSet(array('defaultkey'));
|
||||
$this->assertTrue($node->hasDefaultValue());
|
||||
$this->assertEquals(array('defaultkey' => array('foo' => 'bar')), $node->getDefaultValue());
|
||||
|
||||
$node = $this->getPrototypeNodeWithDefaultChildren();
|
||||
$node->setKeyAttribute('foobar');
|
||||
$node->setAddChildrenIfNoneSet(array('dk1', 'dk2'));
|
||||
$this->assertTrue($node->hasDefaultValue());
|
||||
$this->assertEquals(array('dk1' => array('foo' => 'bar'), 'dk2' => array('foo' => 'bar')), $node->getDefaultValue());
|
||||
|
||||
$node = $this->getPrototypeNodeWithDefaultChildren();
|
||||
$node->setAddChildrenIfNoneSet(array(5, 6));
|
||||
$this->assertTrue($node->hasDefaultValue());
|
||||
$this->assertEquals(array(0 => array('foo' => 'bar'), 1 => array('foo' => 'bar')), $node->getDefaultValue());
|
||||
|
||||
$node = $this->getPrototypeNodeWithDefaultChildren();
|
||||
$node->setAddChildrenIfNoneSet(2);
|
||||
$this->assertTrue($node->hasDefaultValue());
|
||||
$this->assertEquals(array(array('foo' => 'bar'), array('foo' => 'bar')), $node->getDefaultValue());
|
||||
}
|
||||
|
||||
public function testDefaultChildrenWinsOverDefaultValue()
|
||||
{
|
||||
$node = $this->getPrototypeNodeWithDefaultChildren();
|
||||
$node->setAddChildrenIfNoneSet();
|
||||
$node->setDefaultValue(array('bar' => 'foo'));
|
||||
$this->assertTrue($node->hasDefaultValue());
|
||||
$this->assertEquals(array(array('foo' => 'bar')), $node->getDefaultValue());
|
||||
}
|
||||
|
||||
protected function getPrototypeNodeWithDefaultChildren()
|
||||
{
|
||||
$node = new PrototypedArrayNode('root');
|
||||
$prototype = new ArrayNode(null, $node);
|
||||
$child = new ScalarNode('foo');
|
||||
$child->setDefaultValue('bar');
|
||||
$prototype->addChild($child);
|
||||
$prototype->setAddIfNotSet(true);
|
||||
$node->setPrototype($prototype);
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?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\Definition;
|
||||
|
||||
use Symfony\Component\Config\Definition\ScalarNode;
|
||||
|
||||
class ScalarNodeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getValidValues
|
||||
*/
|
||||
public function testNormalize($value)
|
||||
{
|
||||
$node = new ScalarNode('test');
|
||||
$this->assertSame($value, $node->normalize($value));
|
||||
}
|
||||
|
||||
public function getValidValues()
|
||||
{
|
||||
return array(
|
||||
array(false),
|
||||
array(true),
|
||||
array(null),
|
||||
array(''),
|
||||
array('foo'),
|
||||
array(0),
|
||||
array(1),
|
||||
array(0.0),
|
||||
array(0.1),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidValues
|
||||
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidTypeException
|
||||
*/
|
||||
public function testNormalizeThrowsExceptionOnInvalidValues($value)
|
||||
{
|
||||
$node = new ScalarNode('test');
|
||||
$node->normalize($value);
|
||||
}
|
||||
|
||||
public function getInvalidValues()
|
||||
{
|
||||
return array(
|
||||
array(array()),
|
||||
array(array('foo' => 'bar')),
|
||||
array(new \stdClass()),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
<?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;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
class FileLocatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getIsAbsolutePathTests
|
||||
*/
|
||||
public function testIsAbsolutePath($path)
|
||||
{
|
||||
$loader = new FileLocator(array());
|
||||
$r = new \ReflectionObject($loader);
|
||||
$m = $r->getMethod('isAbsolutePath');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$this->assertTrue($m->invoke($loader, $path), '->isAbsolutePath() returns true for an absolute path');
|
||||
}
|
||||
|
||||
public function getIsAbsolutePathTests()
|
||||
{
|
||||
return array(
|
||||
array('/foo.xml'),
|
||||
array('c:\\\\foo.xml'),
|
||||
array('c:/foo.xml'),
|
||||
array('\\server\\foo.xml'),
|
||||
array('https://server/foo.xml'),
|
||||
array('phar://server/foo.xml'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testLocate()
|
||||
{
|
||||
$loader = new FileLocator(__DIR__.'/Fixtures');
|
||||
|
||||
$this->assertEquals(
|
||||
__DIR__.DIRECTORY_SEPARATOR.'FileLocatorTest.php',
|
||||
$loader->locate('FileLocatorTest.php', __DIR__),
|
||||
'->locate() returns the absolute filename if the file exists in the given path'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml',
|
||||
$loader->locate('foo.xml', __DIR__),
|
||||
'->locate() returns the absolute filename if the file exists in one of the paths given in the constructor'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml',
|
||||
$loader->locate(__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', __DIR__),
|
||||
'->locate() returns the absolute filename if the file exists in one of the paths given in the constructor'
|
||||
);
|
||||
|
||||
$loader = new FileLocator(array(__DIR__.'/Fixtures', __DIR__.'/Fixtures/Again'));
|
||||
|
||||
$this->assertEquals(
|
||||
array(__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', __DIR__.'/Fixtures/Again'.DIRECTORY_SEPARATOR.'foo.xml'),
|
||||
$loader->locate('foo.xml', __DIR__, false),
|
||||
'->locate() returns an array of absolute filenames'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', __DIR__.'/Fixtures/Again'.DIRECTORY_SEPARATOR.'foo.xml'),
|
||||
$loader->locate('foo.xml', __DIR__.'/Fixtures', false),
|
||||
'->locate() returns an array of absolute filenames'
|
||||
);
|
||||
|
||||
$loader = new FileLocator(__DIR__.'/Fixtures/Again');
|
||||
|
||||
$this->assertEquals(
|
||||
array(__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', __DIR__.'/Fixtures/Again'.DIRECTORY_SEPARATOR.'foo.xml'),
|
||||
$loader->locate('foo.xml', __DIR__.'/Fixtures', false),
|
||||
'->locate() returns an array of absolute filenames'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testLocateThrowsAnExceptionIfTheFileDoesNotExists()
|
||||
{
|
||||
$loader = new FileLocator(array(__DIR__.'/Fixtures'));
|
||||
|
||||
$loader->locate('foobar.xml', __DIR__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testLocateThrowsAnExceptionIfTheFileDoesNotExistsInAbsolutePath()
|
||||
{
|
||||
$loader = new FileLocator(array(__DIR__.'/Fixtures'));
|
||||
|
||||
$loader->locate(__DIR__.'/Fixtures/foobar.xml', __DIR__);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?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\Definition\Builder;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
||||
|
||||
class BarNodeDefinition extends NodeDefinition
|
||||
{
|
||||
protected function createNode()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?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\Definition\Builder;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\NodeBuilder as BaseNodeBuilder;
|
||||
|
||||
class NodeBuilder extends BaseNodeBuilder
|
||||
{
|
||||
public function barNode($name)
|
||||
{
|
||||
return $this->node($name, 'bar');
|
||||
}
|
||||
|
||||
protected function getNodeClass($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'variable':
|
||||
return __NAMESPACE__.'\\'.ucfirst($type).'NodeDefinition';
|
||||
case 'bar':
|
||||
return __NAMESPACE__.'\\'.ucfirst($type).'NodeDefinition';
|
||||
default:
|
||||
return parent::getNodeClass($type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?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\Definition\Builder;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\VariableNodeDefinition as BaseVariableNodeDefinition;
|
||||
|
||||
class VariableNodeDefinition extends BaseVariableNodeDefinition
|
||||
{
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user