minor #12554 compare version using PHP_VERSION_ID (xabbuh)

This PR was merged into the 2.5 branch.

Discussion
----------

compare version using PHP_VERSION_ID

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

This continues the work started in #12497 on the `2.3` branch.

Commits
-------

d2f846b compare version using PHP_VERSION_ID
This commit is contained in:
Fabien Potencier 2014-11-28 10:43:41 +01:00
commit 0dfa7d549e
12 changed files with 16 additions and 16 deletions

View File

@ -474,7 +474,7 @@ class Configuration implements ConfigurationInterface
// API version already during container configuration // API version already during container configuration
// (to adjust service classes etc.) // (to adjust service classes etc.)
// See https://github.com/symfony/symfony/issues/11580 // See https://github.com/symfony/symfony/issues/11580
$v['validation']['api'] = version_compare(PHP_VERSION, '5.3.9', '<') $v['validation']['api'] = PHP_VERSION_ID < 50309
? '2.4' ? '2.4'
: '2.5-bc'; : '2.5-bc';

View File

@ -17,7 +17,7 @@ class JsonDescriptorTest extends AbstractDescriptorTest
{ {
protected function setUp() protected function setUp()
{ {
if (version_compare(phpversion(), '5.4.0', '<')) { if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped on PHP 5.3 as JSON_PRETTY_PRINT does not exist.'); $this->markTestSkipped('Test skipped on PHP 5.3 as JSON_PRETTY_PRINT does not exist.');
} }
} }

View File

@ -129,7 +129,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
'static_method' => array('loadValidatorMetadata'), 'static_method' => array('loadValidatorMetadata'),
'translation_domain' => 'validators', 'translation_domain' => 'validators',
'strict_email' => false, 'strict_email' => false,
'api' => version_compare(PHP_VERSION, '5.3.9', '<') ? '2.4' : '2.5-bc', 'api' => PHP_VERSION_ID < 50309 ? '2.4' : '2.5-bc',
), ),
'annotations' => array( 'annotations' => array(
'cache' => 'file', 'cache' => 'file',

View File

@ -280,7 +280,7 @@ abstract class FrameworkExtensionTest extends TestCase
$this->assertEquals(array(new Reference('validator.mapping.cache.apc')), $calls[5][1]); $this->assertEquals(array(new Reference('validator.mapping.cache.apc')), $calls[5][1]);
$this->assertSame('setApiVersion', $calls[6][0]); $this->assertSame('setApiVersion', $calls[6][0]);
if (version_compare(PHP_VERSION, '5.3.9', '<')) { if (PHP_VERSION_ID < 50309) {
$this->assertEquals(array(Validation::API_VERSION_2_4), $calls[6][1]); $this->assertEquals(array(Validation::API_VERSION_2_4), $calls[6][1]);
} else { } else {
$this->assertEquals(array(Validation::API_VERSION_2_5_BC), $calls[6][1]); $this->assertEquals(array(Validation::API_VERSION_2_5_BC), $calls[6][1]);
@ -433,7 +433,7 @@ abstract class FrameworkExtensionTest extends TestCase
$this->assertSame('setApiVersion', $calls[5][0]); $this->assertSame('setApiVersion', $calls[5][0]);
// no cache, no annotations // no cache, no annotations
if (version_compare(PHP_VERSION, '5.3.9', '<')) { if (PHP_VERSION_ID < 50309) {
$this->assertSame(array(Validation::API_VERSION_2_4), $calls[5][1]); $this->assertSame(array(Validation::API_VERSION_2_4), $calls[5][1]);
} else { } else {
$this->assertSame(array(Validation::API_VERSION_2_5_BC), $calls[5][1]); $this->assertSame(array(Validation::API_VERSION_2_5_BC), $calls[5][1]);
@ -457,7 +457,7 @@ abstract class FrameworkExtensionTest extends TestCase
$this->assertSame('setApiVersion', $calls[5][0]); $this->assertSame('setApiVersion', $calls[5][0]);
// no cache, no annotations // no cache, no annotations
if (version_compare(PHP_VERSION, '5.3.9', '<')) { if (PHP_VERSION_ID < 50309) {
$this->assertSame(array(Validation::API_VERSION_2_4), $calls[5][1]); $this->assertSame(array(Validation::API_VERSION_2_4), $calls[5][1]);
} else { } else {
$this->assertSame(array(Validation::API_VERSION_2_5_BC), $calls[5][1]); $this->assertSame(array(Validation::API_VERSION_2_5_BC), $calls[5][1]);

View File

@ -336,7 +336,7 @@ class Parser
$node = new Node\GetAttrNode($node, $arg, $arguments, $type); $node = new Node\GetAttrNode($node, $arg, $arguments, $type);
} elseif ('[' === $token->value) { } elseif ('[' === $token->value) {
if ($node instanceof Node\GetAttrNode && Node\GetAttrNode::METHOD_CALL === $node->attributes['type'] && version_compare(PHP_VERSION, '5.4.0', '<')) { if ($node instanceof Node\GetAttrNode && Node\GetAttrNode::METHOD_CALL === $node->attributes['type'] && PHP_VERSION_ID < 50400) {
throw new SyntaxError('Array calls on a method call is only supported on PHP 5.4+', $token->cursor); throw new SyntaxError('Array calls on a method call is only supported on PHP 5.4+', $token->cursor);
} }

View File

@ -51,7 +51,7 @@ class NativeSessionTokenStorageTest extends \PHPUnit_Framework_TestCase
public function testStoreTokenInClosedSessionWithExistingSessionId() public function testStoreTokenInClosedSessionWithExistingSessionId()
{ {
if (version_compare(PHP_VERSION, '5.4', '<')) { if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('This test requires PHP 5.4 or later.'); $this->markTestSkipped('This test requires PHP 5.4 or later.');
} }

View File

@ -108,7 +108,7 @@ class NativeSessionTokenStorage implements TokenStorageInterface
private function startSession() private function startSession()
{ {
if (version_compare(PHP_VERSION, '5.4', '>=')) { if (PHP_VERSION_ID >= 50400) {
if (PHP_SESSION_NONE === session_status()) { if (PHP_SESSION_NONE === session_status()) {
session_start(); session_start();
} }

View File

@ -18,7 +18,7 @@ class JsonFileDumperTest extends \PHPUnit_Framework_TestCase
{ {
public function testDump() public function testDump()
{ {
if (version_compare(PHP_VERSION, '5.4.0', '<')) { if (PHP_VERSION_ID < 50400) {
$this->markTestIncomplete('PHP below 5.4 doesn\'t support JSON pretty printing'); $this->markTestIncomplete('PHP below 5.4 doesn\'t support JSON pretty printing');
} }

View File

@ -21,7 +21,7 @@ class LegacyValidator2Dot5ApiTest extends Abstract2Dot5ApiTest
{ {
protected function setUp() protected function setUp()
{ {
if (version_compare(PHP_VERSION, '5.3.9', '<')) { if (PHP_VERSION_ID < 50309) {
$this->markTestSkipped('Not supported prior to PHP 5.3.9'); $this->markTestSkipped('Not supported prior to PHP 5.3.9');
} }

View File

@ -21,7 +21,7 @@ class LegacyValidatorLegacyApiTest extends AbstractLegacyApiTest
{ {
protected function setUp() protected function setUp()
{ {
if (version_compare(PHP_VERSION, '5.3.9', '<')) { if (PHP_VERSION_ID < 50309) {
$this->markTestSkipped('Not supported prior to PHP 5.3.9'); $this->markTestSkipped('Not supported prior to PHP 5.3.9');
} }

View File

@ -112,7 +112,7 @@ class ValidatorBuilderTest extends \PHPUnit_Framework_TestCase
public function testDefaultApiVersion() public function testDefaultApiVersion()
{ {
if (version_compare(PHP_VERSION, '5.3.9', '<')) { if (PHP_VERSION_ID < 50309) {
// Old implementation on PHP < 5.3.9 // Old implementation on PHP < 5.3.9
$this->assertInstanceOf('Symfony\Component\Validator\Validator', $this->builder->getValidator()); $this->assertInstanceOf('Symfony\Component\Validator\Validator', $this->builder->getValidator());
} else { } else {
@ -135,7 +135,7 @@ class ValidatorBuilderTest extends \PHPUnit_Framework_TestCase
public function testSetApiVersion24And25() public function testSetApiVersion24And25()
{ {
if (version_compare(PHP_VERSION, '5.3.9', '<')) { if (PHP_VERSION_ID < 50309) {
$this->markTestSkipped('Not supported prior to PHP 5.3.9'); $this->markTestSkipped('Not supported prior to PHP 5.3.9');
} }

View File

@ -325,7 +325,7 @@ class ValidatorBuilder implements ValidatorBuilderInterface
)); ));
} }
if (version_compare(PHP_VERSION, '5.3.9', '<') && $apiVersion === Validation::API_VERSION_2_5_BC) { if (PHP_VERSION_ID < 50309 && $apiVersion === Validation::API_VERSION_2_5_BC) {
throw new InvalidArgumentException(sprintf( throw new InvalidArgumentException(sprintf(
'The Validator API that is compatible with both Symfony 2.4 '. 'The Validator API that is compatible with both Symfony 2.4 '.
'and Symfony 2.5 can only be used on PHP 5.3.9 and higher. '. 'and Symfony 2.5 can only be used on PHP 5.3.9 and higher. '.
@ -385,7 +385,7 @@ class ValidatorBuilder implements ValidatorBuilderInterface
$apiVersion = $this->apiVersion; $apiVersion = $this->apiVersion;
if (null === $apiVersion) { if (null === $apiVersion) {
$apiVersion = version_compare(PHP_VERSION, '5.3.9', '<') $apiVersion = PHP_VERSION_ID < 50309
? Validation::API_VERSION_2_4 ? Validation::API_VERSION_2_4
: Validation::API_VERSION_2_5_BC; : Validation::API_VERSION_2_5_BC;
} }