|
1
|
|
|
<?php namespace spec\Felixkiss\UniqueWithValidator; |
|
2
|
|
|
|
|
3
|
|
|
use PhpSpec\ObjectBehavior; |
|
4
|
|
|
|
|
5
|
|
|
class RuleParserSpec extends ObjectBehavior |
|
6
|
|
|
{ |
|
7
|
|
|
function it_is_initializable() |
|
8
|
|
|
{ |
|
9
|
|
|
$this->shouldHaveType('Felixkiss\UniqueWithValidator\RuleParser'); |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
function it_can_parse_the_table_name_correctly() |
|
13
|
|
|
{ |
|
14
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'last_name'], []); |
|
15
|
|
|
$this->getTable()->shouldReturn('users'); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
function it_can_parse_the_primary_field_correctly() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'last_name'], []); |
|
21
|
|
|
$this->getPrimaryField()->shouldReturn('first_name'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
function it_can_parse_the_primary_value_correctly() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'last_name'], []); |
|
27
|
|
|
$this->getPrimaryValue()->shouldReturn('Foo'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
function it_can_parse_one_additional_field_correctly() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'last_name'], ['last_name' => 'Bar']); |
|
33
|
|
|
$this->getAdditionalFields()->shouldReturn(['last_name' => 'Bar']); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_can_parse_two_additional_fields_correctly() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'middle_name', 'last_name'], ['middle_name' => 'Quux', 'last_name' => 'Bar']); |
|
39
|
|
|
$this->getAdditionalFields()->shouldReturn(['middle_name' => 'Quux', 'last_name' => 'Bar']); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
function it_can_parse_custom_name_for_primary_field_correctly() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'first_name = firstName', 'last_name'], ['last_name' => 'Bar']); |
|
45
|
|
|
$this->getPrimaryField()->shouldReturn('firstName'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
function it_can_parse_custom_name_for_additional_field_correctly() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'last_name = sur_name'], ['last_name' => 'Bar']); |
|
51
|
|
|
$this->getAdditionalFields()->shouldReturn(['sur_name' => 'Bar']); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function it_has_no_ignore_value_by_default() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'last_name'], []); |
|
57
|
|
|
$this->getIgnoreValue()->shouldReturn(null); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
function it_has_no_ignore_column_by_default() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'last_name'], []); |
|
63
|
|
|
$this->getIgnoreColumn()->shouldReturn(null); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
function it_can_parse_implicit_integer_ignore_value_correctly() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'last_name', '1'], []); |
|
69
|
|
|
$this->getIgnoreValue()->shouldReturn('1'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
function it_can_parse_implicit_integer_ignore_column_correctly() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'last_name', '1 = user_id'], []); |
|
75
|
|
|
$this->getIgnoreColumn()->shouldReturn('user_id'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
function it_can_parse_explicit_ignore_value_correctly() |
|
79
|
|
|
{ |
|
80
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'last_name', 'ignore:abc123'], []); |
|
81
|
|
|
$this->getIgnoreValue()->shouldReturn('abc123'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
function it_can_parse_explicit_ignore_column_correctly() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'last_name', 'ignore:abc123 = user_id'], []); |
|
87
|
|
|
$this->getIgnoreColumn()->shouldReturn('user_id'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
function it_returns_data_fields_correctly() |
|
91
|
|
|
{ |
|
92
|
|
|
$this->beConstructedWith('first_name', 'Foo', ['users', 'first_name = firstName', 'middle_name', 'last_name => lastName', 'ignore:abc123 = user_id'], []); |
|
93
|
|
|
$this->getDataFields()->shouldReturn(['first_name', 'middle_name', 'last_name']); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|