Skip to content

Commit f49b355

Browse files
Ajutes e novos testes.
1 parent e524223 commit f49b355

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/AttributeAccessors/AttributeWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function validate($target) {
107107
* @return mixed|null
108108
*/
109109
protected function get($target) {
110-
if (!array_key_exists($this->attribute, $target)) {
110+
if (!is_array($target) || !array_key_exists($this->attribute, $target)) {
111111
return AttributeNotExists::instance();
112112
}
113113

src/AttributeAccessors/NestedAttributeWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function cast(array $target) {
4747
* @return mixed|null
4848
*/
4949
protected function get($target) {
50-
if (!array_key_exists($this->attribute, $target)) {
50+
if (!is_array($target) || !array_key_exists($this->attribute, $target)) {
5151
return AttributeNotExists::instance();
5252
}
5353

test/ValidatorTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,28 @@
55

66
class ValidatorTest extends \PHPUnit_Framework_TestCase {
77

8-
public function testValidator() {
8+
public function testArray() {
9+
$validator = new Validator();
10+
$validator
11+
->addRules([
12+
"*.id" => "required|numeric",
13+
"*.ok" => "required|boolean",
14+
])
15+
->addRule("*.msg", "present");
16+
17+
$this->assertEmpty($validator->validate([["id" => "1", "ok" => false, "msg" => null]]));
18+
$this->assertEmpty($validator->validate([["id" => 1, "ok" => true, "msg" => ""]]));
19+
$this->assertEmpty($validator->validate([["id" => 1, "ok" => true, "msg" => "Err"]]));
20+
$this->assertEmpty($validator->validate([]));
21+
22+
$this->assertNotEmpty($validator->validate([["id" => null, "ok" => true, "msg" => "Err"]]));
23+
$this->assertNotEmpty($validator->validate([["ok" => true, "msg" => "Err"]]));
24+
$this->assertNotEmpty($validator->validate([["id" => 1, "ok" => true]]));
25+
$this->assertNotEmpty($validator->validate(["id" => 1, "ok" => true, "msg" => "Err"]));
26+
$this->assertNotEmpty($validator->validate(null));
27+
}
28+
29+
public function atestValidator() {
930
//Loader::load(Validator::class);
1031

1132
$validator = new Validator();

0 commit comments

Comments
 (0)