-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFieldConstraintsSetProviderTestCase.php
More file actions
47 lines (40 loc) · 1.61 KB
/
FieldConstraintsSetProviderTestCase.php
File metadata and controls
47 lines (40 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace AssoConnect\ValidatorBundle\Test;
use AssoConnect\ValidatorBundle\Validator\ConstraintsSetProvider\Field\FieldConstraintsSetProviderInterface;
use Doctrine\ORM\Mapping\FieldMapping;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraint;
/**
* This test should test validation violations instead of the returned set of constraints
* But that would require using the Symfony Compound constraint which cannot be used for tests
* @link https://github.com/symfony/symfony/issues/50205
*/
abstract class FieldConstraintsSetProviderTestCase extends TestCase
{
abstract protected function getFactory(): FieldConstraintsSetProviderInterface;
/**
* @param Constraint[] $constraints
* @dataProvider getConstraintsForTypeProvider
*/
public function testGetConstraintsForType(FieldMapping $fieldMapping, array $constraints): void
{
$factory = $this->getFactory();
self::assertTrue($factory->supports($fieldMapping->type));
self::assertArrayContainsSameObjects(
/** @phpstan-ignore-next-line */
$factory->getConstraints($fieldMapping),
$constraints
);
}
/** @return iterable{FieldMapping, Constraint[]} */
abstract public function getConstraintsForTypeProvider(): iterable;
/**
* @param mixed[] $array1
* @param mixed[] $array2
*/
protected static function assertArrayContainsSameObjects(array $array1, array $array2, string $message = ''): void
{
self::assertThat($array1, new ArrayContainSameObjectsConstraint($array2), $message);
}
}