From c51c1b304721aabcf98d32c689fc93cb8aef0b77 Mon Sep 17 00:00:00 2001 From: John Whitley Date: Tue, 16 Aug 2016 09:16:37 +0100 Subject: [PATCH] Squashed commit of the following: commit 3994b556dcffcde7b1801c8bc712f3127e8f8e7c Author: John Whitley Date: Tue Aug 16 09:02:53 2016 +0100 https://github.com/composer/composer/issues/5600 This alters the default flag for loadOptions in \Composer\Package\Loader\ArrayLoader to true; and alters the assumption of the test to reflect this change. **Rationale** The `\Composer\Package\Loader\ArrayLoader` test (defined in tests/Composer/Test/Package/Loader/ArrayLoaderTest.php) assumed that a new `\Composer\Package\Loader\ArrayLoader` instance would be always created with the optional flag loadOptions set to true. ```php $this->loader = new \Composer\Package\Loader\ArrayLoader(null, true); ``` This change alters the general case to reflect the default assumption as defined in the test. commit b75fc4ad7238bc50f724bd29446ccbc33e82c34c Author: John Whitley Date: Mon Aug 15 16:55:27 2016 +0100 Altered the test for ArrayLoader to use the default loadConfig flag, and to test the true and false states for the loadConfig flag --- src/Composer/Package/Loader/ArrayLoader.php | 2 +- .../Test/Package/Loader/ArrayLoaderTest.php | 54 +++++++++++++++++-- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 10ad4376a..e86df0a45 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -29,7 +29,7 @@ class ArrayLoader implements LoaderInterface protected $versionParser; protected $loadOptions; - public function __construct(SemverVersionParser $parser = null, $loadOptions = false) + public function __construct(SemverVersionParser $parser = null, $loadOptions = true) { if (!$parser) { $parser = new VersionParser; diff --git a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php index 10963b55b..25bf7b28c 100644 --- a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php @@ -24,7 +24,7 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->loader = new ArrayLoader(null, true); + $this->loader = new ArrayLoader(null); } public function testSelfVersion() @@ -82,9 +82,9 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals('1.2.3.4', $package->getVersion()); } - public function testParseDump() + public function testParseDumpProvider() { - $config = array( + $validConfig = array( 'name' => 'A/B', 'version' => '1.2.3', 'version_normalized' => '1.2.3.0', @@ -126,9 +126,55 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase 'abandoned' => 'foo/bar', ); + $validTestArguments = array($validConfig); + $argumentsToProvide = array($validTestArguments); + + return $argumentsToProvide; + } + + protected function fixConfigWhenLoadConfigIsFalse($config) + { + $expectedConfig = $config; + unset($expectedConfig['transport-options']); + return $expectedConfig; + } + + /** + * The default parser should default to loading the config as this + * allows require-dev libraries to have transport options included. + * + * @dataProvider testParseDumpProvider + */ + public function testParseDumpDefaultLoadConfig($config) + { $package = $this->loader->load($config); $dumper = new ArrayDumper; - $this->assertEquals($config, $dumper->dump($package)); + $expectedConfig = $config; + $this->assertEquals($expectedConfig, $dumper->dump($package)); + } + + /** + * @dataProvider testParseDumpProvider + */ + public function testParseDumpTrueLoadConfig($config) + { + $loader = new ArrayLoader(null, true); + $package = $loader->load($config); + $dumper = new ArrayDumper; + $expectedConfig = $config; + $this->assertEquals($expectedConfig, $dumper->dump($package)); + } + + /** + * @dataProvider testParseDumpProvider + */ + public function testParseDumpFalseLoadConfig($config) + { + $loader = new ArrayLoader(null, false); + $package = $loader->load($config); + $dumper = new ArrayDumper; + $expectedConfig = $this->fixConfigWhenLoadConfigIsFalse($config); + $this->assertEquals($expectedConfig, $dumper->dump($package)); } public function testPackageWithBranchAlias()