PackageDependencyParserTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Repository\Pear;
  12. use Composer\Repository\Pear\DependencyConstraint;
  13. use Composer\Repository\Pear\PackageDependencyParser;
  14. use Composer\Test\TestCase;
  15. class PackageDependencyParserTest extends TestCase
  16. {
  17. /**
  18. * @dataProvider dataProvider10
  19. * @param $expected
  20. * @param $data10
  21. * @param $data20
  22. */
  23. public function testShouldParseDependencies($expected, $data10, $data20)
  24. {
  25. $expectedDependencies = array();
  26. foreach ($expected as $expectedItem) {
  27. $expectedDependencies[] = new DependencyConstraint(
  28. $expectedItem['type'],
  29. $expectedItem['constraint'],
  30. $expectedItem['channel'],
  31. $expectedItem['name']
  32. );
  33. }
  34. $parser = new PackageDependencyParser();
  35. if (false !== $data10) {
  36. $result = $parser->buildDependencyInfo($data10);
  37. $this->assertEquals($expectedDependencies, $result->getRequires() + $result->getOptionals(), "Failed for package.xml 1.0 format");
  38. }
  39. if (false !== $data20) {
  40. $result = $parser->buildDependencyInfo($data20);
  41. $this->assertEquals($expectedDependencies, $result->getRequires() + $result->getOptionals(), "Failed for package.xml 2.0 format");
  42. }
  43. }
  44. public function dataProvider10()
  45. {
  46. $data = json_decode(file_get_contents(__DIR__.'/Fixtures/DependencyParserTestData.json'), true);
  47. if (0 !== json_last_error()) {
  48. throw new \PHPUnit_Framework_Exception('Invalid json file.');
  49. }
  50. return $data;
  51. }
  52. }