Skip to content

Commit 472be85

Browse files
committed
Merge branch '0.7' into 0.8
2 parents 378e114 + fa90e9a commit 472be85

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

library/Rules/AbstractRelated.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ public function check($input)
6565

6666
public function validate($input)
6767
{
68-
$hasReference = $this->hasReference($input);
68+
if ($input === '') {
69+
return true;
70+
}
6971

72+
$hasReference = $this->hasReference($input);
7073
if ($this->mandatory && !$hasReference) {
7174
return false;
7275
}
7376

74-
return $this->decision('validate', $hasReference, $input) || $this->getReferenceValue($input) === '';
77+
return $this->decision('validate', $hasReference, $input);
7578
}
7679
}

tests/Rules/KeyTest.php

+34-5
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,43 @@ public function testArrayWithPresentKeyShouldReturnTrue()
1313
$this->assertTrue($validator->validate($obj));
1414
}
1515

16+
public function testEmptyInputMustReturnTrue()
17+
{
18+
$validator = new Key('someEmptyKey');
19+
$input = '';
20+
21+
$this->assertTrue($validator->assert($input));
22+
$this->assertTrue($validator->check($input));
23+
$this->assertTrue($validator->validate($input));
24+
}
25+
1626
public function testArrayWithEmptyKeyShouldReturnTrue()
1727
{
1828
$validator = new Key('someEmptyKey');
19-
$obj = array();
20-
$obj['someEmptyKey'] = '';
21-
$this->assertTrue($validator->assert($obj));
22-
$this->assertTrue($validator->check($obj));
23-
$this->assertTrue($validator->validate($obj));
29+
$input = array();
30+
$input['someEmptyKey'] = '';
31+
32+
$this->assertTrue($validator->assert($input));
33+
$this->assertTrue($validator->check($input));
34+
$this->assertTrue($validator->validate($input));
35+
}
36+
37+
public function testShouldHaveTheSameReturnValueForAllValidators()
38+
{
39+
$rule = new Key('key', new NotEmpty());
40+
$input = array('key' => '');
41+
42+
try {
43+
$rule->assert($input);
44+
$this->fail('`assert()` must throws exception');
45+
} catch (\Exception $e) {}
46+
47+
try {
48+
$rule->check($input);
49+
$this->fail('`check()` must throws exception');
50+
} catch (\Exception $e) {}
51+
52+
$this->assertFalse($rule->validate($input));
2453
}
2554

2655
/**

0 commit comments

Comments
 (0)