|
|
|
@ -18,6 +18,9 @@ use Composer\Util\Filesystem;
|
|
|
|
|
|
|
|
|
|
class JsonConfigSourceTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
{
|
|
|
|
|
/** @var Filesystem */
|
|
|
|
|
private $fs;
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $workingDir;
|
|
|
|
|
|
|
|
|
|
protected function fixturePath($name)
|
|
|
|
@ -39,6 +42,89 @@ class JsonConfigSourceTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAddRepository()
|
|
|
|
|
{
|
|
|
|
|
$config = $this->workingDir.'/composer.json';
|
|
|
|
|
copy($this->fixturePath('composer-repositories.json'), $config);
|
|
|
|
|
$jsonConfigSource = new JsonConfigSource(new JsonFile($config));
|
|
|
|
|
$jsonConfigSource->addRepository('example_tld', array('type' => 'git', 'url' => 'example.tld'));
|
|
|
|
|
|
|
|
|
|
$this->assertFileEquals($this->fixturePath('config/config-with-exampletld-repository.json'), $config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRemoveRepository()
|
|
|
|
|
{
|
|
|
|
|
$config = $this->workingDir.'/composer.json';
|
|
|
|
|
copy($this->fixturePath('config/config-with-exampletld-repository.json'), $config);
|
|
|
|
|
$jsonConfigSource = new JsonConfigSource(new JsonFile($config));
|
|
|
|
|
$jsonConfigSource->removeRepository('example_tld');
|
|
|
|
|
|
|
|
|
|
$this->assertFileEquals($this->fixturePath('composer-repositories.json'), $config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAddPackagistRepositoryWithFalseValue()
|
|
|
|
|
{
|
|
|
|
|
$config = $this->workingDir.'/composer.json';
|
|
|
|
|
copy($this->fixturePath('composer-repositories.json'), $config);
|
|
|
|
|
$jsonConfigSource = new JsonConfigSource(new JsonFile($config));
|
|
|
|
|
$jsonConfigSource->addRepository('packagist', false);
|
|
|
|
|
|
|
|
|
|
$this->assertFileEquals($this->fixturePath('config/config-with-packagist-false.json'), $config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRemovePackagist()
|
|
|
|
|
{
|
|
|
|
|
$config = $this->workingDir.'/composer.json';
|
|
|
|
|
copy($this->fixturePath('config/config-with-packagist-false.json'), $config);
|
|
|
|
|
$jsonConfigSource = new JsonConfigSource(new JsonFile($config));
|
|
|
|
|
$jsonConfigSource->removeRepository('packagist');
|
|
|
|
|
|
|
|
|
|
$this->assertFileEquals($this->fixturePath('composer-repositories.json'), $config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function addLinkDataArguments($type, $name, $value, $fixtureBasename, $before)
|
|
|
|
|
{
|
|
|
|
|
return array(
|
|
|
|
@ -88,28 +174,6 @@ class JsonConfigSourceTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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(
|
|
|
|
@ -156,25 +220,4 @@ class JsonConfigSourceTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
$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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|