From a81480d309cfea6a080982a5f4ffcdc3c97c0de2 Mon Sep 17 00:00:00 2001 From: Suralc Date: Tue, 6 Aug 2013 19:56:05 +0200 Subject: [PATCH] Improved ValidatorTest organization. --- .../validators/models/FakedValidationModel.php | 55 ++++++++++++++++++++++ .../framework/validators/BooleanValidatorTest.php | 3 +- .../framework/validators/CompareValidatorTest.php | 2 +- .../framework/validators/DateValidatorTest.php | 2 +- .../framework/validators/EmailValidatorTest.php | 1 + .../framework/validators/FakedValidationModel.php | 36 -------------- .../framework/validators/NumberValidatorTest.php | 1 + .../framework/validators/StringValidatorTest.php | 1 + .../unit/framework/validators/UrlValidatorTest.php | 3 +- 9 files changed, 62 insertions(+), 42 deletions(-) create mode 100644 tests/unit/data/validators/models/FakedValidationModel.php delete mode 100644 tests/unit/framework/validators/FakedValidationModel.php diff --git a/tests/unit/data/validators/models/FakedValidationModel.php b/tests/unit/data/validators/models/FakedValidationModel.php new file mode 100644 index 0000000..1e3366c --- /dev/null +++ b/tests/unit/data/validators/models/FakedValidationModel.php @@ -0,0 +1,55 @@ + 'reqTest'), + array('val_attr_c', 'integer'), + ); + } + + public function inlineVal($attribute, $params = array()) + { + return true; + } + + public function __get($name) + { + if (stripos($name, 'attr') === 0) { + return isset($this->attr[$name]) ? $this->attr[$name] : null; + } + + return parent::__get($name); + } + + public function __set($name, $value) + { + if (stripos($name, 'attr') === 0) { + $this->attr[$name] = $value; + } else { + parent::__set($name, $value); + } + } + + public function getAttributeLabel($attr) + { + return $attr; + } +} \ No newline at end of file diff --git a/tests/unit/framework/validators/BooleanValidatorTest.php b/tests/unit/framework/validators/BooleanValidatorTest.php index e3fa3e5..f37b39a 100644 --- a/tests/unit/framework/validators/BooleanValidatorTest.php +++ b/tests/unit/framework/validators/BooleanValidatorTest.php @@ -1,11 +1,10 @@ attr[$name]) ? $this->attr[$name] : null; - } - - return parent::__get($name); - } - - public function __set($name, $value) - { - if (stripos($name, 'attr') === 0) { - $this->attr[$name] = $value; - } else { - parent::__set($name, $value); - } - } - - public function getAttributeLabel($attr) - { - return $attr; - } -} \ No newline at end of file diff --git a/tests/unit/framework/validators/NumberValidatorTest.php b/tests/unit/framework/validators/NumberValidatorTest.php index 279b89e..4868503 100644 --- a/tests/unit/framework/validators/NumberValidatorTest.php +++ b/tests/unit/framework/validators/NumberValidatorTest.php @@ -4,6 +4,7 @@ namespace yiiunit\framework\validators; use yii\validators\NumberValidator; +use yiiunit\data\validators\models\FakedValidationModel; use yiiunit\TestCase; class NumberValidatorTest extends TestCase diff --git a/tests/unit/framework/validators/StringValidatorTest.php b/tests/unit/framework/validators/StringValidatorTest.php index e7c68bc..c7d2889 100644 --- a/tests/unit/framework/validators/StringValidatorTest.php +++ b/tests/unit/framework/validators/StringValidatorTest.php @@ -4,6 +4,7 @@ namespace yiiunit\framework\validators; use yii\validators\StringValidator; +use yiiunit\data\validators\models\FakedValidationModel; use yiiunit\TestCase; class StringValidatorTest extends TestCase diff --git a/tests/unit/framework/validators/UrlValidatorTest.php b/tests/unit/framework/validators/UrlValidatorTest.php index f585590..7b618c1 100644 --- a/tests/unit/framework/validators/UrlValidatorTest.php +++ b/tests/unit/framework/validators/UrlValidatorTest.php @@ -1,10 +1,9 @@