mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Added type hinting to Model::validator()
Added missing param and fixed typo in method's phpdoc. Used 'assertSame' and 'assertNotSame'. Removed piped NULL type from phpdoc. Simplify condition in Model::validator()
This commit is contained in:
parent
ffcf71c810
commit
7f0085cd4e
2 changed files with 32 additions and 8 deletions
|
@ -3424,21 +3424,18 @@ class Model extends Object implements CakeEventListener {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retunrs an instance of a model validator for this class
|
||||
* Returns an instance of a model validator for this class
|
||||
*
|
||||
* @param ModelValidator Model validator instance.
|
||||
* If null a new ModelValidator instance will be made using current model object
|
||||
* @return ModelValidator
|
||||
*/
|
||||
public function validator($instance = null) {
|
||||
if ($instance instanceof ModelValidator) {
|
||||
return $this->_validator = $instance;
|
||||
}
|
||||
|
||||
if (empty($this->_validator) && is_null($instance)) {
|
||||
public function validator(ModelValidator $instance = null) {
|
||||
if ($instance) {
|
||||
$this->_validator = $instance;
|
||||
} elseif (!$this->_validator) {
|
||||
$this->_validator = new ModelValidator($this);
|
||||
}
|
||||
|
||||
return $this->_validator;
|
||||
}
|
||||
|
||||
|
|
|
@ -2115,6 +2115,33 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$this->assertTrue($result instanceof CakeValidationSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that validator override works as expected
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidatorOverride() {
|
||||
$TestModel = new Article();
|
||||
$ValidatorA = new ModelValidator($TestModel);
|
||||
$ValidatorB = new ModelValidator($TestModel);
|
||||
|
||||
$TestModel->validator($ValidatorA);
|
||||
$TestModel->validator($ValidatorB);
|
||||
|
||||
$this->assertSame($ValidatorB, $TestModel->validator());
|
||||
$this->assertNotSame($ValidatorA, $TestModel->validator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that type hint exception is thrown
|
||||
*
|
||||
* @expectedException PHPUnit_Framework_Error
|
||||
* @return void
|
||||
*/
|
||||
public function testValidatorTypehintException() {
|
||||
$Validator = new ModelValidator('asdasds');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that altering data in a beforeValidate callback will lead to saving those
|
||||
* values in database, this time with belongsTo associations
|
||||
|
|
Loading…
Reference in a new issue