Переглянути джерело

Added addLink and removeLink to Configuration Source Interface

 * Added addLink() and removeLink() to `ConfigSourceInterface`
 * Added addLink() and removeLink() implementations to `JsonConfigSource`
 * Added tests (+ a ton of fixtures) for `JsonConfigSource`
 * Added additional docblocks
 * Minor PSR-1/PSR-2 fixes here and there
Beau Simensen 12 роки тому
батько
коміт
752fa64704
48 змінених файлів з 1069 додано та 1 видалено
  1. 42 0
      src/Composer/Config/ConfigSourceInterface.php
  2. 41 1
      src/Composer/Config/JsonConfigSource.php
  3. 7 0
      tests/Composer/Test/Config/Fixtures/addLink/conflict-from-empty.json
  4. 23 0
      tests/Composer/Test/Config/Fixtures/addLink/conflict-from-oneOfEverything.json
  5. 29 0
      tests/Composer/Test/Config/Fixtures/addLink/conflict-from-twoOfEverything.json
  6. 7 0
      tests/Composer/Test/Config/Fixtures/addLink/provide-from-empty.json
  7. 23 0
      tests/Composer/Test/Config/Fixtures/addLink/provide-from-oneOfEverything.json
  8. 29 0
      tests/Composer/Test/Config/Fixtures/addLink/provide-from-twoOfEverything.json
  9. 7 0
      tests/Composer/Test/Config/Fixtures/addLink/replace-from-empty.json
  10. 23 0
      tests/Composer/Test/Config/Fixtures/addLink/replace-from-oneOfEverything.json
  11. 29 0
      tests/Composer/Test/Config/Fixtures/addLink/replace-from-twoOfEverything.json
  12. 7 0
      tests/Composer/Test/Config/Fixtures/addLink/require-dev-from-empty.json
  13. 23 0
      tests/Composer/Test/Config/Fixtures/addLink/require-dev-from-oneOfEverything.json
  14. 29 0
      tests/Composer/Test/Config/Fixtures/addLink/require-dev-from-twoOfEverything.json
  15. 7 0
      tests/Composer/Test/Config/Fixtures/addLink/require-from-empty.json
  16. 23 0
      tests/Composer/Test/Config/Fixtures/addLink/require-from-oneOfEverything.json
  17. 29 0
      tests/Composer/Test/Config/Fixtures/addLink/require-from-twoOfEverything.json
  18. 7 0
      tests/Composer/Test/Config/Fixtures/addLink/suggest-from-empty.json
  19. 23 0
      tests/Composer/Test/Config/Fixtures/addLink/suggest-from-oneOfEverything.json
  20. 29 0
      tests/Composer/Test/Config/Fixtures/addLink/suggest-from-twoOfEverything.json
  21. 4 0
      tests/Composer/Test/Config/Fixtures/composer-empty.json
  22. 22 0
      tests/Composer/Test/Config/Fixtures/composer-one-of-everything.json
  23. 28 0
      tests/Composer/Test/Config/Fixtures/composer-two-of-everything.json
  24. 6 0
      tests/Composer/Test/Config/Fixtures/removeLink/conflict-to-empty-after.json
  25. 7 0
      tests/Composer/Test/Config/Fixtures/removeLink/conflict-to-empty.json
  26. 23 0
      tests/Composer/Test/Config/Fixtures/removeLink/conflict-to-oneOfEverything.json
  27. 29 0
      tests/Composer/Test/Config/Fixtures/removeLink/conflict-to-twoOfEverything.json
  28. 6 0
      tests/Composer/Test/Config/Fixtures/removeLink/provide-to-empty-after.json
  29. 7 0
      tests/Composer/Test/Config/Fixtures/removeLink/provide-to-empty.json
  30. 23 0
      tests/Composer/Test/Config/Fixtures/removeLink/provide-to-oneOfEverything.json
  31. 29 0
      tests/Composer/Test/Config/Fixtures/removeLink/provide-to-twoOfEverything.json
  32. 6 0
      tests/Composer/Test/Config/Fixtures/removeLink/replace-to-empty-after.json
  33. 7 0
      tests/Composer/Test/Config/Fixtures/removeLink/replace-to-empty.json
  34. 23 0
      tests/Composer/Test/Config/Fixtures/removeLink/replace-to-oneOfEverything.json
  35. 29 0
      tests/Composer/Test/Config/Fixtures/removeLink/replace-to-twoOfEverything.json
  36. 6 0
      tests/Composer/Test/Config/Fixtures/removeLink/require-dev-to-empty-after.json
  37. 7 0
      tests/Composer/Test/Config/Fixtures/removeLink/require-dev-to-empty.json
  38. 23 0
      tests/Composer/Test/Config/Fixtures/removeLink/require-dev-to-oneOfEverything.json
  39. 29 0
      tests/Composer/Test/Config/Fixtures/removeLink/require-dev-to-twoOfEverything.json
  40. 6 0
      tests/Composer/Test/Config/Fixtures/removeLink/require-to-empty-after.json
  41. 7 0
      tests/Composer/Test/Config/Fixtures/removeLink/require-to-empty.json
  42. 23 0
      tests/Composer/Test/Config/Fixtures/removeLink/require-to-oneOfEverything.json
  43. 29 0
      tests/Composer/Test/Config/Fixtures/removeLink/require-to-twoOfEverything.json
  44. 6 0
      tests/Composer/Test/Config/Fixtures/removeLink/suggest-to-empty-after.json
  45. 7 0
      tests/Composer/Test/Config/Fixtures/removeLink/suggest-to-empty.json
  46. 23 0
      tests/Composer/Test/Config/Fixtures/removeLink/suggest-to-oneOfEverything.json
  47. 29 0
      tests/Composer/Test/Config/Fixtures/removeLink/suggest-to-twoOfEverything.json
  48. 188 0
      tests/Composer/Test/Config/JsonConfigSourceTest.php

