Skip to content

Commit

Permalink
Merge pull request #71 from vanilla/fix/php74-issues
Browse files Browse the repository at this point in the history
Fix PHP deprecation
  • Loading branch information
tburry committed Dec 1, 2019
2 parents 4137672 + 04091b0 commit dded822
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ValidationField.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function val($key, $default = null) {
* @return bool Returns **true** if the field has a key or **false** otherwise.
*/
public function hasVal($key) {
return array_key_exists($key, $this->field);
return isset($this->field[$key]) || (is_array($this->field) && array_key_exists($key, $this->field));
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/RealWorldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,19 @@ public function testNestedMergedFilteredAdd() {
$validatedData = $filteredSchema->validate($data);
$this->assertEquals($expectedData, $validatedData);
}

/**
* A nested schema object should have its default value respected.
*/
public function testNestedDefaultRequired() {
$schema = Schema::parse([
'letter' => Schema::parse([
'default' => 'a',
'type' => 'string',
])
]);
$data = [];
$data = $schema->validate($data);
$this->assertEquals(['letter' => 'a'], $data);
}
}

0 comments on commit dded822

Please sign in to comment.