Merge branch '2.7' into 2.8
* 2.7: [FrameworkBundle] Fix visibility of a test helper [link] clear the cache after linking [link] Prevent warnings when running link with 2.7 [Validator] ExpressionValidator should use OBJECT_TO_STRING to allow value in message
This commit is contained in:
commit
874d418a8f
13
link
13
link
@ -35,11 +35,14 @@ if (!is_dir("$argv[1]/vendor/symfony")) {
|
||||
}
|
||||
|
||||
$sfPackages = array('symfony/symfony' => __DIR__);
|
||||
foreach (glob(__DIR__.'/src/Symfony/{Bundle,Bridge,Component,Component/Security}/*', GLOB_BRACE | GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
|
||||
$sfPackages[json_decode(file_get_contents("$dir/composer.json"))->name] = $dir;
|
||||
}
|
||||
|
||||
$filesystem = new Filesystem();
|
||||
foreach (glob(__DIR__.'/src/Symfony/{Bundle,Bridge,Component,Component/Security}/*', GLOB_BRACE | GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
|
||||
if ($filesystem->exists($composer = "$dir/composer.json")) {
|
||||
$sfPackages[json_decode(file_get_contents($composer))->name] = $dir;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (glob("$argv[1]/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
|
||||
$package = 'symfony/'.basename($dir);
|
||||
if (is_link($dir)) {
|
||||
@ -57,3 +60,7 @@ foreach (glob("$argv[1]/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir)
|
||||
$filesystem->symlink($sfDir, $dir);
|
||||
echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL;
|
||||
}
|
||||
|
||||
foreach (glob("$argv[1]/var/cache/*") as $cacheDir) {
|
||||
$filesystem->remove($cacheDir);
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ class RedirectControllerTest extends TestCase
|
||||
return $controller;
|
||||
}
|
||||
|
||||
public function assertRedirectUrl(Response $returnResponse, $expectedUrl)
|
||||
private function assertRedirectUrl(Response $returnResponse, $expectedUrl)
|
||||
{
|
||||
$this->assertTrue($returnResponse->isRedirect($expectedUrl), "Expected: $expectedUrl\nGot: ".$returnResponse->headers->get('Location'));
|
||||
}
|
||||
|
@ -72,12 +72,12 @@ class ExpressionValidator extends ConstraintValidator
|
||||
if (!$this->getExpressionLanguage()->evaluate($constraint->expression, $variables)) {
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING))
|
||||
->setCode(Expression::EXPRESSION_FAILED_ERROR)
|
||||
->addViolation();
|
||||
} else {
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $this->formatValue($value))
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING))
|
||||
->setCode(Expression::EXPRESSION_FAILED_ERROR)
|
||||
->addViolation();
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
use Symfony\Component\Validator\Constraints\Expression;
|
||||
use Symfony\Component\Validator\Constraints\ExpressionValidator;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\Entity;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ToString;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class ExpressionValidatorTest extends AbstractConstraintValidatorTest
|
||||
@ -93,6 +94,40 @@ class ExpressionValidatorTest extends AbstractConstraintValidatorTest
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testSucceedingExpressionAtObjectLevelWithToString()
|
||||
{
|
||||
$constraint = new Expression('this.data == 1');
|
||||
|
||||
$object = new ToString();
|
||||
$object->data = '1';
|
||||
|
||||
$this->setObject($object);
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testFailingExpressionAtObjectLevelWithToString()
|
||||
{
|
||||
$constraint = new Expression(array(
|
||||
'expression' => 'this.data == 1',
|
||||
'message' => 'myMessage',
|
||||
));
|
||||
|
||||
$object = new ToString();
|
||||
$object->data = '2';
|
||||
|
||||
$this->setObject($object);
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', 'toString')
|
||||
->setCode(Expression::EXPRESSION_FAILED_ERROR)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testSucceedingExpressionAtPropertyLevel()
|
||||
{
|
||||
$constraint = new Expression('value == this.data');
|
||||
|
22
src/Symfony/Component/Validator/Tests/Fixtures/ToString.php
Normal file
22
src/Symfony/Component/Validator/Tests/Fixtures/ToString.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Fixtures;
|
||||
|
||||
class ToString
|
||||
{
|
||||
public $data;
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return 'toString';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user