+ 42 - 0
src/Composer/Config/ConfigSourceInterface.php

@@ -13,15 +13,57 @@
 namespace Composer\Config;
 
 /**
+ * Configuration Source Interface
+ *
  * @author Jordi Boggiano <j.boggiano@seld.be>
+ * @author Beau Simensen <beau@dflydev.com>
  */
 interface ConfigSourceInterface
 {
+    /**
+     * Add a repository
+     *
+     * @param string $name   Name
+     * @param array  $config Configuration
+     */
     public function addRepository($name, $config);
 
+    /**
+     * Remove a repository
+     *
+     * @param string $name
+     */
     public function removeRepository($name);
 
+    /**
+     * Add a config setting
+     *
+     * @param string $name  Name
+     * @param string $value Value
+     */
     public function addConfigSetting($name, $value);
 
+    /**
+     * Remove a config setting
+     *
+     * @param string $name
+     */
     public function removeConfigSetting($name);
+
+    /**
+     * Add a package link
+     *
+     * @param string $type  Type (require, require-dev, provide, suggest, replace, conflict)
+     * @param string $name  Name
+     * @param string $value Value
+     */
+    public function addLink($type, $name, $value);
+
+    /**
+     * Remove a package link
+     *
+     * @param string $type Type (require, require-dev, provide, suggest, replace, conflict)
+     * @param string $name Name
+     */
+    public function removeLink($type, $name);
 }

+ 41 - 1
src/Composer/Config/JsonConfigSource.php

@@ -12,22 +12,33 @@
 
 namespace Composer\Config;
 
-use Composer\Json\JsonManipulator;
 use Composer\Json\JsonFile;
