Skip to content

Commit 192aadb

Browse files
committed
minor #14228 Add PHP7 compatible versions for the Null/True/False constraints as they are reserved words in PHP7 (stefan.r)
This PR was merged into the 2.3 branch. Discussion ---------- Add PHP7 compatible versions for the Null/True/False constraints as they are reserved words in PHP7 | Q | A | ------------- | --- | Bug fix? | PHP7 compatibility | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | N/A | Fixed tickets | N/A - helps towards symfony/symfony#14086 | License | MIT Null, True and False are reserved words in PHP7: https://wiki.php.net/rfc/reserve_more_types_in_php_7 Commits ------- 44edbdf Fixed compatibility with PHP7 and up by introducing new constraints (IsNull, IsTrue, IsFalse) and related validators (IsNullValidator, IsTrueValidator, IsFalseValidator)
2 parents 9cd323e + 43979f7 commit 192aadb

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

Extension/Validator/ValidatorTypeGuesser.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ public function guessTypeForConstraint(Constraint $constraint)
157157

158158
case 'Symfony\Component\Validator\Constraints\True':
159159
case 'Symfony\Component\Validator\Constraints\False':
160+
case 'Symfony\Component\Validator\Constraints\IsTrue':
161+
case 'Symfony\Component\Validator\Constraints\IsFalse':
160162
return new TypeGuess('checkbox', array(), Guess::MEDIUM_CONFIDENCE);
161163
}
162164
}
@@ -174,6 +176,7 @@ public function guessRequiredForConstraint(Constraint $constraint)
174176
case 'Symfony\Component\Validator\Constraints\NotNull':
175177
case 'Symfony\Component\Validator\Constraints\NotBlank':
176178
case 'Symfony\Component\Validator\Constraints\True':
179+
case 'Symfony\Component\Validator\Constraints\IsTrue':
177180
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
178181
}
179182
}

Tests/Extension/Validator/ValidatorTypeGuesserTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Symfony\Component\Validator\Constraints\NotBlank;
2020
use Symfony\Component\Validator\Constraints\NotNull;
2121
use Symfony\Component\Validator\Constraints\Range;
22-
use Symfony\Component\Validator\Constraints\True;
22+
use Symfony\Component\Validator\Constraints\IsTrue;
2323
use Symfony\Component\Validator\Constraints\Type;
2424
use Symfony\Component\Validator\Mapping\ClassMetadata;
2525

@@ -64,7 +64,7 @@ public function guessRequiredProvider()
6464
return array(
6565
array(new NotNull(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
6666
array(new NotBlank(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
67-
array(new True(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
67+
array(new IsTrue(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
6868
array(new Length(10), new ValueGuess(false, Guess::LOW_CONFIDENCE)),
6969
array(new Range(array('min' => 1, 'max' => 20)), new ValueGuess(false, Guess::LOW_CONFIDENCE)),
7070
);
@@ -84,6 +84,18 @@ public function testGuessRequired($constraint, $guess)
8484
$this->assertEquals($guess, $this->guesser->guessRequired(self::TEST_CLASS, self::TEST_PROPERTY));
8585
}
8686

87+
/**
88+
* @group legacy
89+
*/
90+
public function testLegacyGuessRequired()
91+
{
92+
if (PHP_VERSION_ID >= 70000) {
93+
$this->markTestSkipped('Cannot use a class called True on PHP 7 or higher.');
94+
}
95+
$true = 'Symfony\Component\Validator\Constraints\True';
96+
$this->testGuessRequired(new $true(), new ValueGuess(true, Guess::HIGH_CONFIDENCE));
97+
}
98+
8799
public function testGuessRequiredReturnsFalseForUnmappedProperties()
88100
{
89101
$this->assertEquals(new ValueGuess(false, Guess::LOW_CONFIDENCE), $this->guesser->guessRequired(self::TEST_CLASS, self::TEST_PROPERTY));

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"require-dev": {
2626
"symfony/phpunit-bridge": "~2.7",
2727
"doctrine/collections": "~1.0",
28-
"symfony/validator": "~2.3.0,>=2.3.20",
28+
"symfony/validator": "~2.3.29",
2929
"symfony/translation": "~2.0,>=2.0.5",
3030
"symfony/http-foundation": "~2.2"
3131
},

0 commit comments

Comments
 (0)