Navigation Menu

Skip to content

Commit

Permalink
Add accessor for protected properties of ValidationRule
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Feb 6, 2015
1 parent 0778188 commit a89bf35
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Validation/ValidationRule.php
Expand Up @@ -193,4 +193,18 @@ protected function _addValidatorProps($validator = [])
}
}
}

/**
* Returns the value of a property by name
*
* @param string $property The name of the property to retrieve.
* @return mixed
*/
public function get($property)
{
$property = '_' . $property;
if (isset($this->{$property})) {
return $this->{$property};
}
}
}
21 changes: 21 additions & 0 deletions tests/TestCase/Validation/ValidationRuleTest.php
Expand Up @@ -171,4 +171,25 @@ public function testCallableOn()
]);
$this->assertTrue($Rule->process($data, $providers, ['newRecord' => true]));
}

/**
* testGet
*
* @return void
*/
public function testGet() {
$Rule = new ValidationRule(['rule' => 'myTestRule', 'message' => 'foo']);

$this->assertEquals('myTestRule', $Rule->get('rule'));
$this->assertEquals('foo', $Rule->get('message'));
$this->assertEquals('default', $Rule->get('provider'));
$this->assertEquals([], $Rule->get('pass'));
$this->assertNull($Rule->get('non-existent'));

$Rule = new ValidationRule(['rule' => ['myTestRule2', 'param'], 'message' => 'bar']);

$this->assertEquals('myTestRule2', $Rule->get('rule'));
$this->assertEquals('bar', $Rule->get('message'));
$this->assertEquals(['param'], $Rule->get('pass'));
}
}

0 comments on commit a89bf35

Please sign in to comment.