+use Composer\Json\JsonManipulator;
 
 /**
+ * JSON Configuration Source
+ *
  * @author Jordi Boggiano <j.boggiano@seld.be>
+ * @author Beau Simensen <beau@dflydev.com>
  */
 class JsonConfigSource implements ConfigSourceInterface
 {
     private $file;
     private $manipulator;
 
+    /**
+     * Constructor
+     *
+     * @param JsonFile $file
+     */
     public function __construct(JsonFile $file)
     {
         $this->file = $file;
     }
 
+    /**
+     * {@inheritdoc}
+     */
     public function addRepository($name, $config)
     {
         $this->manipulateJson('addRepository', $name, $config, function (&$config, $repo, $repoConfig) {
@@ -35,6 +46,9 @@ class JsonConfigSource implements ConfigSourceInterface
         });
     }
 
+    /**
+     * {@inheritdoc}
+     */
     public function removeRepository($name)
     {
         $this->manipulateJson('removeRepository', $name, function (&$config, $repo) {
@@ -42,6 +56,9 @@ class JsonConfigSource implements ConfigSourceInterface
         });
     }
 
+    /**
+     * {@inheritdoc}
+     */
     public function addConfigSetting($name, $value)
     {
         $this->manipulateJson('addConfigSetting', $name, $value, function (&$config, $key, $val) {
@@ -49,6 +66,9 @@ class JsonConfigSource implements ConfigSourceInterface
         });
     }
 
+    /**
+     * {@inheritdoc}
+     */
     public function removeConfigSetting($name)
     {
         $this->manipulateJson('removeConfigSetting', $name, function (&$config, $key) {
@@ -56,6 +76,26 @@ class JsonConfigSource implements ConfigSourceInterface
         });
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function addLink($type, $name, $value)
+    {
+        $this->manipulateJson('addLink', $type, $name, $value, function (&$config, $key) {
+            $config[$type][$name] = $value;
+        });
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function removeLink($type, $name)
+    {
+        $this->manipulateJson('removeSubNode', $type, $name, function (&$config, $key) {
+            unset($config[$type][$name]);
+        });
+    }
+
     protected function manipulateJson($method, $args, $fallback)
     {
         $args = func_get_args();

+ 7 - 0
tests/Composer/Test/Config/Fixtures/addLink/conflict-from-empty.json

@@ -0,0 +1,7 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "conflict": {
+        "my-vend/my-old-app": "1.*"
+    }
+}

+ 23 - 0
tests/Composer/Test/Config/Fixtures/addLink/conflict-from-oneOfEverything.json

@@ -0,0 +1,23 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-old-app": "1.*"
+    }
+}

+ 29 - 0
tests/Composer/Test/Config/Fixtures/addLink/conflict-from-twoOfEverything.json

@@ -0,0 +1,29 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*",
+        "my-vend/my-old-app": "1.*"
+    }
+}

+ 7 - 0
tests/Composer/Test/Config/Fixtures/addLink/provide-from-empty.json

@@ -0,0 +1,7 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "provide": {
+        "my-vend/my-lib-interface": "1.*"
+    }
+}

+ 23 - 0
tests/Composer/Test/Config/Fixtures/addLink/provide-from-oneOfEverything.json

@@ -0,0 +1,23 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-lib-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*"
+    }
+}

+ 29 - 0
tests/Composer/Test/Config/Fixtures/addLink/provide-from-twoOfEverything.json

@@ -0,0 +1,29 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*",
+        "my-vend/my-lib-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*"
+    }
+}

+ 7 - 0
tests/Composer/Test/Config/Fixtures/addLink/replace-from-empty.json

@@ -0,0 +1,7 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "replace": {
+        "my-vend/other-app": "1.*"
+    }
+}

+ 23 - 0
tests/Composer/Test/Config/Fixtures/addLink/replace-from-oneOfEverything.json

@@ -0,0 +1,23 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "my-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*"
+    }
+}

+ 29 - 0
tests/Composer/Test/Config/Fixtures/addLink/replace-from-twoOfEverything.json

@@ -0,0 +1,29 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*",
+        "my-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*"
+    }
+}

+ 7 - 0
tests/Composer/Test/Config/Fixtures/addLink/require-dev-from-empty.json

@@ -0,0 +1,7 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require-dev": {
+        "my-vend/my-lib-tests": "1.*"
+    }
+}

+ 23 - 0
tests/Composer/Test/Config/Fixtures/addLink/require-dev-from-oneOfEverything.json

@@ -0,0 +1,23 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*"
+    }
+}

+ 29 - 0
tests/Composer/Test/Config/Fixtures/addLink/require-dev-from-twoOfEverything.json

@@ -0,0 +1,29 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*",
+        "my-vend/my-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*"
+    }
+}

+ 7 - 0
tests/Composer/Test/Config/Fixtures/addLink/require-from-empty.json

