-
-
Notifications
You must be signed in to change notification settings - Fork 420
/
Copy pathValidatorTest.php
119 lines (98 loc) · 4.02 KB
/
ValidatorTest.php
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
111
112
113
114
115
116
117
118
119
<?php
/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\MakerBundle\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
use Symfony\Bundle\MakerBundle\Validator;
class ValidatorTest extends TestCase
{
public function testValidateLength()
{
$this->assertSame(100, Validator::validateLength('100'));
$this->assertSame(99, Validator::validateLength(99));
}
public function testInvalidLength()
{
$this->expectException(RuntimeCommandException::class);
$this->expectExceptionMessage('Invalid length "-100".');
Validator::validateLength(-100);
}
public function testValidatePrecision()
{
$this->assertSame(15, Validator::validatePrecision('15'));
$this->assertSame(21, Validator::validatePrecision(21));
}
public function testInvalidPrecision()
{
$this->expectException(RuntimeCommandException::class);
$this->expectExceptionMessage('Invalid precision "66".');
Validator::validatePrecision(66);
}
public function testValidateScale()
{
$this->assertSame(2, Validator::validateScale('2'));
$this->assertSame(5, Validator::validateScale(5));
}
public function testInvalidScale()
{
$this->expectException(RuntimeCommandException::class);
$this->expectExceptionMessage('Invalid scale "31".');
Validator::validateScale(31);
}
public function testValidateClassName()
{
$this->assertSame('\App\Service\Foo', Validator::validateClassName('\App\Service\Foo'));
$this->assertSame('Foo', Validator::validateClassName('Foo'));
}
public function testValidateEmailAddress()
{
$this->assertSame('[email protected]', Validator::validateEmailAddress('[email protected]'));
}
public function testInvalidateEmailAddress()
{
$this->expectException(RuntimeCommandException::class);
$this->expectExceptionMessage('"badEmail" is not a valid email address.');
Validator::validateEmailAddress('badEmail');
$this->expectException(RuntimeCommandException::class);
$this->expectExceptionMessage('"" is not a valid email address.');
Validator::validateEmailAddress('');
}
public function testInvalidClassName()
{
$this->expectException(RuntimeCommandException::class);
$this->expectExceptionMessage('"Class" is a reserved keyword and thus cannot be used as class name in PHP.');
Validator::validateClassName('App\Entity\Class');
}
public function testInvalidEncodingInClassName()
{
$this->expectException(RuntimeCommandException::class);
$this->expectExceptionMessage(\sprintf('"%sController" is not a UTF-8-encoded string.', \chr(0xA6)));
Validator::validateClassName(mb_convert_encoding('ŚController', 'ISO-8859-2', 'UTF-8'));
}
public function testRegisteredEntitiesExists()
{
$this->expectException(RuntimeCommandException::class);
$this->expectExceptionMessage('There are no registered entities; please create an entity before using this command.');
Validator::entityExists('App\Entity\Class', []);
}
public function testEntityExists()
{
$className = self::class;
$this->assertSame($className, Validator::entityExists($className, [$className]));
$this->assertSame('\\'.$className, Validator::entityExists('\\'.$className, [$className]));
}
public function testEntityDoesNotExist()
{
$className = '\\'.self::class;
$this->expectException(RuntimeCommandException::class);
$this->expectExceptionMessage(\sprintf('Entity "%s" doesn\'t exist; please enter an existing one or create a new one.', $className));
Validator::entityExists($className, ['Full\Entity\DummyEntity']);
}
}