@@ 81-93 (lines=13) @@ | ||
78 | $this->assertEquals(['foo', 'bar'], $attributeSet->getAttributes()); |
|
79 | } |
|
80 | ||
81 | public function testShouldValidateAttributesWhenThereAreMissingRequiredAttributes() |
|
82 | { |
|
83 | $input = (object)[ |
|
84 | 'foo' => 42, |
|
85 | ]; |
|
86 | ||
87 | $attribute1 = new Attribute('foo', new AlwaysValid(), true); |
|
88 | $attribute2 = new Attribute('bar', new AlwaysValid(), true); |
|
89 | ||
90 | $attributeSet = new AttributeSet($attribute1, $attribute2); |
|
91 | ||
92 | $this->assertFalse($attributeSet->validate($input)); |
|
93 | } |
|
94 | ||
95 | public function testShouldValidateAttributesWhenThereAreMissingNonRequiredAttributes() |
|
96 | { |
|
@@ 95-107 (lines=13) @@ | ||
92 | $this->assertFalse($attributeSet->validate($input)); |
|
93 | } |
|
94 | ||
95 | public function testShouldValidateAttributesWhenThereAreMissingNonRequiredAttributes() |
|
96 | { |
|
97 | $input = (object)[ |
|
98 | 'foo' => 42, |
|
99 | ]; |
|
100 | ||
101 | $attribute1 = new Attribute('foo', new AlwaysValid(), true); |
|
102 | $attribute2 = new Attribute('bar', new AlwaysValid(), false); |
|
103 | ||
104 | $attributeSet = new AttributeSet($attribute1, $attribute2); |
|
105 | ||
106 | $this->assertTrue($attributeSet->validate($input)); |
|
107 | } |
|
108 | ||
109 | public function testShouldValidateAttributesWhenThereAreMoreAttributes() |
|
110 | { |
|
@@ 125-135 (lines=11) @@ | ||
122 | $this->assertFalse($attributeSet->validate($input)); |
|
123 | } |
|
124 | ||
125 | public function testShouldValidateAttributesWhenEmpty() |
|
126 | { |
|
127 | $input = (object)[]; |
|
128 | ||
129 | $attribute1 = new Attribute('foo', new AlwaysValid(), true); |
|
130 | $attribute2 = new Attribute('bar', new AlwaysValid(), true); |
|
131 | ||
132 | $attributeSet = new AttributeSet($attribute1, $attribute2); |
|
133 | ||
134 | $this->assertFalse($attributeSet->validate($input)); |
|
135 | } |
|
136 | ||
137 | /** |
|
138 | * @expectedException \Respect\Validation\Exceptions\AttributeException |
|
@@ 141-150 (lines=10) @@ | ||
138 | * @expectedException \Respect\Validation\Exceptions\AttributeException |
|
139 | * @expectedExceptionMessage Attribute foo must be present |
|
140 | */ |
|
141 | public function testShouldCheckAttributesAndUseChildValidators() |
|
142 | { |
|
143 | $input = (object)[]; |
|
144 | ||
145 | $attribute1 = new Attribute('foo', new AlwaysValid(), true); |
|
146 | $attribute2 = new Attribute('bar', new AlwaysValid(), true); |
|
147 | ||
148 | $attributeSet = new AttributeSet($attribute1, $attribute2); |
|
149 | $attributeSet->check($input); |
|
150 | } |
|
151 | ||
152 | public function testShouldAssertGetAttributesInException() |
|
153 | { |
|
@@ 220-232 (lines=13) @@ | ||
217 | $this->assertTrue($attributeSet->validate($input)); |
|
218 | } |
|
219 | ||
220 | public function testShouldByAbleToAssert() |
|
221 | { |
|
222 | $input = (object)[ |
|
223 | 'foo' => 42, |
|
224 | ]; |
|
225 | ||
226 | $attribute1 = new Attribute('foo', new AlwaysValid(), true); |
|
227 | $attribute2 = new Attribute('bar', new AlwaysValid(), false); |
|
228 | ||
229 | $attributeSet = new AttributeSet($attribute1, $attribute2); |
|
230 | ||
231 | $attributeSet->assert($input); |
|
232 | } |
|
233 | } |
|
234 |