@@ -0,0 +1,7 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-lib": "1.*"
+    }
+}

+ 23 - 0
tests/Composer/Test/Config/Fixtures/addLink/require-from-oneOfEverything.json

@@ -0,0 +1,23 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*"
+    }
+}

+ 29 - 0
tests/Composer/Test/Config/Fixtures/addLink/require-from-twoOfEverything.json

@@ -0,0 +1,29 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*",
+        "my-vend/my-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*"
+    }
+}

+ 7 - 0
tests/Composer/Test/Config/Fixtures/addLink/suggest-from-empty.json

@@ -0,0 +1,7 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "suggest": {
+        "my-vend/my-optional-extension": "1.*"
+    }
+}

+ 23 - 0
tests/Composer/Test/Config/Fixtures/addLink/suggest-from-oneOfEverything.json

@@ -0,0 +1,23 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*"
+    }
+}

+ 29 - 0
tests/Composer/Test/Config/Fixtures/addLink/suggest-from-twoOfEverything.json

@@ -0,0 +1,29 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*",
+        "my-vend/my-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*"
+    }
+}

+ 4 - 0
tests/Composer/Test/Config/Fixtures/composer-empty.json

@@ -0,0 +1,4 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT"
+}

+ 22 - 0
tests/Composer/Test/Config/Fixtures/composer-one-of-everything.json

@@ -0,0 +1,22 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*"
+    }
+}

+ 28 - 0
tests/Composer/Test/Config/Fixtures/composer-two-of-everything.json

@@ -0,0 +1,28 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*"
+    }
+}

+ 6 - 0
tests/Composer/Test/Config/Fixtures/removeLink/conflict-to-empty-after.json

@@ -0,0 +1,6 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "conflict": {
+    }
+}

+ 7 - 0
tests/Composer/Test/Config/Fixtures/removeLink/conflict-to-empty.json

@@ -0,0 +1,7 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "conflict": {
+        "my-vend/my-old-app": "1.*"
+    }
+}

+ 23 - 0
tests/Composer/Test/Config/Fixtures/removeLink/conflict-to-oneOfEverything.json

@@ -0,0 +1,23 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-old-app": "1.*"
+    }
+}

+ 29 - 0
tests/Composer/Test/Config/Fixtures/removeLink/conflict-to-twoOfEverything.json

@@ -0,0 +1,29 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*",
+        "my-vend/my-old-app": "1.*"
+    }
+}

+ 6 - 0
tests/Composer/Test/Config/Fixtures/removeLink/provide-to-empty-after.json

@@ -0,0 +1,6 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "provide": {
+    }
+}

+ 7 - 0
tests/Composer/Test/Config/Fixtures/removeLink/provide-to-empty.json

@@ -0,0 +1,7 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "provide": {
+        "my-vend/my-lib-interface": "1.*"
+    }
+}

+ 23 - 0
tests/Composer/Test/Config/Fixtures/removeLink/provide-to-oneOfEverything.json

@@ -0,0 +1,23 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-lib-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*"
+    }
+}

+ 29 - 0
tests/Composer/Test/Config/Fixtures/removeLink/provide-to-twoOfEverything.json

@@ -0,0 +1,29 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*",
+        "my-vend/my-lib-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*"
+    }
+}

+ 6 - 0
tests/Composer/Test/Config/Fixtures/removeLink/replace-to-empty-after.json

@@ -0,0 +1,6 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "replace": {
+    }
+}

+ 7 - 0
tests/Composer/Test/Config/Fixtures/removeLink/replace-to-empty.json

@@ -0,0 +1,7 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "replace": {
+        "my-vend/other-app": "1.*"
+    }
+}

+ 23 - 0
tests/Composer/Test/Config/Fixtures/removeLink/replace-to-oneOfEverything.json

@@ -0,0 +1,23 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "my-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*"
+    }
+}

+ 29 - 0
tests/Composer/Test/Config/Fixtures/removeLink/replace-to-twoOfEverything.json

@@ -0,0 +1,29 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*",
+        "my-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*"
+    }
+}

+ 6 - 0
tests/Composer/Test/Config/Fixtures/removeLink/require-dev-to-empty-after.json

