Validation options not working [solved]

I have problems generating errors in a model by configuring rules/validators.

In Yii 1.1 i used option “allowEmpty”=>false in validators to require them to have a valid value, what should I use in Yii2?

Also the integer validator has problems, is set option “integerOnly”=>true, but that does not give error when I give the attribute a string.

The model:

    namespace app\models;

    class Test extends \yii\base\Model {

        public $date;
        public $age;

        public function rules() {
            return [
                // This should give error if value is null because of skipOnEmpty=false
                [['date'], 'date', 'format'=>'php:Y-m-d', 'skipOnEmpty'=>false],

                // This should give error if value is string "20"
                [['age'], 'integer', 'integerOnly'=>true],
            ];
        }
    }

The code I test with gives empty array in last line:

            $model = new Test();
            $model->age = '20';  // integer validator option "integerOnly"=>true should cause error
            $model->date = null; // skipOnEmpty=>false should cause error (empty not allowed)
            $model->validate();
            var_dump($model->getErrors());

I have tested this code on Yii 2.0.35, 2.0.48 and 2.0.48.1.

I have found out things!
To be able to not allow an attribute to be empty, the option to set this in validators in general is taken away, and you need to use the “required” validator.

About the “integerOnly”=>true option: All validators inherit the skipOnEmpty property which default value is true. That means “integerOnly”=>true does not apply its purpose when the attribute value is empty, (meaning null or empty string). So “integerOnly”=>true will only be in effect when the value is string (not empty), boolean, float etc.

Took some time to find out. Hope this post helps others!