1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Author: Nil Portugués Calderó <[email protected]> |
4
|
|
|
* Date: 12/29/14 |
5
|
|
|
* Time: 9:39 PM |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Tests\NilPortugues\Validator; |
12
|
|
|
|
13
|
|
|
use NilPortugues\Validator\ValidatorFactory; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class ValidatorFactoryTest |
17
|
|
|
* @package Tests\NilPortugues\Validator |
18
|
|
|
*/ |
19
|
|
|
class ValidatorFactoryTest extends \PHPUnit_Framework_TestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @test |
23
|
|
|
*/ |
24
|
|
|
public function itShouldGetStringValidatorAndReturnFalse() |
25
|
|
|
{ |
26
|
|
|
$stringValidator = ValidatorFactory::create('field1', 'string', ['between:5:11']); |
27
|
|
|
|
28
|
|
|
$this->assertInstanceOf('\NilPortugues\Validator\Attribute\String\StringAttribute', $stringValidator); |
29
|
|
|
$this->assertFalse($stringValidator->validate('hello world')); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @test |
34
|
|
|
*/ |
35
|
|
|
public function itShouldGetStringValidatorWithBooleanValueAndReturnFalse() |
36
|
|
|
{ |
37
|
|
|
$stringValidator = ValidatorFactory::create('field1', 'string', ['between:5:11:false']); |
38
|
|
|
$this->assertFalse($stringValidator->validate('hello world')); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @test |
43
|
|
|
*/ |
44
|
|
|
public function itShouldGetStringValidatorAndReturnTrue() |
45
|
|
|
{ |
46
|
|
|
$stringValidator = ValidatorFactory::create('field1', 'string', ['between:5:11:true']); |
47
|
|
|
$this->assertTrue($stringValidator->validate('hello world')); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @test |
52
|
|
|
*/ |
53
|
|
|
public function itShouldGetStringValidatorAndAssertTrueUsingAllMethodAliases() |
54
|
|
|
{ |
55
|
|
|
$stringValidator = ValidatorFactory::create('field1', 'string', ['is_email']); |
56
|
|
|
$this->assertTrue($stringValidator->validate('[email protected]')); |
57
|
|
|
|
58
|
|
|
$stringValidator = ValidatorFactory::create('field2', 'string', ['isEmail']); |
59
|
|
|
$this->assertTrue($stringValidator->validate('[email protected]')); |
60
|
|
|
|
61
|
|
|
$stringValidator = ValidatorFactory::create('field3', 'string', ['email']); |
62
|
|
|
$this->assertTrue($stringValidator->validate('[email protected]')); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @test |
67
|
|
|
*/ |
68
|
|
|
public function itShouldThrowValidatorFactoryException() |
69
|
|
|
{ |
70
|
|
|
$this->setExpectedException('NilPortugues\Validator\Factory\ValidatorFactoryException'); |
71
|
|
|
ValidatorFactory::create('field1', 'not-a-valid-type'); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|