Merge branch '2.4' into 2.5
* 2.4: [Form] Removed constructor argument from FormTypeHttpFoundationExtension for forward compatibility with 2.5 [Validator] Simplified testing of violations remove obsolete test file [FrameworkBundle] output failed matched path for clarification bug #10242 Missing checkPreAuth from RememberMeAuthenticationProvider [Validator] Fixed StaticMethodLoaderTest to actually test something [Form] Fixed ValidatorTypeGuesser to guess properties without constraints not to be required Use request format from request in twig ExceptionController fixed bug added the possibility to return null from SimplePreAuthenticationListener [Form] Moved POST_MAX_SIZE validation from FormValidator to request handler [Form] Add a form error if post_max_size has been reached. Response::isNotModified returns true when If-Modified-Since is later than Last-Modified [WebProfilerBundle] turbolinks compatibility Conflicts: src/Symfony/Component/Form/Extension/Core/Type/FormType.php src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php src/Symfony/Component/Security/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php
This commit is contained in:
commit
c48ae250ac
@ -165,7 +165,10 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($entity2, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(), 'property.path.name', 'Foo');
|
||||
$this->buildViolation('myMessage')
|
||||
->atPath('property.path.name')
|
||||
->setInvalidValue('Foo')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testValidateCustomErrorPath()
|
||||
@ -185,7 +188,10 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($entity2, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(), 'property.path.bar', 'Foo');
|
||||
$this->buildViolation('myMessage')
|
||||
->atPath('property.path.bar')
|
||||
->setInvalidValue('Foo')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testValidateUniquenessWithNull()
|
||||
@ -233,7 +239,10 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($entity2, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(), 'property.path.name', 'Foo');
|
||||
$this->buildViolation('myMessage')
|
||||
->atPath('property.path.name')
|
||||
->setInvalidValue('Foo')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testValidateUniquenessAfterConsideringMultipleQueryResults()
|
||||
@ -352,7 +361,10 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($associated2, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(), 'property.path.single', 1);
|
||||
$this->buildViolation('myMessage')
|
||||
->atPath('property.path.single')
|
||||
->setInvalidValue(1)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testAssociatedEntityWithNull()
|
||||
|
@ -107,7 +107,7 @@ EOF
|
||||
}
|
||||
|
||||
if (!$matches) {
|
||||
$output->writeln('<fg=red>None of the routes match</>');
|
||||
$output->writeln(sprintf('<fg=red>None of the routes match the path "%s"</>', $input->getArgument('path_info')));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
set_include_path('{include_path}');
|
||||
require_once 'PHPUnit/Autoload.php';
|
||||
ob_start();
|
||||
|
||||
function __phpunit_run_isolated_test()
|
||||
{
|
||||
if (!class_exists('{className}')) {
|
||||
require_once '{filename}';
|
||||
}
|
||||
|
||||
$result = new PHPUnit_Framework_TestResult;
|
||||
$result->collectRawCodeCoverageInformation({collectCodeCoverageInformation});
|
||||
|
||||
$test = new {className}('{methodName}', unserialize('{data}'), '{dataName}');
|
||||
$test->setDependencyInput(unserialize('{dependencyInput}'));
|
||||
$test->setInIsolation(TRUE);
|
||||
|
||||
ob_end_clean();
|
||||
ob_start();
|
||||
$test->run($result);
|
||||
$output = ob_get_clean();
|
||||
|
||||
print serialize(
|
||||
array(
|
||||
'testResult' => $test->getResult(),
|
||||
'numAssertions' => $test->getNumAssertions(),
|
||||
'result' => $result,
|
||||
'output' => $output
|
||||
)
|
||||
);
|
||||
|
||||
ob_start();
|
||||
}
|
||||
|
||||
{globals}
|
||||
|
||||
if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP'])) {
|
||||
require_once $GLOBALS['__PHPUNIT_BOOTSTRAP'];
|
||||
unset($GLOBALS['__PHPUNIT_BOOTSTRAP']);
|
||||
}
|
||||
|
||||
{constants}
|
||||
|
||||
__phpunit_run_isolated_test();
|
||||
ob_end_clean();
|
||||
?>
|
@ -39,20 +39,19 @@ class ExceptionController
|
||||
* @param Request $request The request
|
||||
* @param FlattenException $exception A FlattenException instance
|
||||
* @param DebugLoggerInterface $logger A DebugLoggerInterface instance
|
||||
* @param string $_format The format to use for rendering (html, xml, ...)
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @throws \InvalidArgumentException When the exception template does not exist
|
||||
*/
|
||||
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html')
|
||||
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
|
||||
{
|
||||
$currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
|
||||
|
||||
$code = $exception->getStatusCode();
|
||||
|
||||
return new Response($this->twig->render(
|
||||
$this->findTemplate($request, $_format, $code, $this->debug),
|
||||
$this->findTemplate($request, $request->getRequestFormat(), $code, $this->debug),
|
||||
array(
|
||||
'status_code' => $code,
|
||||
'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
|
||||
|
@ -1,6 +1,6 @@
|
||||
<!-- START of Symfony2 Web Debug Toolbar -->
|
||||
{% if 'normal' != position %}
|
||||
<div id="sfMiniToolbar-{{ token }}" class="sf-minitoolbar">
|
||||
<div id="sfMiniToolbar-{{ token }}" class="sf-minitoolbar" data-no-turbolink>
|
||||
<a href="javascript:void(0);" title="Show Symfony toolbar" onclick="
|
||||
var elem = this.parentNode;
|
||||
if (elem.style.display == 'none') {
|
||||
@ -24,7 +24,7 @@
|
||||
<div id="sfToolbarClearer-{{ token }}" style="clear: both; height: 38px;"></div>
|
||||
{% endif %}
|
||||
|
||||
<div id="sfToolbarMainContent-{{ token }}" class="sf-toolbarreset">
|
||||
<div id="sfToolbarMainContent-{{ token }}" class="sf-toolbarreset" data-no-turbolink>
|
||||
{% for name, template in templates %}
|
||||
{{ template.renderblock('toolbar', {
|
||||
'collector': profile.getcollector(name),
|
||||
|
@ -56,8 +56,7 @@ class FormType extends BaseType
|
||||
->setDataLocked($isDataOptionSet)
|
||||
->setDataMapper($options['compound'] ? new PropertyPathMapper($this->propertyAccessor) : null)
|
||||
->setMethod($options['method'])
|
||||
->setAction($options['action'])
|
||||
;
|
||||
->setAction($options['action']);
|
||||
|
||||
if ($options['trim']) {
|
||||
$builder->addEventSubscriber(new TrimListener());
|
||||
@ -207,6 +206,7 @@ class FormType extends BaseType
|
||||
// section 4.2., empty URIs are considered same-document references
|
||||
'action' => '',
|
||||
'attr' => $defaultAttr,
|
||||
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
|
||||
));
|
||||
|
||||
$resolver->setAllowedTypes(array(
|
||||
|
@ -12,8 +12,10 @@
|
||||
namespace Symfony\Component\Form\Extension\HttpFoundation;
|
||||
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\RequestHandlerInterface;
|
||||
use Symfony\Component\Form\Util\ServerParams;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
@ -24,6 +26,19 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
*/
|
||||
class HttpFoundationRequestHandler implements RequestHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var ServerParams
|
||||
*/
|
||||
private $serverParams;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(ServerParams $serverParams = null)
|
||||
{
|
||||
$this->serverParams = $serverParams ?: new ServerParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -53,6 +68,25 @@ class HttpFoundationRequestHandler implements RequestHandlerInterface
|
||||
$data = $request->query->get($name);
|
||||
}
|
||||
} else {
|
||||
// Mark the form with an error if the uploaded size was too large
|
||||
// This is done here and not in FormValidator because $_POST is
|
||||
// empty when that error occurs. Hence the form is never submitted.
|
||||
$contentLength = $this->serverParams->getContentLength();
|
||||
$maxContentLength = $this->serverParams->getPostMaxSize();
|
||||
|
||||
if (!empty($maxContentLength) && $contentLength > $maxContentLength) {
|
||||
// Submit the form, but don't clear the default values
|
||||
$form->submit(null, false);
|
||||
|
||||
$form->addError(new FormError(
|
||||
$form->getConfig()->getOption('post_max_size_message'),
|
||||
null,
|
||||
array('{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize())
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ('' === $name) {
|
||||
$params = $request->request->all();
|
||||
$files = $request->files->all();
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace Symfony\Component\Form\Extension\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\Extension\Validator\Util\ServerParams;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
@ -23,22 +22,6 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
*/
|
||||
class FormValidator extends ConstraintValidator
|
||||
{
|
||||
/**
|
||||
* @var ServerParams
|
||||
*/
|
||||
private $serverParams;
|
||||
|
||||
/**
|
||||
* Creates a validator with the given server parameters.
|
||||
*
|
||||
* @param ServerParams $params The server parameters. Default
|
||||
* parameters are created if null.
|
||||
*/
|
||||
public function __construct(ServerParams $params = null)
|
||||
{
|
||||
$this->serverParams = $params ?: new ServerParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -151,29 +134,6 @@ class FormValidator extends ConstraintValidator
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Mark the form with an error if the uploaded size was too large
|
||||
$length = $this->serverParams->getContentLength();
|
||||
|
||||
if ($form->isRoot() && null !== $length) {
|
||||
$max = $this->serverParams->getPostMaxSize();
|
||||
|
||||
if (!empty($max) && $length > $max) {
|
||||
if ($this->context instanceof ExecutionContextInterface) {
|
||||
$this->context->buildViolation($config->getOption('post_max_size_message'))
|
||||
->setParameter('{{ max }}', $this->serverParams->getNormalizedIniPostMaxSize())
|
||||
->setInvalidValue($length)
|
||||
->addViolation();
|
||||
} else {
|
||||
// 2.4 API
|
||||
$this->context->addViolation(
|
||||
$config->getOption('post_max_size_message'),
|
||||
array('{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize()),
|
||||
$length
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,7 +74,6 @@ class FormTypeValidatorExtension extends BaseValidatorExtension
|
||||
'invalid_message' => 'This value is not valid.',
|
||||
'invalid_message_parameters' => array(),
|
||||
'extra_fields_message' => 'This form should not contain extra fields.',
|
||||
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
|
||||
));
|
||||
|
||||
$resolver->setNormalizers(array(
|
||||
|
@ -11,75 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Form\Extension\Validator\Util;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class ServerParams
|
||||
class ServerParams extends \Symfony\Component\Form\Util\ServerParams
|
||||
{
|
||||
private $requestStack;
|
||||
|
||||
public function __construct(RequestStack $requestStack = null)
|
||||
{
|
||||
$this->requestStack = $requestStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns maximum post size in bytes.
|
||||
*
|
||||
* @return null|int The maximum post size in bytes
|
||||
*/
|
||||
public function getPostMaxSize()
|
||||
{
|
||||
$iniMax = strtolower($this->getNormalizedIniPostMaxSize());
|
||||
|
||||
if ('' === $iniMax) {
|
||||
return;
|
||||
}
|
||||
|
||||
$max = ltrim($iniMax, '+');
|
||||
if (0 === strpos($max, '0x')) {
|
||||
$max = intval($max, 16);
|
||||
} elseif (0 === strpos($max, '0')) {
|
||||
$max = intval($max, 8);
|
||||
} else {
|
||||
$max = intval($max);
|
||||
}
|
||||
|
||||
switch (substr($iniMax, -1)) {
|
||||
case 't': $max *= 1024;
|
||||
case 'g': $max *= 1024;
|
||||
case 'm': $max *= 1024;
|
||||
case 'k': $max *= 1024;
|
||||
}
|
||||
|
||||
return $max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the normalized "post_max_size" ini setting.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNormalizedIniPostMaxSize()
|
||||
{
|
||||
return strtoupper(trim(ini_get('post_max_size')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content length of the request.
|
||||
*
|
||||
* @return mixed The request content length.
|
||||
*/
|
||||
public function getContentLength()
|
||||
{
|
||||
if (null !== $this->requestStack && null !== $request = $this->requestStack->getCurrentRequest()) {
|
||||
return $request->server->get('CONTENT_LENGTH');
|
||||
}
|
||||
|
||||
return isset($_SERVER['CONTENT_LENGTH'])
|
||||
? (int) $_SERVER['CONTENT_LENGTH']
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
@ -276,11 +276,11 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $defaultValue) {
|
||||
$guesses[] = new ValueGuess($defaultValue, Guess::LOW_CONFIDENCE);
|
||||
}
|
||||
}
|
||||
|
||||
return Guess::getBestGuess($guesses);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\Util\ServerParams;
|
||||
|
||||
/**
|
||||
* A request handler using PHP's super globals $_GET, $_POST and $_SERVER.
|
||||
@ -20,6 +21,19 @@ use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
*/
|
||||
class NativeRequestHandler implements RequestHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var ServerParams
|
||||
*/
|
||||
private $serverParams;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(ServerParams $params = null)
|
||||
{
|
||||
$this->serverParams = $params ?: new ServerParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* The allowed keys of the $_FILES array.
|
||||
*
|
||||
@ -62,6 +76,25 @@ class NativeRequestHandler implements RequestHandlerInterface
|
||||
$data = $_GET[$name];
|
||||
}
|
||||
} else {
|
||||
// Mark the form with an error if the uploaded size was too large
|
||||
// This is done here and not in FormValidator because $_POST is
|
||||
// empty when that error occurs. Hence the form is never submitted.
|
||||
$contentLength = $this->serverParams->getContentLength();
|
||||
$maxContentLength = $this->serverParams->getPostMaxSize();
|
||||
|
||||
if (!empty($maxContentLength) && $contentLength > $maxContentLength) {
|
||||
// Submit the form, but don't clear the default values
|
||||
$form->submit(null, false);
|
||||
|
||||
$form->addError(new FormError(
|
||||
$form->getConfig()->getOption('post_max_size_message'),
|
||||
null,
|
||||
array('{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize())
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fixedFiles = array();
|
||||
foreach ($_FILES as $name => $file) {
|
||||
$fixedFiles[$name] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
|
||||
|
@ -11,21 +11,38 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests;
|
||||
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\FormFactory;
|
||||
use Symfony\Component\Form\Forms;
|
||||
use Symfony\Component\Form\RequestHandlerInterface;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
abstract class AbstractRequestHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\Form\RequestHandlerInterface
|
||||
* @var RequestHandlerInterface
|
||||
*/
|
||||
protected $requestHandler;
|
||||
|
||||
/**
|
||||
* @var FormFactory
|
||||
*/
|
||||
protected $factory;
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $serverParams;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->serverParams = $this->getMock(
|
||||
'Symfony\Component\Form\Util\ServerParams',
|
||||
array('getNormalizedIniPostMaxSize', 'getContentLength')
|
||||
);
|
||||
$this->requestHandler = $this->getRequestHandler();
|
||||
$this->factory = Forms::createFormFactoryBuilder()->getFormFactory();
|
||||
$this->request = null;
|
||||
}
|
||||
|
||||
@ -249,6 +266,50 @@ abstract class AbstractRequestHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->requestHandler->handleRequest($form, $this->request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPostMaxSizeFixtures
|
||||
*/
|
||||
public function testAddFormErrorIfPostMaxSizeExceeded($contentLength, $iniMax, $shouldFail, array $errorParams = array())
|
||||
{
|
||||
$this->serverParams->expects($this->once())
|
||||
->method('getContentLength')
|
||||
->will($this->returnValue($contentLength));
|
||||
$this->serverParams->expects($this->any())
|
||||
->method('getNormalizedIniPostMaxSize')
|
||||
->will($this->returnValue($iniMax));
|
||||
|
||||
$options = array('post_max_size_message' => 'Max {{ max }}!');
|
||||
$form = $this->factory->createNamed('name', 'text', null, $options);
|
||||
$this->setRequestData('POST', array(), array());
|
||||
|
||||
$this->requestHandler->handleRequest($form, $this->request);
|
||||
|
||||
if ($shouldFail) {
|
||||
$errors = array(new FormError($options['post_max_size_message'], null, $errorParams));
|
||||
|
||||
$this->assertEquals($errors, iterator_to_array($form->getErrors()));
|
||||
$this->assertTrue($form->isSubmitted());
|
||||
} else {
|
||||
$this->assertCount(0, $form->getErrors());
|
||||
$this->assertFalse($form->isSubmitted());
|
||||
}
|
||||
}
|
||||
|
||||
public function getPostMaxSizeFixtures()
|
||||
{
|
||||
return array(
|
||||
array(pow(1024, 3) + 1, '1G', true, array('{{ max }}' => '1G')),
|
||||
array(pow(1024, 3), '1G', false),
|
||||
array(pow(1024, 2) + 1, '1M', true, array('{{ max }}' => '1M')),
|
||||
array(pow(1024, 2), '1M', false),
|
||||
array(1024 + 1, '1K', true, array('{{ max }}' => '1K')),
|
||||
array(1024, '1K', false),
|
||||
array(null, '1K', false),
|
||||
array(1024, '', false),
|
||||
array(1024, 0, false),
|
||||
);
|
||||
}
|
||||
|
||||
abstract protected function setRequestData($method, $data, $files = array());
|
||||
|
||||
abstract protected function getRequestHandler();
|
||||
|
@ -43,7 +43,7 @@ class HttpFoundationRequestHandlerTest extends AbstractRequestHandlerTest
|
||||
|
||||
protected function getRequestHandler()
|
||||
{
|
||||
return new HttpFoundationRequestHandler();
|
||||
return new HttpFoundationRequestHandler($this->serverParams);
|
||||
}
|
||||
|
||||
protected function getMockFile()
|
||||
|
@ -225,10 +225,12 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($form, new Form());
|
||||
|
||||
$this->assertViolation('invalid_message_key', array(
|
||||
'{{ value }}' => 'foo',
|
||||
'{{ foo }}' => 'bar',
|
||||
), 'property.path', 'foo', null, Form::ERR_INVALID);
|
||||
$this->buildViolation('invalid_message_key')
|
||||
->setParameter('{{ value }}', 'foo')
|
||||
->setParameter('{{ foo }}', 'bar')
|
||||
->setInvalidValue('foo')
|
||||
->setCode(Form::ERR_INVALID)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testAddInvalidErrorEvenIfNoValidationGroups()
|
||||
@ -257,10 +259,12 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($form, new Form());
|
||||
|
||||
$this->assertViolation('invalid_message_key', array(
|
||||
'{{ value }}' => 'foo',
|
||||
'{{ foo }}' => 'bar',
|
||||
), 'property.path', 'foo', null, Form::ERR_INVALID);
|
||||
$this->buildViolation('invalid_message_key')
|
||||
->setParameter('{{ value }}', 'foo')
|
||||
->setParameter('{{ foo }}', 'bar')
|
||||
->setInvalidValue('foo')
|
||||
->setCode(Form::ERR_INVALID)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testDontValidateConstraintsIfNotSynchronized()
|
||||
@ -289,9 +293,11 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($form, new Form());
|
||||
|
||||
$this->assertViolation('invalid_message_key', array(
|
||||
'{{ value }}' => 'foo',
|
||||
), 'property.path','foo', null, Form::ERR_INVALID);
|
||||
$this->buildViolation('invalid_message_key')
|
||||
->setParameter('{{ value }}', 'foo')
|
||||
->setInvalidValue('foo')
|
||||
->setCode(Form::ERR_INVALID)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
// https://github.com/symfony/symfony/issues/4359
|
||||
@ -543,72 +549,10 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($form, new Form());
|
||||
|
||||
$this->assertViolation('Extra!', array(
|
||||
'{{ extra_fields }}' => 'foo',
|
||||
), 'property.path', array('foo' => 'bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPostMaxSizeFixtures
|
||||
*/
|
||||
public function testPostMaxSizeViolation($contentLength, $iniMax, $nbViolation, array $params = array())
|
||||
{
|
||||
$this->serverParams->expects($this->once())
|
||||
->method('getContentLength')
|
||||
->will($this->returnValue($contentLength));
|
||||
$this->serverParams->expects($this->any())
|
||||
->method('getNormalizedIniPostMaxSize')
|
||||
->will($this->returnValue($iniMax));
|
||||
|
||||
$options = array('post_max_size_message' => 'Max {{ max }}!');
|
||||
$form = $this->getBuilder('name', null, $options)->getForm();
|
||||
|
||||
$this->validator->validate($form, new Form());
|
||||
|
||||
$violations = array();
|
||||
|
||||
for ($i = 0; $i < $nbViolation; ++$i) {
|
||||
$violations[] = $this->createViolation($options['post_max_size_message'], $params, 'property.path', $contentLength);
|
||||
}
|
||||
|
||||
$this->assertViolations($violations);
|
||||
}
|
||||
|
||||
public function getPostMaxSizeFixtures()
|
||||
{
|
||||
return array(
|
||||
array(pow(1024, 3) + 1, '1G', 1, array('{{ max }}' => '1G')),
|
||||
array(pow(1024, 3), '1G', 0),
|
||||
array(pow(1024, 2) + 1, '1M', 1, array('{{ max }}' => '1M')),
|
||||
array(pow(1024, 2), '1M', 0),
|
||||
array(1024 + 1, '1K', 1, array('{{ max }}' => '1K')),
|
||||
array(1024, '1K', 0),
|
||||
array(null, '1K', 0),
|
||||
array(1024, '', 0),
|
||||
array(1024, 0, 0),
|
||||
);
|
||||
}
|
||||
|
||||
public function testNoViolationIfNotRoot()
|
||||
{
|
||||
$this->serverParams->expects($this->once())
|
||||
->method('getContentLength')
|
||||
->will($this->returnValue(1025));
|
||||
$this->serverParams->expects($this->never())
|
||||
->method('getNormalizedIniPostMaxSize');
|
||||
|
||||
$parent = $this->getBuilder()
|
||||
->setCompound(true)
|
||||
->setDataMapper($this->getDataMapper())
|
||||
->getForm();
|
||||
$form = $this->getForm();
|
||||
$parent->add($form);
|
||||
|
||||
$this->expectNoValidate();
|
||||
|
||||
$this->validator->validate($form, new Form());
|
||||
|
||||
$this->assertNoViolation();
|
||||
$this->buildViolation('Extra!')
|
||||
->setParameter('{{ extra_fields }}', 'foo')
|
||||
->setInvalidValue(array('foo' => 'bar'))
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,32 +13,91 @@ namespace Symfony\Component\Form\Tests\Extension\Validator;
|
||||
|
||||
use Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser;
|
||||
use Symfony\Component\Form\Guess\Guess;
|
||||
use Symfony\Component\Form\Guess\ValueGuess;
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
use Symfony\Component\Validator\Constraints\Range;
|
||||
use Symfony\Component\Validator\Constraints\True;
|
||||
use Symfony\Component\Validator\Constraints\Type;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
|
||||
/**
|
||||
* @author franek <franek@chicour.net>
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class ValidatorTypeGuesserTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $typeGuesser;
|
||||
const TEST_CLASS = 'Symfony\Component\Form\Tests\Extension\Validator\ValidatorTypeGuesserTest_TestClass';
|
||||
|
||||
public function setUp()
|
||||
const TEST_PROPERTY = 'property';
|
||||
|
||||
/**
|
||||
* @var ValidatorTypeGuesser
|
||||
*/
|
||||
private $guesser;
|
||||
|
||||
/**
|
||||
* @var ClassMetadata
|
||||
*/
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $metadataFactory;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Validator\Constraint')) {
|
||||
$this->markTestSkipped('The "Validator" component is not available');
|
||||
}
|
||||
|
||||
$metadataFactory = $this->getMock('Symfony\Component\Validator\MetadataFactoryInterface');
|
||||
$this->metadata = new ClassMetadata(self::TEST_CLASS);
|
||||
$this->metadataFactory = $this->getMock('Symfony\Component\Validator\MetadataFactoryInterface');
|
||||
$this->metadataFactory->expects($this->any())
|
||||
->method('getMetadataFor')
|
||||
->with(self::TEST_CLASS)
|
||||
->will($this->returnValue($this->metadata));
|
||||
$this->guesser = new ValidatorTypeGuesser($this->metadataFactory);
|
||||
}
|
||||
|
||||
$this->typeGuesser = new ValidatorTypeGuesser($metadataFactory);
|
||||
public function guessRequiredProvider()
|
||||
{
|
||||
return array(
|
||||
array(new NotNull(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
|
||||
array(new NotBlank(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
|
||||
array(new True(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
|
||||
array(new Length(10), new ValueGuess(false, Guess::LOW_CONFIDENCE)),
|
||||
array(new Range(array('min' => 1, 'max' => 20)), new ValueGuess(false, Guess::LOW_CONFIDENCE)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider guessRequiredProvider
|
||||
*/
|
||||
public function testGuessRequired($constraint, $guess)
|
||||
{
|
||||
// add distracting constraint
|
||||
$this->metadata->addPropertyConstraint(self::TEST_PROPERTY, new Email());
|
||||
|
||||
// add constraint under test
|
||||
$this->metadata->addPropertyConstraint(self::TEST_PROPERTY, $constraint);
|
||||
|
||||
$this->assertEquals($guess, $this->guesser->guessRequired(self::TEST_CLASS, self::TEST_PROPERTY));
|
||||
}
|
||||
|
||||
public function testGuessRequiredReturnsFalseForUnmappedProperties()
|
||||
{
|
||||
$this->assertEquals(new ValueGuess(false, Guess::LOW_CONFIDENCE), $this->guesser->guessRequired(self::TEST_CLASS, self::TEST_PROPERTY));
|
||||
}
|
||||
|
||||
public function testGuessMaxLengthForConstraintWithMaxValue()
|
||||
{
|
||||
$constraint = new Length(array('max' => '2'));
|
||||
|
||||
$result = $this->typeGuesser->guessMaxLengthForConstraint($constraint);
|
||||
$result = $this->guesser->guessMaxLengthForConstraint($constraint);
|
||||
$this->assertInstanceOf('Symfony\Component\Form\Guess\ValueGuess', $result);
|
||||
$this->assertEquals(2, $result->getValue());
|
||||
$this->assertEquals(Guess::HIGH_CONFIDENCE, $result->getConfidence());
|
||||
@ -48,24 +107,11 @@ class ValidatorTypeGuesserTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$constraint = new Length(array('min' => '2'));
|
||||
|
||||
$result = $this->typeGuesser->guessMaxLengthForConstraint($constraint);
|
||||
$result = $this->guesser->guessMaxLengthForConstraint($constraint);
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderTestGuessMaxLengthForConstraintWithType
|
||||
*/
|
||||
public function testGuessMaxLengthForConstraintWithType($type)
|
||||
{
|
||||
$constraint = new Type($type);
|
||||
|
||||
$result = $this->typeGuesser->guessMaxLengthForConstraint($constraint);
|
||||
$this->assertInstanceOf('Symfony\Component\Form\Guess\ValueGuess', $result);
|
||||
$this->assertEquals(null, $result->getValue());
|
||||
$this->assertEquals(Guess::MEDIUM_CONFIDENCE, $result->getConfidence());
|
||||
}
|
||||
|
||||
public static function dataProviderTestGuessMaxLengthForConstraintWithType()
|
||||
public function maxLengthTypeProvider()
|
||||
{
|
||||
return array (
|
||||
array('double'),
|
||||
@ -74,4 +120,22 @@ class ValidatorTypeGuesserTest extends \PHPUnit_Framework_TestCase
|
||||
array('real'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider maxLengthTypeProvider
|
||||
*/
|
||||
public function testGuessMaxLengthForConstraintWithType($type)
|
||||
{
|
||||
$constraint = new Type($type);
|
||||
|
||||
$result = $this->guesser->guessMaxLengthForConstraint($constraint);
|
||||
$this->assertInstanceOf('Symfony\Component\Form\Guess\ValueGuess', $result);
|
||||
$this->assertNull($result->getValue());
|
||||
$this->assertEquals(Guess::MEDIUM_CONFIDENCE, $result->getConfidence());
|
||||
}
|
||||
}
|
||||
|
||||
class ValidatorTypeGuesserTest_TestClass
|
||||
{
|
||||
private $property;
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ class NativeRequestHandlerTest extends AbstractRequestHandlerTest
|
||||
|
||||
protected function getRequestHandler()
|
||||
{
|
||||
return new NativeRequestHandler();
|
||||
return new NativeRequestHandler($this->serverParams);
|
||||
}
|
||||
|
||||
protected function getMockFile()
|
||||
|
85
src/Symfony/Component/Form/Util/ServerParams.php
Normal file
85
src/Symfony/Component/Form/Util/ServerParams.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?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\Form\Util;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class ServerParams
|
||||
{
|
||||
private $requestStack;
|
||||
|
||||
public function __construct(RequestStack $requestStack = null)
|
||||
{
|
||||
$this->requestStack = $requestStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns maximum post size in bytes.
|
||||
*
|
||||
* @return null|int The maximum post size in bytes
|
||||
*/
|
||||
public function getPostMaxSize()
|
||||
{
|
||||
$iniMax = strtolower($this->getNormalizedIniPostMaxSize());
|
||||
|
||||
if ('' === $iniMax) {
|
||||
return;
|
||||
}
|
||||
|
||||
$max = ltrim($iniMax, '+');
|
||||
if (0 === strpos($max, '0x')) {
|
||||
$max = intval($max, 16);
|
||||
} elseif (0 === strpos($max, '0')) {
|
||||
$max = intval($max, 8);
|
||||
} else {
|
||||
$max = intval($max);
|
||||
}
|
||||
|
||||
switch (substr($iniMax, -1)) {
|
||||
case 't': $max *= 1024;
|
||||
case 'g': $max *= 1024;
|
||||
case 'm': $max *= 1024;
|
||||
case 'k': $max *= 1024;
|
||||
}
|
||||
|
||||
return $max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the normalized "post_max_size" ini setting.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNormalizedIniPostMaxSize()
|
||||
{
|
||||
return strtoupper(trim(ini_get('post_max_size')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content length of the request.
|
||||
*
|
||||
* @return mixed The request content length.
|
||||
*/
|
||||
public function getContentLength()
|
||||
{
|
||||
if (null !== $this->requestStack && null !== $request = $this->requestStack->getCurrentRequest()) {
|
||||
return $request->server->get('CONTENT_LENGTH');
|
||||
}
|
||||
|
||||
return isset($_SERVER['CONTENT_LENGTH'])
|
||||
? (int) $_SERVER['CONTENT_LENGTH']
|
||||
: null;
|
||||
}
|
||||
}
|
@ -1077,12 +1077,16 @@ class Response
|
||||
return false;
|
||||
}
|
||||
|
||||
$lastModified = $request->headers->get('If-Modified-Since');
|
||||
$notModified = false;
|
||||
$lastModified = $this->headers->get('Last-Modified');
|
||||
$modifiedSince = $request->headers->get('If-Modified-Since');
|
||||
|
||||
if ($etags = $request->getEtags()) {
|
||||
$notModified = (in_array($this->getEtag(), $etags) || in_array('*', $etags)) && (!$lastModified || $this->headers->get('Last-Modified') == $lastModified);
|
||||
} elseif ($lastModified) {
|
||||
$notModified = $lastModified == $this->headers->get('Last-Modified');
|
||||
$notModified = in_array($this->getEtag(), $etags) || in_array('*', $etags);
|
||||
}
|
||||
|
||||
if ($modifiedSince && $lastModified) {
|
||||
$notModified = strtotime($modifiedSince) >= strtotime($lastModified) && (!$etags || $notModified);
|
||||
}
|
||||
|
||||
if ($notModified) {
|
||||
|
@ -141,16 +141,24 @@ class ResponseTest extends ResponseTestCase
|
||||
|
||||
public function testIsNotModifiedLastModified()
|
||||
{
|
||||
$before = 'Sun, 25 Aug 2013 18:32:31 GMT';
|
||||
$modified = 'Sun, 25 Aug 2013 18:33:31 GMT';
|
||||
$after = 'Sun, 25 Aug 2013 19:33:31 GMT';
|
||||
|
||||
$request = new Request();
|
||||
$request->headers->set('If-Modified-Since', $modified);
|
||||
|
||||
$response = new Response();
|
||||
$response->headers->set('Last-Modified', $modified);
|
||||
|
||||
$response->headers->set('Last-Modified', $modified);
|
||||
$this->assertTrue($response->isNotModified($request));
|
||||
|
||||
$response->headers->set('Last-Modified', $before);
|
||||
$this->assertTrue($response->isNotModified($request));
|
||||
|
||||
$response->headers->set('Last-Modified', $after);
|
||||
$this->assertFalse($response->isNotModified($request));
|
||||
|
||||
$response->headers->set('Last-Modified', '');
|
||||
$this->assertFalse($response->isNotModified($request));
|
||||
}
|
||||
@ -175,6 +183,50 @@ class ResponseTest extends ResponseTestCase
|
||||
$this->assertFalse($response->isNotModified($request));
|
||||
}
|
||||
|
||||
public function testIsNotModifiedLastModifiedAndEtag()
|
||||
{
|
||||
$before = 'Sun, 25 Aug 2013 18:32:31 GMT';
|
||||
$modified = 'Sun, 25 Aug 2013 18:33:31 GMT';
|
||||
$after = 'Sun, 25 Aug 2013 19:33:31 GMT';
|
||||
$etag = 'randomly_generated_etag';
|
||||
|
||||
$request = new Request();
|
||||
$request->headers->set('if_none_match', sprintf('%s, %s', $etag, 'etagThree'));
|
||||
$request->headers->set('If-Modified-Since', $modified);
|
||||
|
||||
$response = new Response();
|
||||
|
||||
$response->headers->set('ETag', $etag);
|
||||
$response->headers->set('Last-Modified', $after);
|
||||
$this->assertFalse($response->isNotModified($request));
|
||||
|
||||
$response->headers->set('ETag', 'non-existent-etag');
|
||||
$response->headers->set('Last-Modified', $before);
|
||||
$this->assertFalse($response->isNotModified($request));
|
||||
|
||||
$response->headers->set('ETag', $etag);
|
||||
$response->headers->set('Last-Modified', $modified);
|
||||
$this->assertTrue($response->isNotModified($request));
|
||||
}
|
||||
|
||||
public function testIsNotModifiedIfModifiedSinceAndEtagWithoutLastModified()
|
||||
{
|
||||
$modified = 'Sun, 25 Aug 2013 18:33:31 GMT';
|
||||
$etag = 'randomly_generated_etag';
|
||||
|
||||
$request = new Request();
|
||||
$request->headers->set('if_none_match', sprintf('%s, %s', $etag, 'etagThree'));
|
||||
$request->headers->set('If-Modified-Since', $modified);
|
||||
|
||||
$response = new Response();
|
||||
|
||||
$response->headers->set('ETag', $etag);
|
||||
$this->assertTrue($response->isNotModified($request));
|
||||
|
||||
$response->headers->set('ETag', 'non-existent-etag');
|
||||
$this->assertFalse($response->isNotModified($request));
|
||||
}
|
||||
|
||||
public function testIsValidateable()
|
||||
{
|
||||
$response = new Response('', 200, array('Last-Modified' => $this->createDateTimeOneHourAgo()->format(DATE_RFC2822)));
|
||||
|
@ -50,7 +50,7 @@ class RememberMeAuthenticationProvider implements AuthenticationProviderInterfac
|
||||
}
|
||||
|
||||
$user = $token->getUser();
|
||||
$this->userChecker->checkPostAuth($user);
|
||||
$this->userChecker->checkPreAuth($user);
|
||||
|
||||
$authenticatedToken = new RememberMeToken($user, $this->providerKey, $this->key);
|
||||
$authenticatedToken->setAttributes($token->getAttributes());
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
|
||||
|
||||
use Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider;
|
||||
use Symfony\Component\Security\Core\Exception\AccountExpiredException;
|
||||
use Symfony\Component\Security\Core\Exception\DisabledException;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
|
||||
@ -45,15 +45,14 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Security\Core\Exception\AccountExpiredException
|
||||
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
|
||||
*/
|
||||
public function testAuthenticateWhenPostChecksFails()
|
||||
public function testAuthenticateWhenPreChecksFails()
|
||||
{
|
||||
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
|
||||
$userChecker->expects($this->once())
|
||||
->method('checkPostAuth')
|
||||
->will($this->throwException(new AccountExpiredException()))
|
||||
;
|
||||
->method('checkPreAuth')
|
||||
->will($this->throwException(new DisabledException()));
|
||||
|
||||
$provider = $this->getProvider($userChecker);
|
||||
|
||||
@ -65,8 +64,7 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
|
||||
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
|
||||
$user->expects($this->exactly(2))
|
||||
->method('getRoles')
|
||||
->will($this->returnValue(array('ROLE_FOO')))
|
||||
;
|
||||
->will($this->returnValue(array('ROLE_FOO')));
|
||||
|
||||
$provider = $this->getProvider();
|
||||
|
||||
@ -86,16 +84,14 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
|
||||
$user
|
||||
->expects($this->any())
|
||||
->method('getRoles')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
->will($this->returnValue(array()));
|
||||
}
|
||||
|
||||
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', array('getProviderKey'), array($user, 'foo', $key));
|
||||
$token
|
||||
->expects($this->once())
|
||||
->method('getProviderKey')
|
||||
->will($this->returnValue('foo'))
|
||||
;
|
||||
->will($this->returnValue('foo'));
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
@ -76,6 +76,12 @@ class SimplePreAuthenticationListener implements ListenerInterface
|
||||
|
||||
try {
|
||||
$token = $this->simpleAuthenticator->createToken($request, $this->providerKey);
|
||||
|
||||
// allow null to be returned to skip authentication
|
||||
if (null === $token) {
|
||||
return;
|
||||
}
|
||||
|
||||
$token = $this->authenticationManager->authenticate($token);
|
||||
$this->securityContext->setToken($token);
|
||||
} catch (AuthenticationException $e) {
|
||||
|
@ -84,11 +84,11 @@ abstract class AbstractComparisonValidatorTestCase extends AbstractConstraintVal
|
||||
|
||||
$this->validator->validate($dirtyValue, $constraint);
|
||||
|
||||
$this->assertViolation('Constraint Message', array(
|
||||
'{{ value }}' => $dirtyValueAsString,
|
||||
'{{ compared_value }}' => $comparedValueString,
|
||||
'{{ compared_value_type }}' => $comparedValueType,
|
||||
));
|
||||
$this->buildViolation('Constraint Message')
|
||||
->setParameter('{{ value }}', $dirtyValueAsString)
|
||||
->setParameter('{{ compared_value }}', $comparedValueString)
|
||||
->setParameter('{{ compared_value_type }}', $comparedValueType)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Component\Validator\ConstraintViolation;
|
||||
use Symfony\Component\Validator\Context\ExecutionContext;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Context\LegacyExecutionContext;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface as LegacyExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Mapping\PropertyMetadata;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\StubGlobalExecutionContext;
|
||||
@ -117,6 +118,19 @@ abstract class AbstractConstraintValidatorTest extends \PHPUnit_Framework_TestCa
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
* @param array $parameters
|
||||
* @param string $propertyPath
|
||||
* @param string $invalidValue
|
||||
* @param null $plural
|
||||
* @param null $code
|
||||
*
|
||||
* @return ConstraintViolation
|
||||
*
|
||||
* @deprecated To be removed in Symfony 3.0. Use
|
||||
* {@link buildViolation()} instead.
|
||||
*/
|
||||
protected function createViolation($message, array $parameters = array(), $propertyPath = 'property.path', $invalidValue = 'InvalidValue', $plural = null, $code = null)
|
||||
{
|
||||
return new ConstraintViolation(
|
||||
@ -293,14 +307,34 @@ abstract class AbstractConstraintValidatorTest extends \PHPUnit_Framework_TestCa
|
||||
$this->assertCount(0, $this->context->getViolations());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
* @param array $parameters
|
||||
* @param string $propertyPath
|
||||
* @param string $invalidValue
|
||||
* @param null $plural
|
||||
* @param null $code
|
||||
*
|
||||
* @deprecated To be removed in Symfony 3.0. Use
|
||||
* {@link buildViolation()} instead.
|
||||
*/
|
||||
protected function assertViolation($message, array $parameters = array(), $propertyPath = 'property.path', $invalidValue = 'InvalidValue', $plural = null, $code = null)
|
||||
{
|
||||
$violations = $this->context->getViolations();
|
||||
|
||||
$this->assertCount(1, $violations);
|
||||
$this->assertEquals($this->createViolation($message, $parameters, $propertyPath, $invalidValue, $plural, $code), current(iterator_to_array($violations)));
|
||||
$this->buildViolation($message)
|
||||
->setParameters($parameters)
|
||||
->atPath($propertyPath)
|
||||
->setInvalidValue($invalidValue)
|
||||
->setCode($code)
|
||||
->setPlural($plural)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $expected
|
||||
*
|
||||
* @deprecated To be removed in Symfony 3.0. Use
|
||||
* {@link buildViolation()} instead.
|
||||
*/
|
||||
protected function assertViolations(array $expected)
|
||||
{
|
||||
$violations = $this->context->getViolations();
|
||||
@ -314,7 +348,139 @@ abstract class AbstractConstraintValidatorTest extends \PHPUnit_Framework_TestCa
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
*
|
||||
* @return ConstraintViolationAssertion
|
||||
*/
|
||||
protected function buildViolation($message)
|
||||
{
|
||||
return new ConstraintViolationAssertion($this->context, $message);
|
||||
}
|
||||
|
||||
abstract protected function getApiVersion();
|
||||
|
||||
abstract protected function createValidator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class ConstraintViolationAssertion
|
||||
{
|
||||
/**
|
||||
* @var LegacyExecutionContextInterface
|
||||
*/
|
||||
private $context;
|
||||
|
||||
/**
|
||||
* @var ConstraintViolationAssertion[]
|
||||
*/
|
||||
private $assertions;
|
||||
|
||||
private $message;
|
||||
private $parameters = array();
|
||||
private $invalidValue = 'InvalidValue';
|
||||
private $propertyPath = 'property.path';
|
||||
private $translationDomain;
|
||||
private $plural;
|
||||
private $code;
|
||||
|
||||
public function __construct(LegacyExecutionContextInterface $context, $message, array $assertions = array())
|
||||
{
|
||||
$this->context = $context;
|
||||
$this->message = $message;
|
||||
$this->assertions = $assertions;
|
||||
}
|
||||
|
||||
public function atPath($path)
|
||||
{
|
||||
$this->propertyPath = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setParameter($key, $value)
|
||||
{
|
||||
$this->parameters[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setParameters(array $parameters)
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTranslationDomain($translationDomain)
|
||||
{
|
||||
$this->translationDomain = $translationDomain;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setInvalidValue($invalidValue)
|
||||
{
|
||||
$this->invalidValue = $invalidValue;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPlural($number)
|
||||
{
|
||||
$this->plural = $number;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function buildNextViolation($message)
|
||||
{
|
||||
$assertions = $this->assertions;
|
||||
$assertions[] = $this;
|
||||
|
||||
return new self($this->context, $message, $assertions);
|
||||
}
|
||||
|
||||
public function assertRaised()
|
||||
{
|
||||
$expected = array();
|
||||
foreach ($this->assertions as $assertion) {
|
||||
$expected[] = $assertion->getViolation();
|
||||
}
|
||||
$expected[] = $this->getViolation();
|
||||
|
||||
$violations = iterator_to_array($this->context->getViolations());
|
||||
|
||||
\PHPUnit_Framework_Assert::assertCount(count($expected), $violations);
|
||||
|
||||
reset($violations);
|
||||
|
||||
foreach ($expected as $violation) {
|
||||
\PHPUnit_Framework_Assert::assertEquals($violation, current($violations));
|
||||
next($violations);
|
||||
}
|
||||
}
|
||||
|
||||
private function getViolation()
|
||||
{
|
||||
return new ConstraintViolation(
|
||||
null,
|
||||
$this->message,
|
||||
$this->parameters,
|
||||
$this->context->getRoot(),
|
||||
$this->propertyPath,
|
||||
$this->invalidValue,
|
||||
$this->plural,
|
||||
$this->code
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -52,10 +52,9 @@ class BlankValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation(
|
||||
'myMessage',
|
||||
array('{{ value }}' => $valueAsString)
|
||||
);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', $valueAsString)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidValues()
|
||||
|
@ -70,9 +70,9 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
$this->buildViolation('My message')
|
||||
->setParameter('{{ value }}', 'foobar')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testSingleMethodExplicitName()
|
||||
@ -206,9 +206,9 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
$this->buildViolation('My message')
|
||||
->setParameter('{{ value }}', 'foobar')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
// BC with Symfony < 2.4
|
||||
@ -219,14 +219,11 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolations(array(
|
||||
$this->createViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
)),
|
||||
$this->createViolation('Static message', array(
|
||||
'{{ value }}' => 'baz',
|
||||
)),
|
||||
));
|
||||
$this->buildViolation('My message')
|
||||
->setParameter('{{ value }}', 'foobar')
|
||||
->buildNextViolation('Static message')
|
||||
->setParameter('{{ value }}', 'baz')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
// BC with Symfony < 2.4
|
||||
@ -239,14 +236,11 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolations(array(
|
||||
$this->createViolation('My message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
)),
|
||||
$this->createViolation('Static message', array(
|
||||
'{{ value }}' => 'baz',
|
||||
)),
|
||||
));
|
||||
$this->buildViolation('My message')
|
||||
->setParameter('{{ value }}', 'foobar')
|
||||
->buildNextViolation('Static message')
|
||||
->setParameter('{{ value }}', 'baz')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
// BC with Symfony < 2.4
|
||||
@ -259,9 +253,9 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('Callback message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
$this->buildViolation('Callback message')
|
||||
->setParameter('{{ value }}', 'foobar')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
// BC with Symfony < 2.4
|
||||
@ -274,9 +268,9 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($object, $constraint);
|
||||
|
||||
$this->assertViolation('Callback message', array(
|
||||
'{{ value }}' => 'foobar',
|
||||
));
|
||||
$this->buildViolation('Callback message')
|
||||
->setParameter('{{ value }}', 'foobar')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,9 +63,9 @@ class CardSchemeValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($number, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => is_string($number) ? '"'.$number.'"' : $number,
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', is_string($number) ? '"'.$number.'"' : $number)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getValidNumbers()
|
||||
|
@ -144,9 +144,9 @@ class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate('baz', $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"baz"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"baz"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testInvalidChoiceMultiple()
|
||||
@ -159,9 +159,9 @@ class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate(array('foo', 'baz'), $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"baz"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"baz"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testTooFewChoices()
|
||||
@ -179,9 +179,11 @@ class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ limit }}' => 2,
|
||||
), 'property.path', $value, 2);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ limit }}', 2)
|
||||
->setInvalidValue($value)
|
||||
->setPlural(2)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testTooManyChoices()
|
||||
@ -199,9 +201,11 @@ class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ limit }}' => 2,
|
||||
), 'property.path', $value, 2);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ limit }}', 2)
|
||||
->setInvalidValue($value)
|
||||
->setPlural(2)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testNonStrict()
|
||||
@ -239,9 +243,9 @@ class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate('2', $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"2"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"2"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testNonStrictWithMultipleChoices()
|
||||
@ -268,8 +272,8 @@ class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate(array(2, '3'), $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"3"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"3"')
|
||||
->assertRaised();
|
||||
}
|
||||
}
|
||||
|
@ -142,9 +142,11 @@ abstract class CollectionValidatorTest extends AbstractConstraintValidatorTest
|
||||
'extraFieldsMessage' => 'myMessage',
|
||||
)));
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ field }}' => '"baz"',
|
||||
), 'property.path[baz]', 6);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ field }}', '"baz"')
|
||||
->atPath('property.path[baz]')
|
||||
->setInvalidValue(6)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
// bug fix
|
||||
@ -201,9 +203,11 @@ abstract class CollectionValidatorTest extends AbstractConstraintValidatorTest
|
||||
'missingFieldsMessage' => 'myMessage',
|
||||
)));
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ field }}' => '"foo"',
|
||||
), 'property.path[foo]', null);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ field }}', '"foo"')
|
||||
->atPath('property.path[foo]')
|
||||
->setInvalidValue(null)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testMissingFieldsAllowed()
|
||||
@ -311,9 +315,11 @@ abstract class CollectionValidatorTest extends AbstractConstraintValidatorTest
|
||||
'missingFieldsMessage' => 'myMessage',
|
||||
)));
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ field }}' => '"foo"',
|
||||
), 'property.path[foo]', null);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ field }}', '"foo"')
|
||||
->atPath('property.path[foo]')
|
||||
->setInvalidValue(null)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testRequiredFieldSingleConstraint()
|
||||
|
@ -127,10 +127,12 @@ abstract class CountValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ count }}' => count($value),
|
||||
'{{ limit }}' => 4,
|
||||
), 'property.path', $value, 4);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ count }}', count($value))
|
||||
->setParameter('{{ limit }}', 4)
|
||||
->setInvalidValue($value)
|
||||
->setPlural(4)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,10 +147,12 @@ abstract class CountValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ count }}' => count($value),
|
||||
'{{ limit }}' => 4,
|
||||
), 'property.path', $value, 4);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ count }}', count($value))
|
||||
->setParameter('{{ limit }}', 4)
|
||||
->setInvalidValue($value)
|
||||
->setPlural(4)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,10 +168,12 @@ abstract class CountValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ count }}' => count($value),
|
||||
'{{ limit }}' => 4,
|
||||
), 'property.path', $value, 4);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ count }}', count($value))
|
||||
->setParameter('{{ limit }}', 4)
|
||||
->setInvalidValue($value)
|
||||
->setPlural(4)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testDefaultOption()
|
||||
|
@ -87,9 +87,9 @@ class CountryValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($country, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$country.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$country.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidCountries()
|
||||
|
@ -101,9 +101,9 @@ class CurrencyValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($currency, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$currency.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$currency.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidCurrencies()
|
||||
|
@ -86,9 +86,9 @@ class DateTimeValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($dateTime, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$dateTime.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$dateTime.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidDateTimes()
|
||||
|
@ -86,9 +86,9 @@ class DateValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($date, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$date.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$date.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidDates()
|
||||
|
@ -79,9 +79,9 @@ class EmailValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($email, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$email.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$email.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidEmails()
|
||||
|
@ -49,8 +49,8 @@ class FalseValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate(true, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => 'true',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', 'true')
|
||||
->assertRaised();
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ class FileValidatorPathTest extends FileValidatorTest
|
||||
|
||||
$this->validator->validate('foobar', $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ file }}' => '"foobar"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ file }}', '"foobar"')
|
||||
->assertRaised();
|
||||
}
|
||||
}
|
||||
|
@ -162,12 +162,12 @@ abstract class FileValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($this->getFile($this->path), $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ limit }}' => $limitAsString,
|
||||
'{{ size }}' => $sizeAsString,
|
||||
'{{ suffix }}' => $suffix,
|
||||
'{{ file }}' => '"'.$this->path.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ limit }}', $limitAsString)
|
||||
->setParameter('{{ size }}', $sizeAsString)
|
||||
->setParameter('{{ suffix }}', $suffix)
|
||||
->setParameter('{{ file }}', '"'.$this->path.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function provideMaxSizeNotExceededTests()
|
||||
@ -222,18 +222,15 @@ abstract class FileValidatorTest extends AbstractConstraintValidatorTest
|
||||
$file = $this
|
||||
->getMockBuilder('Symfony\Component\HttpFoundation\File\File')
|
||||
->setConstructorArgs(array(__DIR__.'/Fixtures/foo'))
|
||||
->getMock()
|
||||
;
|
||||
->getMock();
|
||||
$file
|
||||
->expects($this->once())
|
||||
->method('getPathname')
|
||||
->will($this->returnValue($this->path))
|
||||
;
|
||||
->will($this->returnValue($this->path));
|
||||
$file
|
||||
->expects($this->once())
|
||||
->method('getMimeType')
|
||||
->will($this->returnValue('image/jpg'))
|
||||
;
|
||||
->will($this->returnValue('image/jpg'));
|
||||
|
||||
$constraint = new File(array(
|
||||
'mimeTypes' => array('image/png', 'image/jpg'),
|
||||
@ -249,18 +246,15 @@ abstract class FileValidatorTest extends AbstractConstraintValidatorTest
|
||||
$file = $this
|
||||
->getMockBuilder('Symfony\Component\HttpFoundation\File\File')
|
||||
->setConstructorArgs(array(__DIR__.'/Fixtures/foo'))
|
||||
->getMock()
|
||||
;
|
||||
->getMock();
|
||||
$file
|
||||
->expects($this->once())
|
||||
->method('getPathname')
|
||||
->will($this->returnValue($this->path))
|
||||
;
|
||||
->will($this->returnValue($this->path));
|
||||
$file
|
||||
->expects($this->once())
|
||||
->method('getMimeType')
|
||||
->will($this->returnValue('image/jpg'))
|
||||
;
|
||||
->will($this->returnValue('image/jpg'));
|
||||
|
||||
$constraint = new File(array(
|
||||
'mimeTypes' => array('image/*'),
|
||||
@ -276,18 +270,15 @@ abstract class FileValidatorTest extends AbstractConstraintValidatorTest
|
||||
$file = $this
|
||||
->getMockBuilder('Symfony\Component\HttpFoundation\File\File')
|
||||
->setConstructorArgs(array(__DIR__.'/Fixtures/foo'))
|
||||
->getMock()
|
||||
;
|
||||
->getMock();
|
||||
$file
|
||||
->expects($this->once())
|
||||
->method('getPathname')
|
||||
->will($this->returnValue($this->path))
|
||||
;
|
||||
->will($this->returnValue($this->path));
|
||||
$file
|
||||
->expects($this->once())
|
||||
->method('getMimeType')
|
||||
->will($this->returnValue('application/pdf'))
|
||||
;
|
||||
->will($this->returnValue('application/pdf'));
|
||||
|
||||
$constraint = new File(array(
|
||||
'mimeTypes' => array('image/png', 'image/jpg'),
|
||||
@ -296,11 +287,11 @@ abstract class FileValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($file, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ type }}' => '"application/pdf"',
|
||||
'{{ types }}' => '"image/png", "image/jpg"',
|
||||
'{{ file }}' => '"'.$this->path.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ type }}', '"application/pdf"')
|
||||
->setParameter('{{ types }}', '"image/png", "image/jpg"')
|
||||
->setParameter('{{ file }}', '"'.$this->path.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testInvalidWildcardMimeType()
|
||||
@ -308,18 +299,15 @@ abstract class FileValidatorTest extends AbstractConstraintValidatorTest
|
||||
$file = $this
|
||||
->getMockBuilder('Symfony\Component\HttpFoundation\File\File')
|
||||
->setConstructorArgs(array(__DIR__.'/Fixtures/foo'))
|
||||
->getMock()
|
||||
;
|
||||
->getMock();
|
||||
$file
|
||||
->expects($this->once())
|
||||
->method('getPathname')
|
||||
->will($this->returnValue($this->path))
|
||||
;
|
||||
->will($this->returnValue($this->path));
|
||||
$file
|
||||
->expects($this->once())
|
||||
->method('getMimeType')
|
||||
->will($this->returnValue('application/pdf'))
|
||||
;
|
||||
->will($this->returnValue('application/pdf'));
|
||||
|
||||
$constraint = new File(array(
|
||||
'mimeTypes' => array('image/*', 'image/jpg'),
|
||||
@ -328,11 +316,11 @@ abstract class FileValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($file, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ type }}' => '"application/pdf"',
|
||||
'{{ types }}' => '"image/*", "image/jpg"',
|
||||
'{{ file }}' => '"'.$this->path.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ type }}', '"application/pdf"')
|
||||
->setParameter('{{ types }}', '"image/*", "image/jpg"')
|
||||
->setParameter('{{ file }}', '"'.$this->path.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -349,7 +337,9 @@ abstract class FileValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($file, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', $params);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameters($params)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function uploadedFileErrorProvider()
|
||||
|
@ -164,9 +164,9 @@ class IbanValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($iban, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$iban.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$iban.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidIbans()
|
||||
|
@ -94,10 +94,10 @@ class ImageValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($this->image, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ width }}' => '2',
|
||||
'{{ min_width }}' => '3',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ width }}', '2')
|
||||
->setParameter('{{ min_width }}', '3')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testWidthTooBig()
|
||||
@ -109,10 +109,10 @@ class ImageValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($this->image, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ width }}' => '2',
|
||||
'{{ max_width }}' => '1',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ width }}', '2')
|
||||
->setParameter('{{ max_width }}', '1')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testHeightTooSmall()
|
||||
@ -124,10 +124,10 @@ class ImageValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($this->image, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ height }}' => '2',
|
||||
'{{ min_height }}' => '3',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ height }}', '2')
|
||||
->setParameter('{{ min_height }}', '3')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testHeightTooBig()
|
||||
@ -139,10 +139,10 @@ class ImageValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($this->image, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ height }}' => '2',
|
||||
'{{ max_height }}' => '1',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ height }}', '2')
|
||||
->setParameter('{{ max_height }}', '1')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,9 +151,9 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$ip.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$ip.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidIpsV4()
|
||||
@ -183,9 +183,9 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$ip.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$ip.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidPrivateIpsV4()
|
||||
@ -209,9 +209,9 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$ip.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$ip.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidReservedIpsV4()
|
||||
@ -235,9 +235,9 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$ip.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$ip.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidPublicIpsV4()
|
||||
@ -257,9 +257,9 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$ip.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$ip.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidIpsV6()
|
||||
@ -293,9 +293,9 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$ip.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$ip.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidPrivateIpsV6()
|
||||
@ -319,9 +319,9 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$ip.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$ip.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidReservedIpsV6()
|
||||
@ -344,9 +344,9 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$ip.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$ip.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidPublicIpsV6()
|
||||
@ -366,9 +366,9 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$ip.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$ip.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidIpsAll()
|
||||
@ -388,9 +388,9 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$ip.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$ip.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidPrivateIpsAll()
|
||||
@ -410,9 +410,9 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$ip.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$ip.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidReservedIpsAll()
|
||||
@ -432,9 +432,9 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($ip, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$ip.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$ip.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidPublicIpsAll()
|
||||
|
@ -176,9 +176,9 @@ class IsbnValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$isbn.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$isbn.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -205,9 +205,9 @@ class IsbnValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$isbn.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$isbn.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,8 +233,8 @@ class IsbnValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$isbn.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$isbn.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
}
|
||||
|
@ -146,9 +146,9 @@ class IssnValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($issn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$issn.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$issn.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,9 +163,9 @@ class IssnValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($issn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$issn.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$issn.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -191,9 +191,9 @@ class IssnValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($issn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$issn.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$issn.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,9 +207,9 @@ class IssnValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($issn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$issn.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$issn.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,8 +223,8 @@ class IssnValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($issn, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$issn.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$issn.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
}
|
||||
|
@ -87,9 +87,9 @@ class LanguageValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($language, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$language.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$language.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidLanguages()
|
||||
|
@ -156,10 +156,12 @@ class LengthValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$value.'"',
|
||||
'{{ limit }}' => 4,
|
||||
), 'property.path', $value, 4);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$value.'"')
|
||||
->setParameter('{{ limit }}', 4)
|
||||
->setInvalidValue($value)
|
||||
->setPlural(4)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,10 +180,12 @@ class LengthValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$value.'"',
|
||||
'{{ limit }}' => 4,
|
||||
), 'property.path', $value, 4);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$value.'"')
|
||||
->setParameter('{{ limit }}', 4)
|
||||
->setInvalidValue($value)
|
||||
->setPlural(4)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,10 +205,12 @@ class LengthValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$value.'"',
|
||||
'{{ limit }}' => 4,
|
||||
), 'property.path', $value, 4);
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$value.'"')
|
||||
->setParameter('{{ limit }}', 4)
|
||||
->setInvalidValue($value)
|
||||
->setPlural(4)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testConstraintGetDefaultOption()
|
||||
|
@ -89,9 +89,9 @@ class LocaleValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($locale, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$locale.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$locale.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidLocales()
|
||||
|
@ -86,9 +86,9 @@ class LuhnValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($number, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$number.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$number.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidNumbers()
|
||||
|
@ -56,9 +56,9 @@ class NotBlankValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate(null, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => 'null',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', 'null')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testBlankIsInvalid()
|
||||
@ -69,9 +69,9 @@ class NotBlankValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate('', $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '""',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '""')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testFalseIsInvalid()
|
||||
@ -82,9 +82,9 @@ class NotBlankValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate(false, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => 'false',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', 'false')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testEmptyArrayIsInvalid()
|
||||
@ -95,8 +95,8 @@ class NotBlankValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate(array(), $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => 'array',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', 'array')
|
||||
->assertRaised();
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,6 @@ class NotNullValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate(null, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage');
|
||||
$this->buildViolation('myMessage')->assertRaised();
|
||||
}
|
||||
}
|
||||
|
@ -45,9 +45,9 @@ class NullValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $valueAsString,
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', $valueAsString)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidValues()
|
||||
|
@ -113,10 +113,10 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $value,
|
||||
'{{ limit }}' => 10,
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', $value)
|
||||
->setParameter('{{ limit }}', 10)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,10 +131,10 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $value,
|
||||
'{{ limit }}' => 20,
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', $value)
|
||||
->setParameter('{{ limit }}', 20)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,10 +151,10 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMaxMessage', array(
|
||||
'{{ value }}' => $value,
|
||||
'{{ limit }}' => 20,
|
||||
));
|
||||
$this->buildViolation('myMaxMessage')
|
||||
->setParameter('{{ value }}', $value)
|
||||
->setParameter('{{ limit }}', 20)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,10 +171,10 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMinMessage', array(
|
||||
'{{ value }}' => $value,
|
||||
'{{ limit }}' => 10,
|
||||
));
|
||||
$this->buildViolation('myMinMessage')
|
||||
->setParameter('{{ value }}', $value)
|
||||
->setParameter('{{ limit }}', 10)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidValues()
|
||||
@ -198,10 +198,10 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate(9, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => 9,
|
||||
'{{ limit }}' => 10,
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', 9)
|
||||
->setParameter('{{ limit }}', 10)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testMaxMessageIsSet()
|
||||
@ -214,10 +214,10 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate(21, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => 21,
|
||||
'{{ limit }}' => 20,
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', 21)
|
||||
->setParameter('{{ limit }}', 20)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testNonNumeric()
|
||||
@ -228,8 +228,8 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
|
||||
'invalidMessage' => 'myMessage',
|
||||
)));
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"abcd"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"abcd"')
|
||||
->assertRaised();
|
||||
}
|
||||
}
|
||||
|
@ -82,9 +82,9 @@ class RegexValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$value.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$value.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidValues()
|
||||
|
@ -86,9 +86,9 @@ class TimeValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($time, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$time.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$time.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidTimes()
|
||||
|
@ -49,8 +49,8 @@ class TrueValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate(false, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => 'false',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', 'false')
|
||||
->assertRaised();
|
||||
}
|
||||
}
|
||||
|
@ -56,10 +56,10 @@ class TypeValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate('', $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '""',
|
||||
'{{ type }}' => 'integer',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '""')
|
||||
->setParameter('{{ type }}', 'integer')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,10 +123,10 @@ class TypeValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($value, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => $valueAsString,
|
||||
'{{ type }}' => $type,
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', $valueAsString)
|
||||
->setParameter('{{ type }}', $type)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidValues()
|
||||
|
@ -124,9 +124,9 @@ class UrlValidatorTest extends AbstractConstraintValidatorTest
|
||||
|
||||
$this->validator->validate($url, $constraint);
|
||||
|
||||
$this->assertViolation('myMessage', array(
|
||||
'{{ value }}' => '"'.$url.'"',
|
||||
));
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', '"'.$url.'"')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function getInvalidUrls()
|
||||
|
@ -4,7 +4,7 @@ namespace Symfony\Component\Validator\Tests\Mapping\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
|
||||
abstract class AbstractMethodStaticLoader
|
||||
abstract class AbstractStaticMethodLoader
|
||||
{
|
||||
abstract public static function loadMetadata(ClassMetadata $metadata);
|
||||
}
|
@ -90,22 +90,19 @@ class StaticMethodLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testLoadClassMetadataIgnoresAbstractMethods()
|
||||
{
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
// Disable error reporting, as AbstractStaticMethodLoader produces a
|
||||
// strict standards error
|
||||
error_reporting(0);
|
||||
|
||||
if (0 !== error_reporting()) {
|
||||
$this->markTestSkipped('Could not disable error reporting');
|
||||
}
|
||||
|
||||
include __DIR__.'/AbstractStaticMethodLoader.php';
|
||||
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticMethodLoader');
|
||||
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$caught = false;
|
||||
try {
|
||||
include __DIR__.'/AbstractMethodStaticLoader.php';
|
||||
} catch (\Exception $e) {
|
||||
// catching the PHP notice that is converted to an exception by PHPUnit
|
||||
$caught = true;
|
||||
}
|
||||
|
||||
if (!$caught) {
|
||||
$this->fail('AbstractMethodStaticLoader should produce a strict standard error.');
|
||||
}
|
||||
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\AbstractMethodStaticLoader');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$this->assertCount(0, $metadata->getConstraints());
|
||||
|
Reference in New Issue
Block a user