|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Spiral Framework. |
|
5
|
|
|
* |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @author Anton Titov (Wolfy-J) |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Spiral\Tests\Validation; |
|
13
|
|
|
|
|
14
|
|
|
class EmptyTest extends BaseTest |
|
15
|
|
|
{ |
|
16
|
|
|
public function testNoRules(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$result = $this->validation->validate([], []); |
|
19
|
|
|
$this->assertTrue($result->isValid()); |
|
20
|
|
|
$this->assertSame([], $result->getErrors()); |
|
21
|
|
|
|
|
22
|
|
|
$result = $this->validation->validate(['email' => '[email protected]'], []); |
|
23
|
|
|
$this->assertTrue($result->isValid()); |
|
24
|
|
|
$this->assertSame([], $result->getErrors()); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testNotEmpty(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$result = $this->validation->validate([], ['name' => ['type::notEmpty']]); |
|
30
|
|
|
$this->assertFalse($result->isValid()); |
|
31
|
|
|
$this->assertSame(['name' => 'This value is required.'], $result->getErrors()); |
|
32
|
|
|
|
|
33
|
|
|
$result = $this->validation->validate(['name' => null], ['name' => ['type::notEmpty']]); |
|
34
|
|
|
$this->assertFalse($result->isValid()); |
|
35
|
|
|
|
|
36
|
|
|
$result = $this->validation->validate(['name' => ''], ['name' => ['type::notEmpty']]); |
|
37
|
|
|
$this->assertFalse($result->isValid()); |
|
38
|
|
|
|
|
39
|
|
|
$result = $this->validation->validate(['name' => 'John Doe'], ['name' => ['type::notEmpty']]); |
|
40
|
|
|
$this->assertTrue($result->isValid()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testNotEmptyShorter(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$result = $this->validation->validate([], ['name' => 'notEmpty']); |
|
46
|
|
|
$this->assertFalse($result->isValid()); |
|
47
|
|
|
$this->assertSame(['name' => 'This value is required.'], $result->getErrors()); |
|
48
|
|
|
|
|
49
|
|
|
$result = $this->validation->validate(['name' => null], ['name' => 'notEmpty']); |
|
50
|
|
|
$this->assertFalse($result->isValid()); |
|
51
|
|
|
|
|
52
|
|
|
$result = $this->validation->validate(['name' => ''], ['name' => 'notEmpty']); |
|
53
|
|
|
$this->assertFalse($result->isValid()); |
|
54
|
|
|
|
|
55
|
|
|
$result = $this->validation->validate(['name' => 'John Doe'], ['name' => 'notEmpty']); |
|
56
|
|
|
$this->assertTrue($result->isValid()); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|