VersionTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Version
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_VersionTest::main');
  24. }
  25. /**
  26. * @see Zend_Version
  27. */
  28. require_once 'Zend/Version.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Version
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Version
  36. */
  37. class Zend_VersionTest extends PHPUnit_Framework_TestCase
  38. {
  39. public static function main()
  40. {
  41. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  42. $result = PHPUnit_TextUI_TestRunner::run($suite);
  43. }
  44. /**
  45. * Tests that version_compare() and its "proxy"
  46. * Zend_Version::compareVersion() work as expected.
  47. */
  48. public function testVersionCompare()
  49. {
  50. $expect = -1;
  51. // unit test breaks if ZF version > 1.x
  52. for ($i=0; $i <= 1; $i++) {
  53. for ($j=0; $j <= 12; $j++) {
  54. for ($k=0; $k < 20; $k++) {
  55. foreach (array('dev', 'pr', 'PR', 'alpha', 'a1', 'a2', 'beta', 'b1', 'b2', 'RC', 'RC1', 'RC2', 'RC3', '', 'pl1', 'PL1') as $rel) {
  56. $ver = "$i.$j.$k$rel";
  57. $normalizedVersion = strtolower(Zend_Version::VERSION);
  58. if (strtolower($ver) === $normalizedVersion
  59. || strtolower("$i.$j.$k-$rel") === $normalizedVersion
  60. || strtolower("$i.$j.$k.$rel") === $normalizedVersion
  61. || strtolower("$i.$j.$k $rel") === $normalizedVersion
  62. ) {
  63. if ($expect == -1) {
  64. $expect = 1;
  65. }
  66. } else {
  67. $this->assertSame(
  68. Zend_Version::compareVersion($ver),
  69. $expect,
  70. "For version '$ver' and Zend_Version::VERSION = '"
  71. . Zend_Version::VERSION . "': result=" . (Zend_Version::compareVersion($ver))
  72. . ', but expected ' . $expect);
  73. }
  74. }
  75. }
  76. }
  77. }
  78. if ($expect === -1) {
  79. $this->fail('Unable to recognize Zend_Version::VERSION ('. Zend_Version::VERSION . '); last version compared: ' . $ver);
  80. }
  81. }
  82. /**
  83. * @group ZF-10363
  84. */
  85. public function testFetchLatestVersion()
  86. {
  87. if (!defined('TESTS_ZEND_VERSION_ONLINE_ENABLED')
  88. || !constant('TESTS_ZEND_VERSION_ONLINE_ENABLED')
  89. ) {
  90. $this->markTestSkipped('Testing fetchLatersVersion only works when TESTS_ZEND_VERSION_ONLINE_ENABLED is set.');
  91. return;
  92. }
  93. $actual = Zend_Version::getLatest();
  94. if ('not available' === $actual) {
  95. $this->markTestIncomplete('http://framework.zend.com/ may be down');
  96. }
  97. $this->assertRegExp('/^[1-2](\.[0-9]+){2}/', $actual);
  98. }
  99. }
  100. if (PHPUnit_MAIN_METHOD == "Zend_VersionTest::main") {
  101. Zend_VersionTest::main();
  102. }