Skip to content

Commit

Permalink
Merge branch '2.8'
Browse files Browse the repository at this point in the history
* 2.8:
  [EventDispatcher] make listeners removable from an executed listener
  [2.7][DoctrineBridge] change Logger interface in tests to use Psr\\Log\\LoggerInterface instead of Symfony\\Component\\HttpKernel\\Log\\LoggerInterface"
  [HttpFoundation] Fix volatile MongoDbSessionHandlerTest::testRead()
  bumped Symfony version to 2.7.0
  updated VERSION for 2.7.0-BETA2
  updated CHANGELOG for 2.7.0-BETA2
  Fixed compatibility with PHP7 and up by introducing new constraints (IsNull, IsTrue, IsFalse) and related validators (IsNullValidator, IsTrueValidator, IsFalseValidator)
  [Console] SymfonyStyle: fix block rpadding when escaping '<'
  [Console] fix code style

Conflicts:
	CHANGELOG-2.7.md
	src/Symfony/Component/Form/composer.json
  • Loading branch information
nicolas-grekas committed May 15, 2015
2 parents e4162fc + 2119bf3 commit d0b9801
Show file tree
Hide file tree
Showing 31 changed files with 326 additions and 165 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php
Expand Up @@ -75,7 +75,7 @@ public function testLogNonUtf8()

public function testLogLongString()
{
$logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
$logger = $this->getMock('Psr\\Log\\LoggerInterface');

$dbalLogger = $this
->getMockBuilder('Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger')
Expand Down Expand Up @@ -107,7 +107,7 @@ public function testLogUTF8LongString()
$this->markTestSkipped('Testing log shortening of utf8 charsets requires the mb_detect_encoding() function.');
}

$logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
$logger = $this->getMock('Psr\\Log\\LoggerInterface');

$dbalLogger = $this
->getMockBuilder('Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger')
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Console/Style/StyleInterface.php
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\Console\Style;

/**
* Output style helpers
* Output style helpers.
*
* @author Kevin Bond <kevinbond@gmail.com>
*/
Expand Down Expand Up @@ -92,9 +92,9 @@ public function table(array $headers, array $rows);
/**
* Asks a question.
*
* @param string $question
* @param string|null $default
* @param callable|null $validator
* @param string $question
* @param string|null $default
* @param callable|null $validator
*
* @return string
*/
Expand Down Expand Up @@ -132,7 +132,7 @@ public function confirm($question, $default = true);
public function choice($question, array $choices, $default = null);

/**
* Add newline(s)
* Add newline(s).
*
* @param int $count The number of newlines
*/
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Console/Style/SymfonyStyle.php
Expand Up @@ -52,11 +52,11 @@ public function __construct(InputInterface $input, OutputInterface $output)
/**
* Formats a message as a block of text.
*
* @param string|array $messages The message to write in the block
* @param string|null $type The block type (added in [] on first line)
* @param string|null $style The style to apply to the whole block
* @param string $prefix The prefix for the block
* @param bool $padding Whether to add vertical padding
* @param string|array $messages The message to write in the block
* @param string|null $type The block type (added in [] on first line)
* @param string|null $style The style to apply to the whole block
* @param string $prefix The prefix for the block
* @param bool $padding Whether to add vertical padding
*/
public function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false)
{
Expand Down Expand Up @@ -85,7 +85,7 @@ public function block($messages, $type = null, $style = null, $prefix = ' ', $pa

foreach ($lines as &$line) {
$line = sprintf('%s%s', $prefix, $line);
$line .= str_repeat(' ', $this->lineLength - Helper::strlen($line));
$line .= str_repeat(' ', $this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(), $line));

if ($style) {
$line = sprintf('<%s>%s</>', $style, $line);
Expand Down
Expand Up @@ -150,6 +150,8 @@ public function guessTypeForConstraint(Constraint $constraint)

case 'Symfony\Component\Validator\Constraints\True':
case 'Symfony\Component\Validator\Constraints\False':
case 'Symfony\Component\Validator\Constraints\IsTrue':
case 'Symfony\Component\Validator\Constraints\IsFalse':
return new TypeGuess('checkbox', array(), Guess::MEDIUM_CONFIDENCE);
}
}
Expand All @@ -167,6 +169,7 @@ public function guessRequiredForConstraint(Constraint $constraint)
case 'Symfony\Component\Validator\Constraints\NotNull':
case 'Symfony\Component\Validator\Constraints\NotBlank':
case 'Symfony\Component\Validator\Constraints\True':
case 'Symfony\Component\Validator\Constraints\IsTrue':
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
}
}
Expand Down
Expand Up @@ -19,7 +19,7 @@
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\IsTrue;
use Symfony\Component\Validator\Constraints\Type;
use Symfony\Component\Validator\Mapping\ClassMetadata;

Expand Down Expand Up @@ -64,7 +64,7 @@ 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 IsTrue(), 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)),
);
Expand All @@ -84,6 +84,18 @@ public function testGuessRequired($constraint, $guess)
$this->assertEquals($guess, $this->guesser->guessRequired(self::TEST_CLASS, self::TEST_PROPERTY));
}

