8000 [VarDumper] Draft: Positive*/Negative* constraint extends GreaterThan… · symfony/symfony@84de93c · GitHub
[go: up one dir, main page]

Skip to content

Commit 84de93c

Browse files
committed
[VarDumper] Draft: Positive*/Negative* constraint extends GreaterThan*/LessThan* constraint
1 parent c234619 commit 84de93c

16 files changed

+202
-671
lines changed

src/Symfony/Component/Validator/Constraints/Negative.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,27 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14-
use Symfony\Component\Validator\Constraint;
15-
1614
/**
1715
* @Annotation
1816
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1917
*
2018
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
2119
*/
22-
class Negative extends Constraint
20+
class Negative extends LessThan
2321
{
24-
const IS_POSITIVE_ERROR = '50430dfd-503a-4451-a9b6-3eb348a1d777';
25-
const IS_ZERO_ERROR = '5013ce74-a117-42d9-84ec-f076f52a6179';
22+
public $message = 'This value should be negative.';
2623

27-
protected static $errorNames = array(
28-
self::IS_POSITIVE_ERROR => 'IS_POSITIVE_ERROR',
29-
self::IS_ZERO_ERROR => 'IS_ZERO_ERROR',
30-
);
24+
public function __construct(array $options = null)
25+
{
26+
if (empty($options)) {
27+
$options = array('value' => 0);
28+
}
3129

32-
public $message = 'This value should be negative.';
30+
parent::__construct($options);
31+
}
32+
33+
public function validatedBy()
34+
{
35+
return 'LessThanValidator';
36+
}
3337
}

src/Symfony/Component/Validator/Constraints/NegativeOrZero.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14-
use Symfony\Component\Validator\Constraint;
15-
1614
/**
1715
* @Annotation
1816
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1917
*
2018
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
2119
*/
22-
class NegativeOrZero extends Constraint
20+
class NegativeOrZero extends LessThanOrEqual
2321
{
24-
const IS_POSITIVE_ERROR = '7b17bb87-4fce-4817-8167-3bb039dcae8e';
22+
public $message = 'This value should be either negative or zero.';
2523

26-
protected static $errorNames = array(
27-
self::IS_POSITIVE_ERROR => 'IS_POSITIVE_ERROR',
28-
);
24+
public function __construct(array $options = null)
25+
{
26+
if (empty($options)) {
27+
$options = array('value' => 0);
28+
}
2929

30-
public $message = 'This value should be either negative or zero.';
30+
parent::__construct($options);
31+
}
32+
33+
public function validatedBy()
34+
{
35+
return 'LessThanOrEqualValidator';
36+
}
3137
}

src/Symfony/Component/Validator/Constraints/NegativeOrZeroValidator.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Symfony/Component/Validator/Constraints/NegativeValidator.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/Symfony/Component/Validator/Constraints/Positive.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@
1717
*
1818
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
1919
*/
20-
class Positive extends AbstractComparison
20+
class Positive extends GreaterThan
2121
{
22-
const IS_NEGATIVE_ERROR = 'da93d4fe-371c-4bc2-99a3-9201efe7e1a4';
22+
public $message = 'This value should be positive.';
2323

24-
protected static $errorNames = array(
25-
self::IS_NEGATIVE_ERROR => 'IS_NEGATIVE_ERROR',
26-
);
24+
public function __construct(array $options = null)
25+
{
26+
if (empty($options)) {
27+
$options = array('value' => 0);
28+
}
2729

28-
public $message = 'This value should be positive.';
30+
parent::__construct($options);
31+
}
32+
33+
public function validatedBy()
34+
{
35+
return 'GreaterThanValidator';
36+
}
2937
}

src/Symfony/Component/Validator/Constraints/PositiveOrZero.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14-
use Symfony\Component\Validator\Constraint;
15-
1614
/**
1715
* @Annotation
1816
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1917
*
2018
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
2119
*/
22-
class PositiveOrZero extends Constraint
20+
class PositiveOrZero extends GreaterThanOrEqual
2321
{
24-
const IS_NEGATIVE_ERROR = 'd3b156b2-a386-4113-96be-76947bc7f16a';
22+
public $message = 'This value should be either positive or zero.';
2523

26-
protected static $errorNames = array(
27-
self::IS_NEGATIVE_ERROR => 'IS_NEGATIVE_ERROR',
28-
);
24+
public function __construct(array $options = null)
25+
{
26+
if (empty($options)) {
27+
$options = array('value' => 0);
28+
}
2929

30-
public $message = 'This value should be either positive or zero.';
30+
parent::__construct($options);
31+
}
32+
33+
public function validatedBy()
34+
{
35+
return 'GreaterThanOrEqualValidator';
36+
}
3137
}

src/Symfony/Component/Validator/Constraints/PositiveOrZeroValidator.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Symfony/Component/Validator/Constraints/PositiveValidator.php

Lines changed: 0 additions & 59 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Constraints;
13+
14+
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
15+
use Symfony\Component\Validator\Constraints\GreaterThanOrEqualValidator;
16+
use Symfony\Component\Validator\Constraints\PositiveOrZero;
17+
18+
/**
19+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
20+
*/
21+
class GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest extends GreaterThanOrEqualValidatorTest
22+
{
23+
protected function createConstraint(array $options = null)
24+
{
25+
return new PositiveOrZero($options);
26+
}
27+
28+
/**
29+
* @dataProvider provideInvalidConstraintOptions
30+
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
31+
* @expectedExceptionMessage requires either the "value" or "propertyPath" option to be set.
32+
*/
33+
public function testThrowsConstraintExceptionIfNoValueOrPropertyPath($options)
34+
{
35+
$this->markTestSkipped('value property always set for PositiveOrZero constraint');
36+
}
37+
}

0 commit comments

Comments
 (0)
0