PackageDependencyParserTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\Repository\Pear;
  12. use Composer\Test\TestCase;
  13. class PackageDependencyParserTest extends TestCase
  14. {
  15. /**
  16. * @dataProvider dataProvider10
  17. * @param $expected
  18. * @param $data
  19. */
  20. public function testShouldParseDependencies($expected, $data10, $data20)
  21. {
  22. $expectedDependencies = array();
  23. foreach ($expected as $expectedItem) {
  24. $expectedDependencies[] = new DependencyConstraint(
  25. $expectedItem['type'],
  26. $expectedItem['constraint'],
  27. $expectedItem['channel'],
  28. $expectedItem['name']
  29. );
  30. }
  31. $parser = new PackageDependencyParser();
  32. if (false !== $data10) {
  33. $result = $parser->buildDependencyInfo($data10);
  34. $this->assertEquals($expectedDependencies, $result->getRequires() + $result->getOptionals(), "Failed for package.xml 1.0 format");
  35. }
  36. if (false !== $data20) {
  37. $result = $parser->buildDependencyInfo($data20);
  38. $this->assertEquals($expectedDependencies, $result->getRequires() + $result->getOptionals(), "Failed for package.xml 2.0 format");
  39. }
  40. }
  41. public function dataProvider10()
  42. {
  43. $data = json_decode(file_get_contents(__DIR__.'/Fixtures/DependencyParserTestData.json'), true);
  44. if (0 !== json_last_error()) {
  45. throw new \PHPUnit_Framework_Exception('Invalid json file.');
  46. }
  47. return $data;
  48. }
  49. }