VersionTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Intl\Tests\Util;
  11. use Symfony\Component\Intl\Util\Version;
  12. /**
  13. * @author Bernhard Schussek <bschussek@gmail.com>
  14. */
  15. class VersionTest extends \PHPUnit_Framework_TestCase
  16. {
  17. public function normalizeProvider()
  18. {
  19. return array(
  20. array(null, '1', '1'),
  21. array(null, '1.2', '1.2'),
  22. array(null, '1.2.3', '1.2.3'),
  23. array(null, '1.2.3.4', '1.2.3.4'),
  24. array(1, '1', '1'),
  25. array(1, '1.2', '1'),
  26. array(1, '1.2.3', '1'),
  27. array(1, '1.2.3.4', '1'),
  28. array(2, '1', '1'),
  29. array(2, '1.2', '1.2'),
  30. array(2, '1.2.3', '1.2'),
  31. array(2, '1.2.3.4', '1.2'),
  32. array(3, '1', '1'),
  33. array(3, '1.2', '1.2'),
  34. array(3, '1.2.3', '1.2.3'),
  35. array(3, '1.2.3.4', '1.2.3'),
  36. array(4, '1', '1'),
  37. array(4, '1.2', '1.2'),
  38. array(4, '1.2.3', '1.2.3'),
  39. array(4, '1.2.3.4', '1.2.3.4'),
  40. );
  41. }
  42. /**
  43. * @dataProvider normalizeProvider
  44. */
  45. public function testNormalize($precision, $version, $result)
  46. {
  47. $this->assertSame($result, Version::normalize($version, $precision));
  48. }
  49. public function compareProvider()
  50. {
  51. return array(
  52. array(null, '1', '==', '1', true),
  53. array(null, '1.0', '==', '1.1', false),
  54. array(null, '1.0.0', '==', '1.0.1', false),
  55. array(null, '1.0.0.0', '==', '1.0.0.1', false),
  56. array(1, '1', '==', '1', true),
  57. array(1, '1.0', '==', '1.1', true),
  58. array(1, '1.0.0', '==', '1.0.1', true),
  59. array(1, '1.0.0.0', '==', '1.0.0.1', true),
  60. array(2, '1', '==', '1', true),
  61. array(2, '1.0', '==', '1.1', false),
  62. array(2, '1.0.0', '==', '1.0.1', true),
  63. array(2, '1.0.0.0', '==', '1.0.0.1', true),
  64. array(3, '1', '==', '1', true),
  65. array(3, '1.0', '==', '1.1', false),
  66. array(3, '1.0.0', '==', '1.0.1', false),
  67. array(3, '1.0.0.0', '==', '1.0.0.1', true),
  68. );
  69. }
  70. /**
  71. * @dataProvider compareProvider
  72. */
  73. public function testCompare($precision, $version1, $operator, $version2, $result)
  74. {
  75. $this->assertSame($result, Version::compare($version1, $version2, $operator, $precision));
  76. }
  77. }