@@ -0,0 +1,6 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require-dev": {
+    }
+}

+ 7 - 0
tests/Composer/Test/Config/Fixtures/removeLink/require-dev-to-empty.json

@@ -0,0 +1,7 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require-dev": {
+        "my-vend/my-lib-tests": "1.*"
+    }
+}

+ 23 - 0
tests/Composer/Test/Config/Fixtures/removeLink/require-dev-to-oneOfEverything.json

@@ -0,0 +1,23 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*"
+    }
+}

+ 29 - 0
tests/Composer/Test/Config/Fixtures/removeLink/require-dev-to-twoOfEverything.json

@@ -0,0 +1,29 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*",
+        "my-vend/my-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*"
+    }
+}

+ 6 - 0
tests/Composer/Test/Config/Fixtures/removeLink/require-to-empty-after.json

@@ -0,0 +1,6 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+    }
+}

+ 7 - 0
tests/Composer/Test/Config/Fixtures/removeLink/require-to-empty.json

@@ -0,0 +1,7 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-lib": "1.*"
+    }
+}

+ 23 - 0
tests/Composer/Test/Config/Fixtures/removeLink/require-to-oneOfEverything.json

@@ -0,0 +1,23 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*"
+    }
+}

+ 29 - 0
tests/Composer/Test/Config/Fixtures/removeLink/require-to-twoOfEverything.json

@@ -0,0 +1,29 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*",
+        "my-vend/my-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*"
+    }
+}

+ 6 - 0
tests/Composer/Test/Config/Fixtures/removeLink/suggest-to-empty-after.json

@@ -0,0 +1,6 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "suggest": {
+    }
+}

+ 7 - 0
tests/Composer/Test/Config/Fixtures/removeLink/suggest-to-empty.json

@@ -0,0 +1,7 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "suggest": {
+        "my-vend/my-optional-extension": "1.*"
+    }
+}

+ 23 - 0
tests/Composer/Test/Config/Fixtures/removeLink/suggest-to-oneOfEverything.json

@@ -0,0 +1,23 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*"
+    }
+}

+ 29 - 0
tests/Composer/Test/Config/Fixtures/removeLink/suggest-to-twoOfEverything.json

@@ -0,0 +1,29 @@
+{
+    "name": "my-vend/my-app",
+    "license": "MIT",
+    "require": {
+        "my-vend/my-other-lib": "1.*",
+        "my-vend/my-yet-another-lib": "1.*"
+    },
+    "require-dev": {
+        "my-vend/my-other-lib-tests": "1.*",
+        "my-vend/my-yet-another-lib-tests": "1.*"
+    },
+    "provide": {
+        "my-vend/my-other-interface": "1.*",
+        "my-vend/my-yet-another-interface": "1.*"
+    },
+    "suggest": {
+        "my-vend/my-other-optional-extension": "1.*",
+        "my-vend/my-yet-another-optional-extension": "1.*",
+        "my-vend/my-optional-extension": "1.*"
+    },
+    "replace": {
+        "other-vend/other-app": "1.*",
+        "other-vend/yet-another-app": "1.*"
+    },
+    "conflict": {
+        "my-vend/my-other-old-app": "1.*",
+        "my-vend/my-yet-another-old-app": "1.*"
+    }
+}

+ 188 - 0
tests/Composer/Test/Config/JsonConfigSourceTest.php