/**
* @group legacy
*/
public function testLegacyGuessRequired()
{
if (PHP_VERSION_ID >= 70000) {
$this->markTestSkipped('Cannot use a class called True on PHP 7 or higher.');
}
$true = 'Symfony\Component\Validator\Constraints\True';
$this->testGuessRequired(new $true(), new ValueGuess(true, Guess::HIGH_CONFIDENCE));
}

public function testGuessRequiredReturnsFalseForUnmappedProperties()
{
$this->assertEquals(new ValueGuess(false, Guess::LOW_CONFIDENCE), $this->guesser->guessRequired(self::TEST_CLASS, self::TEST_PROPERTY));
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Form/composer.json
Expand Up @@ -31,6 +31,11 @@
"symfony/security-csrf": "~2.8|~3.0",
"symfony/translation": "~2.8|~3.0"
},
"conflict": {
"symfony/doctrine-bridge": "<2.7",
"symfony/framework-bundle": "<2.7",
"symfony/twig-bridge": "<2.7"
},
"suggest": {
"symfony/validator": "For form validation.",
"symfony/security-csrf": "For protecting forms against CSRF attacks.",
Expand Down
Expand Up @@ -85,7 +85,7 @@ public function testRead()

// defining the timeout before the actual method call
// allows to test for "greater than" values in the $criteria
$testTimeout = time();
$testTimeout = time() + 1;

$collection->expects($this->once())
->method('findOne')
Expand Down
Expand Up @@ -93,6 +93,19 @@ public function testAddListenerNested()
$this->assertTrue($called2);
}

public function testListenerCanRemoveItselfWhenExecuted()
{
$eventDispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
$listener1 = function () use ($eventDispatcher, &$listener1) {
$eventDispatcher->removeListener('foo', $listener1);
};
$eventDispatcher->addListener('foo', $listener1);
$eventDispatcher->addListener('foo', function () {});
$eventDispatcher->dispatch('foo');

$this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed');
}

protected function getHttpKernel($dispatcher, $controller)
{
$resolver = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface');
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Expand Up @@ -87,6 +87,11 @@ CHANGELOG
* added a constraint the uses the expression language
* added `minRatio`, `maxRatio`, `allowSquare`, `allowLandscape`, and `allowPortrait` to Image validator

2.3.29
------

* fixed compatibility with PHP7 and up by introducing new constraints (IsNull, IsTrue, IsFalse) and related validators (IsNullValidator, IsTrueValidator, IsFalseValidator)

2.3.0
-----

Expand Down
7 changes: 1 addition & 6 deletions src/Symfony/Component/Validator/Constraints/False.php
Expand Up @@ -11,8 +11,6 @@

namespace Symfony\Component\Validator\Constraints;

use Symfony\Component\Validator\Constraint;

/**
* @Annotation
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Expand All @@ -21,7 +19,4 @@
*
* @api
*/
class False extends Constraint
{
public $message = 'This value should be false.';
}
class False extends IsFalse {}
32 changes: 1 addition & 31 deletions src/Symfony/Component/Validator/Constraints/FalseValidator.php
Expand Up @@ -11,39 +11,9 @@

namespace Symfony\Component\Validator\Constraints;

use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class FalseValidator extends ConstraintValidator
{
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof False) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\False');
}

if (null === $value || false === $value || 0 === $value || '0' === $value) {
return;
}

if ($this->context instanceof ExecutionContextInterface) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->addViolation();
} else {
$this->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->addViolation();
}
}
}
class FalseValidator extends IsFalseValidator {}
27 changes: 27 additions & 0 deletions src/Symfony/Component/Validator/Constraints/IsFalse.php
@@ -0,0 +1,27 @@
<?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\Constraints;

use Symfony\Component\Validator\Constraint;

/**
* @Annotation
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class IsFalse extends Constraint
{
public $message = 'This value should be false.';
}
49 changes: 49 additions & 0 deletions src/Symfony/Component/Validator/Constraints/IsFalseValidator.php
@@ -0,0 +1,49 @@
<?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\Constraints;

use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class IsFalseValidator extends ConstraintValidator
{
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof IsFalse) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsFalse');
}

if (null === $value || false === $value || 0 === $value || '0' === $value) {
return;
}

if ($this->context instanceof ExecutionContextInterface) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->addViolation();
} else {
$this->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->addViolation();
}
}
}
27 changes: 27 additions & 0 deletions src/Symfony/Component/Validator/Constraints/IsNull.php
@@ -0,0 +1,27 @@
<?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\Constraints;

use Symfony\Component\Validator\Constraint;

/**
* @Annotation
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class IsNull extends Constraint
{
public $message = 'This value should be null.';
}
47 changes: 47 additions & 0 deletions src/Symfony/Component/Validator/Constraints/IsNullValidator.php
@@ -0,0 +1,47 @@
<?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\Constraints;

use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class IsNullValidator extends ConstraintValidator
{
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof IsNull) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsNull');
}

if (null !== $value) {
if ($this->context instanceof ExecutionContextInterface) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->addViolation();
} else {
$this->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->addViolation();
}
}
}
}

0 comments on commit d0b9801

Please sign in to comment.