Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PropertyNotSetInConstructor error about $context is not raised in Con…
…straintValidator (#63)
- Loading branch information
Showing
5 changed files
with
66 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\Validator; | ||
|
||
use Symfony\Component\Validator\Context\ExecutionContextInterface; | ||
|
||
abstract class ConstraintValidator implements ConstraintValidatorInterface | ||
{ | ||
/** | ||
* @var ExecutionContextInterface | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
protected $context; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@symfony-common | ||
Feature: ConstraintValidator | ||
|
||
Background: | ||
Given I have the following config | ||
""" | ||
<?xml version="1.0"?> | ||
<psalm errorLevel="1"> | ||
<projectFiles> | ||
<directory name="."/> | ||
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles> | ||
</projectFiles> | ||
<plugins> | ||
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> | ||
</plugins> | ||
</psalm> | ||
""" | ||
|
||
Scenario: PropertyNotSetInConstructor error about $context is not raised | ||
Given I have the following code | ||
""" | ||
<?php | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
class CustomValidator extends ConstraintValidator | ||
{ | ||
public function __construct() {} | ||
public function validate($value, Constraint $constraint): void | ||
{ | ||
if ($value) { | ||
$this->context | ||
->buildViolation('foo') | ||
->atPath('foo') | ||
->addViolation(); | ||
} | ||
} | ||
} | ||
""" | ||
When I run Psalm | ||
Then I see no errors |