X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fsymfony%2Fdependency-injection%2FTests%2FLoader%2FIniFileLoaderTest.php;h=736f75a112c87de1bd3836aad37a1d1796c01b1b;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=70fbf306070c653756da680923cc65c46065a40c;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/symfony/dependency-injection/Tests/Loader/IniFileLoaderTest.php b/vendor/symfony/dependency-injection/Tests/Loader/IniFileLoaderTest.php index 70fbf3060..736f75a11 100644 --- a/vendor/symfony/dependency-injection/Tests/Loader/IniFileLoaderTest.php +++ b/vendor/symfony/dependency-injection/Tests/Loader/IniFileLoaderTest.php @@ -18,20 +18,13 @@ use Symfony\Component\Config\FileLocator; class IniFileLoaderTest extends TestCase { - protected static $fixturesPath; - protected $container; protected $loader; - public static function setUpBeforeClass() - { - self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); - } - protected function setUp() { $this->container = new ContainerBuilder(); - $this->loader = new IniFileLoader($this->container, new FileLocator(self::$fixturesPath.'/ini')); + $this->loader = new IniFileLoader($this->container, new FileLocator(realpath(__DIR__.'/../Fixtures/').'/ini')); } public function testIniFileCanBeLoaded() @@ -40,6 +33,68 @@ class IniFileLoaderTest extends TestCase $this->assertEquals(array('foo' => 'bar', 'bar' => '%foo%'), $this->container->getParameterBag()->all(), '->load() takes a single file name as its first argument'); } + /** + * @dataProvider getTypeConversions + */ + public function testTypeConversions($key, $value, $supported) + { + $this->loader->load('types.ini'); + $parameters = $this->container->getParameterBag()->all(); + $this->assertSame($value, $parameters[$key], '->load() converts values to PHP types'); + } + + /** + * @dataProvider getTypeConversions + * @requires PHP 5.6.1 + * This test illustrates where our conversions differs from INI_SCANNER_TYPED introduced in PHP 5.6.1 + */ + public function testTypeConversionsWithNativePhp($key, $value, $supported) + { + if (defined('HHVM_VERSION_ID')) { + return $this->markTestSkipped(); + } + + if (!$supported) { + $this->markTestSkipped(sprintf('Converting the value "%s" to "%s" is not supported by the IniFileLoader.', $key, $value)); + } + + $this->loader->load('types.ini'); + $expected = parse_ini_file(__DIR__.'/../Fixtures/ini/types.ini', true, INI_SCANNER_TYPED); + $this->assertSame($value, $expected['parameters'][$key], '->load() converts values to PHP types'); + } + + public function getTypeConversions() + { + return array( + array('true_comment', true, true), + array('true', true, true), + array('false', false, true), + array('on', true, true), + array('off', false, true), + array('yes', true, true), + array('no', false, true), + array('none', false, true), + array('null', null, true), + array('constant', PHP_VERSION, true), + array('12', 12, true), + array('12_string', '12', true), + array('12_comment', 12, true), + array('12_string_comment', '12', true), + array('12_string_comment_again', '12', true), + array('-12', -12, true), + array('1', 1, true), + array('0', 0, true), + array('0b0110', bindec('0b0110'), false), // not supported by INI_SCANNER_TYPED + array('11112222333344445555', '1111,2222,3333,4444,5555', true), + array('0777', 0777, false), // not supported by INI_SCANNER_TYPED + array('255', 0xFF, false), // not supported by INI_SCANNER_TYPED + array('100.0', 1e2, false), // not supported by INI_SCANNER_TYPED + array('-120.0', -1.2E2, false), // not supported by INI_SCANNER_TYPED + array('-10100.1', -10100.1, false), // not supported by INI_SCANNER_TYPED + array('-10,100.1', '-10,100.1', true), + ); + } + /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The file "foo.ini" does not exist (in: @@ -50,7 +105,7 @@ class IniFileLoaderTest extends TestCase } /** - * @expectedException \InvalidArgumentException + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException * @expectedExceptionMessage The "nonvalid.ini" file is not valid. */ public function testExceptionIsRaisedWhenIniFileCannotBeParsed() @@ -58,6 +113,15 @@ class IniFileLoaderTest extends TestCase @$this->loader->load('nonvalid.ini'); } + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessage The "almostvalid.ini" file is not valid. + */ + public function testExceptionIsRaisedWhenIniFileIsAlmostValid() + { + @$this->loader->load('almostvalid.ini'); + } + public function testSupports() { $loader = new IniFileLoader(new ContainerBuilder(), new FileLocator());