|
16 | 16 |
|
17 | 17 | class ValidatorTest extends TestCase
|
18 | 18 | {
|
19 |
| - private $object; |
| 19 | + private $validator; |
20 | 20 |
|
21 |
| - public function __construct() |
| 21 | + protected function setUp(): void |
22 | 22 | {
|
23 |
| - parent::__construct(); |
24 |
| - |
25 |
| - $this->object = new Validator(); |
| 23 | + $this->validator = new Validator(); |
26 | 24 | }
|
27 | 25 |
|
28 | 26 | public function testValidateUsername()
|
29 | 27 | {
|
30 | 28 | $test = 'username';
|
31 | 29 |
|
32 |
| - $this->assertSame($test, $this->object->validateUsername($test)); |
| 30 | + $this->assertSame($test, $this->validator->validateUsername($test)); |
33 | 31 | }
|
34 | 32 |
|
35 | 33 | public function testValidateUsernameEmpty()
|
36 | 34 | {
|
37 | 35 | $this->expectException('Exception');
|
38 | 36 | $this->expectExceptionMessage('The username can not be empty.');
|
39 |
| - $this->object->validateUsername(null); |
| 37 | + $this->validator->validateUsername(null); |
40 | 38 | }
|
41 | 39 |
|
42 | 40 | public function testValidateUsernameInvalid()
|
43 | 41 | {
|
44 | 42 | $this->expectException('Exception');
|
45 | 43 | $this->expectExceptionMessage('The username must contain only lowercase latin characters and underscores.');
|
46 |
| - $this->object->validateUsername('INVALID'); |
| 44 | + $this->validator->validateUsername('INVALID'); |
47 | 45 | }
|
48 | 46 |
|
49 | 47 | public function testValidatePassword()
|
50 | 48 | {
|
51 | 49 | $test = 'password';
|
52 | 50 |
|
53 |
| - $this->assertSame($test, $this->object->validatePassword($test)); |
| 51 | + $this->assertSame($test, $this->validator->validatePassword($test)); |
54 | 52 | }
|
55 | 53 |
|
56 | 54 | public function testValidatePasswordEmpty()
|
57 | 55 | {
|
58 | 56 | $this->expectException('Exception');
|
59 | 57 | $this->expectExceptionMessage('The password can not be empty.');
|
60 |
| - $this->object->validatePassword(null); |
| 58 | + $this->validator->validatePassword(null); |
61 | 59 | }
|
62 | 60 |
|
63 | 61 | public function testValidatePasswordInvalid()
|
64 | 62 | {
|
65 | 63 | $this->expectException('Exception');
|
66 | 64 | $this->expectExceptionMessage('The password must be at least 6 characters long.');
|
67 |
| - $this->object->validatePassword('12345'); |
| 65 | + $this->validator->validatePassword('12345'); |
68 | 66 | }
|
69 | 67 |
|
70 | 68 | public function testValidateEmail()
|
71 | 69 | {
|
72 | 70 | $test = '@';
|
73 | 71 |
|
74 |
| - $this->assertSame($test, $this->object->validateEmail($test)); |
| 72 | + $this->assertSame($test, $this->validator->validateEmail($test)); |
75 | 73 | }
|
76 | 74 |
|
77 | 75 | public function testValidateEmailEmpty()
|
78 | 76 | {
|
79 | 77 | $this->expectException('Exception');
|
80 | 78 | $this->expectExceptionMessage('The email can not be empty.');
|
81 |
| - $this->object->validateEmail(null); |
| 79 | + $this->validator->validateEmail(null); |
82 | 80 | }
|
83 | 81 |
|
84 | 82 | public function testValidateEmailInvalid()
|
85 | 83 | {
|
86 | 84 | $this->expectException('Exception');
|
87 | 85 | $this->expectExceptionMessage('The email should look like a real email.');
|
88 |
| - $this->object->validateEmail('invalid'); |
| 86 | + $this->validator->validateEmail('invalid'); |
89 | 87 | }
|
90 | 88 |
|
91 | 89 | public function testValidateFullName()
|
92 | 90 | {
|
93 | 91 | $test = 'Full Name';
|
94 | 92 |
|
95 |
| - $this->assertSame($test, $this->object->validateFullName($test)); |
| 93 | + $this->assertSame($test, $this->validator->validateFullName($test)); |
96 | 94 | }
|
97 | 95 |
|
98 | 96 | public function testValidateFullNameEmpty()
|
99 | 97 | {
|
100 | 98 | $this->expectException('Exception');
|
101 | 99 | $this->expectExceptionMessage('The full name can not be empty.');
|
102 |
| - $this->object->validateFullName(null); |
| 100 | + $this->validator->validateFullName(null); |
103 | 101 | }
|
104 | 102 | }
|
0 commit comments