mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-14 03:07:53 +01:00
Fixes #15553: Fixed yii\validators\NumberValidator incorrectly validate resource
This commit is contained in:
committed by
Alexander Makarov
parent
dbcb66b87a
commit
eb57d4191c
@@ -298,4 +298,45 @@ class NumberValidatorTest extends TestCase
|
||||
$value = new \stdClass();
|
||||
$this->assertFalse($val->validate($value));
|
||||
}
|
||||
|
||||
public function testValidateResource()
|
||||
{
|
||||
$val = new NumberValidator();
|
||||
$fp = fopen('php://stdin', 'r');
|
||||
$this->assertFalse($val->validate($fp));
|
||||
|
||||
$model = new FakedValidationModel();
|
||||
$model->attr_number = $fp;
|
||||
$val->validateAttribute($model, 'attr_number');
|
||||
$this->assertTrue($model->hasErrors('attr_number'));
|
||||
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
public function testValidateToString()
|
||||
{
|
||||
$val = new NumberValidator();
|
||||
$object = new TestClass('10');
|
||||
$this->assertTrue($val->validate($object));
|
||||
|
||||
$model = new FakedValidationModel();
|
||||
$model->attr_number = $object;
|
||||
$val->validateAttribute($model, 'attr_number');
|
||||
$this->assertFalse($model->hasErrors('attr_number'));
|
||||
}
|
||||
}
|
||||
|
||||
class TestClass
|
||||
{
|
||||
public $foo;
|
||||
|
||||
public function __construct($foo)
|
||||
{
|
||||
$this->foo = $foo;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->foo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user