Skip to content

Commit

Permalink
minor #57823 [Validator] properly set up constraint options (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 5.4 branch.

Discussion
----------

[Validator] properly set up constraint options

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

while working on #57812 I noticed that we did not properly set up some of the constraints which means that tests making use of constraint options were never tested correctly

Commits
-------

a3e0dc9edd properly set up constraint options
  • Loading branch information
nicolas-grekas committed Jul 26, 2024
2 parents 4595a47 + e64a020 commit 249792a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest extends Greate
{
protected static function createConstraint(?array $options = null): Constraint
{
return new PositiveOrZero();
return new PositiveOrZero($options);
}

/**
Expand Down Expand Up @@ -92,6 +92,11 @@ public function testInvalidValuePath()
$this->markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint');
}

public static function provideAllValidComparisons(): array
{
self::markTestSkipped('The "value" option cannot be used in the PositiveOrZero constraint');
}

/**
* @dataProvider provideValidComparisonsToPropertyPath
*/
Expand All @@ -100,6 +105,11 @@ public function testValidComparisonToPropertyPath($comparedValue)
$this->markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint');
}

public function testNoViolationOnNullObjectWithPropertyPath()
{
$this->markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint');
}

/**
* @dataProvider throwsOnInvalidStringDatesProvider
*/
Expand All @@ -112,4 +122,19 @@ public function testInvalidComparisonToPropertyPathAddsPathAsParameter()
{
$this->markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint');
}

public static function throwsOnInvalidStringDatesProvider(): array
{
self::markTestSkipped('The "value" option cannot be used in the PositiveOrZero constraint');
}

public static function provideAllInvalidComparisons(): array
{
self::markTestSkipped('The "value" option cannot be used in the Negative constraint');
}

public static function provideComparisonsToNullValueAtPropertyPath(): array
{
self::markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GreaterThanValidatorWithPositiveConstraintTest extends GreaterThanValidato
{
protected static function createConstraint(?array $options = null): Constraint
{
return new Positive();
return new Positive($options);
}

/**
Expand Down Expand Up @@ -95,6 +95,11 @@ public function testInvalidValuePath()
$this->markTestSkipped('PropertyPath option is not used in Positive constraint');
}

public static function provideAllValidComparisons(): array
{
self::markTestSkipped('The "value" option cannot be used in the Positive constraint');
}

/**
* @dataProvider provideValidComparisonsToPropertyPath
*/
Expand All @@ -115,4 +120,19 @@ public function testInvalidComparisonToPropertyPathAddsPathAsParameter()
{
$this->markTestSkipped('PropertyPath option is not used in Positive constraint');
}

public static function throwsOnInvalidStringDatesProvider(): array
{
self::markTestSkipped('The "value" option cannot be used in the Positive constraint');
}

public static function provideAllInvalidComparisons(): array
{
self::markTestSkipped('The "value" option cannot be used in the Positive constraint');
}

public static function provideComparisonsToNullValueAtPropertyPath(): array
{
self::markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest extends LessThanO
{
protected static function createConstraint(?array $options = null): Constraint
{
return new NegativeOrZero();
return new NegativeOrZero($options);
}

/**
Expand Down Expand Up @@ -95,6 +95,11 @@ public function testInvalidValuePath()
$this->markTestSkipped('PropertyPath option is not used in NegativeOrZero constraint');
}

public static function provideAllValidComparisons(): array
{
self::markTestSkipped('The "value" option cannot be used in the NegativeOrZero constraint');
}

/**
* @dataProvider provideValidComparisonsToPropertyPath
*/
Expand All @@ -103,12 +108,9 @@ public function testValidComparisonToPropertyPath($comparedValue)
$this->markTestSkipped('PropertyPath option is not used in NegativeOrZero constraint');
}

/**
* @dataProvider throwsOnInvalidStringDatesProvider
*/
public function testThrowsOnInvalidStringDates(AbstractComparison $constraint, $expectedMessage, $value)
public function testInvalidComparisonToPropertyPathAddsPathAsParameter()
{
$this->markTestSkipped('The compared value cannot be an invalid string date because it is hardcoded to 0.');
$this->markTestSkipped('PropertyPath option is not used in NegativeOrZero constraint');
}

/**
Expand All @@ -119,8 +121,13 @@ public function testCompareWithNullValueAtPropertyAt($dirtyValue, $dirtyValueAsS
$this->markTestSkipped('PropertyPath option is not used in NegativeOrZero constraint');
}

public function testInvalidComparisonToPropertyPathAddsPathAsParameter()
public static function throwsOnInvalidStringDatesProvider(): array
{
$this->markTestSkipped('PropertyPath option is not used in NegativeOrZero constraint');
self::markTestSkipped('The "value" option cannot be used in the NegativeOrZero constraint');
}

public static function provideAllInvalidComparisons(): array
{
self::markTestSkipped('The "value" option cannot be used in the NegativeOrZero constraint');
}
}
19 changes: 13 additions & 6 deletions Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LessThanValidatorWithNegativeConstraintTest extends LessThanValidatorTest
{
protected static function createConstraint(?array $options = null): Constraint
{
return new Negative();
return new Negative($options);
}

/**
Expand Down Expand Up @@ -95,6 +95,11 @@ public function testInvalidValuePath()
$this->markTestSkipped('PropertyPath option is not used in Negative constraint');
}

public static function provideAllValidComparisons(): array
{
self::markTestSkipped('The "value" option cannot be used in the Negative constraint');
}

/**
* @dataProvider provideValidComparisonsToPropertyPath
*/
Expand All @@ -103,12 +108,9 @@ public function testValidComparisonToPropertyPath($comparedValue)
$this->markTestSkipped('PropertyPath option is not used in Negative constraint');
}

/**
* @dataProvider throwsOnInvalidStringDatesProvider
*/
public function testThrowsOnInvalidStringDates(AbstractComparison $constraint, $expectedMessage, $value)
public static function throwsOnInvalidStringDatesProvider(): array
{
$this->markTestSkipped('The compared value cannot be an invalid string date because it is hardcoded to 0.');
self::markTestSkipped('The "value" option cannot be used in the Negative constraint');
}

/**
Expand All @@ -123,4 +125,9 @@ public function testInvalidComparisonToPropertyPathAddsPathAsParameter()
{
$this->markTestSkipped('PropertyPath option is not used in Negative constraint');
}

public static function provideAllInvalidComparisons(): array
{
self::markTestSkipped('The "value" option cannot be used in the Negative constraint');
}
}

0 comments on commit 249792a

Please sign in to comment.