2012-06-09 05:48:52 +00:00
|
|
|
<?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.
|
|
|
|
*/
|
|
|
|
|
2016-10-05 08:45:22 +00:00
|
|
|
namespace Composer\Test\Repository\Pear;
|
2012-06-09 05:48:52 +00:00
|
|
|
|
2016-10-05 08:45:22 +00:00
|
|
|
use Composer\Repository\Pear\DependencyConstraint;
|
|
|
|
use Composer\Repository\Pear\PackageDependencyParser;
|
2013-09-25 08:14:42 +00:00
|
|
|
use Composer\TestCase;
|
2012-06-09 05:48:52 +00:00
|
|
|
|
|
|
|
class PackageDependencyParserTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider dataProvider10
|
|
|
|
* @param $expected
|
2013-06-13 00:05:44 +00:00
|
|
|
* @param $data10
|
|
|
|
* @param $data20
|
2012-06-09 05:48:52 +00:00
|
|
|
*/
|
|
|
|
public function testShouldParseDependencies($expected, $data10, $data20)
|
|
|
|
{
|
|
|
|
$expectedDependencies = array();
|
|
|
|
foreach ($expected as $expectedItem) {
|
|
|
|
$expectedDependencies[] = new DependencyConstraint(
|
|
|
|
$expectedItem['type'],
|
|
|
|
$expectedItem['constraint'],
|
|
|
|
$expectedItem['channel'],
|
|
|
|
$expectedItem['name']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$parser = new PackageDependencyParser();
|
|
|
|
|
|
|
|
if (false !== $data10) {
|
|
|
|
$result = $parser->buildDependencyInfo($data10);
|
|
|
|
$this->assertEquals($expectedDependencies, $result->getRequires() + $result->getOptionals(), "Failed for package.xml 1.0 format");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (false !== $data20) {
|
|
|
|
$result = $parser->buildDependencyInfo($data20);
|
|
|
|
$this->assertEquals($expectedDependencies, $result->getRequires() + $result->getOptionals(), "Failed for package.xml 2.0 format");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataProvider10()
|
|
|
|
{
|
|
|
|
$data = json_decode(file_get_contents(__DIR__.'/Fixtures/DependencyParserTestData.json'), true);
|
|
|
|
if (0 !== json_last_error()) {
|
|
|
|
throw new \PHPUnit_Framework_Exception('Invalid json file.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|