PackageDependencyParserTest.php 1.7 KB

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