VersionParserTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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\Package\Version;
  12. use Composer\Package\Version\VersionParser;
  13. use Composer\Test\TestCase;
  14. class VersionParserTest extends TestCase
  15. {
  16. /**
  17. * @dataProvider getParseNameVersionPairsData
  18. */
  19. public function testParseNameVersionPairs($pairs, $result)
  20. {
  21. $versionParser = new VersionParser();
  22. $this->assertSame($result, $versionParser->parseNameVersionPairs($pairs));
  23. }
  24. public function getParseNameVersionPairsData()
  25. {
  26. return array(
  27. array(array('php:^7.0'), array(array('name' => 'php', 'version' => '^7.0'))),
  28. array(array('php', '^7.0'), array(array('name' => 'php', 'version' => '^7.0'))),
  29. array(array('php', 'ext-apcu'), array(array('name' => 'php'), array('name' => 'ext-apcu'))),
  30. );
  31. }
  32. /**
  33. * @dataProvider getIsUpgradeTests
  34. */
  35. public function testIsUpgrade($from, $to, $expected)
  36. {
  37. $this->assertSame($expected, VersionParser::isUpgrade($from, $to));
  38. }
  39. public function getIsUpgradeTests()
  40. {
  41. return array(
  42. array('0.9.0.0', '1.0.0.0', true),
  43. array('1.0.0.0', '0.9.0.0', false),
  44. array('1.0.0.0', VersionParser::DEV_MASTER_ALIAS, true),
  45. array(VersionParser::DEV_MASTER_ALIAS, VersionParser::DEV_MASTER_ALIAS, true),
  46. array(VersionParser::DEV_MASTER_ALIAS, '1.0.0.0', false),
  47. array('1.0.0.0', 'dev-foo', true),
  48. array('dev-foo', 'dev-foo', true),
  49. array('dev-foo', '1.0.0.0', true),
  50. );
  51. }
  52. }