-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathMakeValidatorTest.php
More file actions
110 lines (91 loc) · 3.78 KB
/
Copy pathMakeValidatorTest.php
File metadata and controls
110 lines (91 loc) · 3.78 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/*
* This file is part of the Symfony MakerBundle 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\Bundle\MakerBundle\Tests\Maker;
use Symfony\Bundle\MakerBundle\Maker\MakeValidator;
use Symfony\Bundle\MakerBundle\Test\MakerTestCase;
use Symfony\Bundle\MakerBundle\Test\MakerTestRunner;
use Symfony\Bundle\MakerBundle\Validator\TargetEnum;
class MakeValidatorTest extends MakerTestCase
{
protected function getMakerClass(): string
{
return MakeValidator::class;
}
public function getTestDetails(): \Generator
{
yield 'it_makes_validator' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
$runner->runMaker(
[
// validator name
'FooBar',
]
);
// Validator
$expectedVoterPath = \dirname(__DIR__).'/fixtures/make-validator/expected/FooBarValidator.php';
$generatedVoter = $runner->getPath('src/Validator/FooBarValidator.php');
self::assertSame(file_get_contents($expectedVoterPath), file_get_contents($generatedVoter));
// Constraint
$expectedVoterPath = \dirname(__DIR__).'/fixtures/make-validator/expected/FooBar.php';
$generatedVoter = $runner->getPath('src/Validator/FooBar.php');
self::assertSame(file_get_contents($expectedVoterPath), file_get_contents($generatedVoter));
}),
];
yield 'it_makes_validator_constraint_with_target' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
$targets = $this->getTargets();
foreach ($targets as $target => $className) {
$runner->runMaker(
[
// Validator name.
$className,
],
"--target=$target"
);
$expectedPath = \dirname(__DIR__)."/fixtures/make-validator/expected/$className.php";
$generatedPath = $runner->getPath("src/Validator/$className.php");
self::assertSame(file_get_contents($expectedPath), file_get_contents($generatedPath));
}
}),
];
yield 'it_makes_validator_constraint_with_target_invalid' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
$targets = $this->getTargets();
$keys = array_keys($targets);
foreach ($targets as $target => $className) {
$choice = array_search($target, $keys);
$runner->runMaker(
[
// Validator name.
$className,
// Target type.
$choice,
],
'--target=invalid'
);
$expectedPath = \dirname(__DIR__)."/fixtures/make-validator/expected/$className.php";
$generatedPath = $runner->getPath("src/Validator/$className.php");
self::assertSame(file_get_contents($expectedPath), file_get_contents($generatedPath));
}
}),
];
}
/**
* @return array<value-of<TargetEnum>, string>
*/
private function getTargets(): array
{
return [
'class' => 'WithTargetClass',
'method' => 'WithTargetMethod',
'property' => 'WithTargetProperty',
];
}
}