@@ -0,0 +1,188 @@
+<?php
+
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ *     Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Test\Json;
+
+use Composer\Config\JsonConfigSource;
+use Composer\Json\JsonFile;
+use Composer\Util\Filesystem;
+
+/**
+ * JsonConfigSource Test
+ *
+ * @author Beau Simensen <beau@dflydev.com>
+ */
+class JsonConfigSourceTest extends \PHPUnit_Framework_TestCase
+{
+    private $workingDir;
+
+    protected function fixturePath($name)
+    {
+        return __DIR__.'/Fixtures/'.$name;
+    }
+
+    protected function setUp()
+    {
+        $this->fs = new Filesystem;
+        $this->workingDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'cmptest';
+        $this->fs->ensureDirectoryExists($this->workingDir);
+    }
+
+    protected function tearDown()
+    {
+        if (is_dir($this->workingDir)) {
+            $this->fs->removeDirectory($this->workingDir);
+        }
+    }
+
+    protected function addLinkDataArguments($type, $name, $value, $fixtureBasename, $before)
+    {
+        return array(
+            $before,
+            $type,
+            $name,
+            $value,
+            $this->fixturePath('addLink/'.$fixtureBasename.'.json'),
+        );
+
+    }
+
+    /**
+     * Provide data for testAddLink
+     *
+     * @return array
+     */
+    public function provideAddLinkData()
+    {
+        $empty = $this->fixturePath('composer-empty.json');
+        $oneOfEverything = $this->fixturePath('composer-one-of-everything.json');
+        $twoOfEverything = $this->fixturePath('composer-two-of-everything.json');
+
+        return array(
+
+            $this->addLinkDataArguments('require', 'my-vend/my-lib', '1.*', 'require-from-empty', $empty),
+            $this->addLinkDataArguments('require', 'my-vend/my-lib', '1.*', 'require-from-oneOfEverything', $oneOfEverything),
+            $this->addLinkDataArguments('require', 'my-vend/my-lib', '1.*', 'require-from-twoOfEverything', $twoOfEverything),
+
+            $this->addLinkDataArguments('require-dev', 'my-vend/my-lib-tests', '1.*', 'require-dev-from-empty', $empty),
+            $this->addLinkDataArguments('require-dev', 'my-vend/my-lib-tests', '1.*', 'require-dev-from-oneOfEverything', $oneOfEverything),
+            $this->addLinkDataArguments('require-dev', 'my-vend/my-lib-tests', '1.*', 'require-dev-from-twoOfEverything', $twoOfEverything),
+
+            $this->addLinkDataArguments('provide', 'my-vend/my-lib-interface', '1.*', 'provide-from-empty', $empty),
+            $this->addLinkDataArguments('provide', 'my-vend/my-lib-interface', '1.*', 'provide-from-oneOfEverything', $oneOfEverything),
+            $this->addLinkDataArguments('provide', 'my-vend/my-lib-interface', '1.*', 'provide-from-twoOfEverything', $twoOfEverything),
+
+            $this->addLinkDataArguments('suggest', 'my-vend/my-optional-extension', '1.*', 'suggest-from-empty', $empty),
+            $this->addLinkDataArguments('suggest', 'my-vend/my-optional-extension', '1.*', 'suggest-from-oneOfEverything', $oneOfEverything),
+            $this->addLinkDataArguments('suggest', 'my-vend/my-optional-extension', '1.*', 'suggest-from-twoOfEverything', $twoOfEverything),
+
+            $this->addLinkDataArguments('replace', 'my-vend/other-app', '1.*', 'replace-from-empty', $empty),
+            $this->addLinkDataArguments('replace', 'my-vend/other-app', '1.*', 'replace-from-oneOfEverything', $oneOfEverything),
+            $this->addLinkDataArguments('replace', 'my-vend/other-app', '1.*', 'replace-from-twoOfEverything', $twoOfEverything),
+
+            $this->addLinkDataArguments('conflict', 'my-vend/my-old-app', '1.*', 'conflict-from-empty', $empty),
+            $this->addLinkDataArguments('conflict', 'my-vend/my-old-app', '1.*', 'conflict-from-oneOfEverything', $oneOfEverything),
+            $this->addLinkDataArguments('conflict', 'my-vend/my-old-app', '1.*', 'conflict-from-twoOfEverything', $twoOfEverything),
+        );
+    }
+
+    /**
+     * Test addLink()
+     *
+     * @param string $sourceFile     Source file
+     * @param string $type           Type (require, require-dev, provide, suggest, replace, conflict)
+     * @param string $name           Name
+     * @param string $value          Value
+     * @param string $compareAgainst File to compare against after making changes
+     *
+     * @dataProvider provideAddLinkData
+     */
+    public function testAddLink($sourceFile, $type, $name, $value, $compareAgainst)
+    {
+        $composerJson = $this->workingDir.'/composer.json';
+        copy($sourceFile, $composerJson);
+        $jsonConfigSource = new JsonConfigSource(new JsonFile($composerJson));
+
+        $jsonConfigSource->addLink($type, $name, $value);
+
+        $this->assertFileEquals($compareAgainst, $composerJson);
+    }
+
+    protected function removeLinkDataArguments($type, $name, $fixtureBasename, $after = null)
+    {
+        return array(
+            $this->fixturePath('removeLink/'.$fixtureBasename.'.json'),
+            $type,
+            $name,
+            $after ?: $this->fixturePath('removeLink/'.$fixtureBasename.'-after.json'),
+        );
+
+    }
+
+    /**
+     * Provide data for testRemoveLink
+     *
+     * @return array
+     */
+    public function provideRemoveLinkData()
+    {
+        $oneOfEverything = $this->fixturePath('composer-one-of-everything.json');
+        $twoOfEverything = $this->fixturePath('composer-two-of-everything.json');
+
+        return array(
+            $this->removeLinkDataArguments('require', 'my-vend/my-lib', 'require-to-empty'),
+            $this->removeLinkDataArguments('require', 'my-vend/my-lib', 'require-to-oneOfEverything', $oneOfEverything),
+            $this->removeLinkDataArguments('require', 'my-vend/my-lib', 'require-to-twoOfEverything', $twoOfEverything),
+
+            $this->removeLinkDataArguments('require-dev', 'my-vend/my-lib-tests', 'require-dev-to-empty'),
+            $this->removeLinkDataArguments('require-dev', 'my-vend/my-lib-tests', 'require-dev-to-oneOfEverything', $oneOfEverything),
+            $this->removeLinkDataArguments('require-dev', 'my-vend/my-lib-tests', 'require-dev-to-twoOfEverything', $twoOfEverything),
+
+            $this->removeLinkDataArguments('provide', 'my-vend/my-lib-interface', 'provide-to-empty'),
+            $this->removeLinkDataArguments('provide', 'my-vend/my-lib-interface', 'provide-to-oneOfEverything', $oneOfEverything),
+            $this->removeLinkDataArguments('provide', 'my-vend/my-lib-interface', 'provide-to-twoOfEverything', $twoOfEverything),
+
+            $this->removeLinkDataArguments('suggest', 'my-vend/my-optional-extension', 'suggest-to-empty'),
+            $this->removeLinkDataArguments('suggest', 'my-vend/my-optional-extension', 'suggest-to-oneOfEverything', $oneOfEverything),
+            $this->removeLinkDataArguments('suggest', 'my-vend/my-optional-extension', 'suggest-to-twoOfEverything', $twoOfEverything),
+
+            $this->removeLinkDataArguments('replace', 'my-vend/other-app', 'replace-to-empty'),
+            $this->removeLinkDataArguments('replace', 'my-vend/other-app', 'replace-to-oneOfEverything', $oneOfEverything),
+            $this->removeLinkDataArguments('replace', 'my-vend/other-app', 'replace-to-twoOfEverything', $twoOfEverything),
+
+            $this->removeLinkDataArguments('conflict', 'my-vend/my-old-app', 'conflict-to-empty'),
+            $this->removeLinkDataArguments('conflict', 'my-vend/my-old-app', 'conflict-to-oneOfEverything', $oneOfEverything),
+            $this->removeLinkDataArguments('conflict', 'my-vend/my-old-app', 'conflict-to-twoOfEverything', $twoOfEverything),
+        );
+    }
+
+    /**
+     * Test removeLink()
+     *
+     * @param string $sourceFile     Source file
+     * @param string $type           Type (require, require-dev, provide, suggest, replace, conflict)
+     * @param string $name           Name
+     * @param string $compareAgainst File to compare against after making changes
+     *
+     * @dataProvider provideRemoveLinkData
+     */
+    public function testRemoveLink($sourceFile, $type, $name, $compareAgainst)
+    {
+        $composerJson = $this->workingDir.'/composer.json';
+        copy($sourceFile, $composerJson);
+        $jsonConfigSource = new JsonConfigSource(new JsonFile($composerJson));
+
+        $jsonConfigSource->removeLink($type, $name);
+
+        $this->assertFileEquals($compareAgainst, $composerJson);
+    }
+}