/**
  * Public validation function to validate some object
  *
  * @param mixed $object Object to validate
  *
  * @return bool
  */
 public function isThisValid($object = null)
 {
     $objectData = $this->getObjectData($object);
     $this->lastState = $this->getState($object);
     $rules = Arr::mergeByCondition($this->rules, $this->lastState);
     $ruleParser = new RuleParser();
     $rules = $ruleParser->parse($rules, $this->templateReplacements);
     $rules = $this->preProcessRules($rules, $objectData);
     //Registering custom validation rules
     foreach ($this->customRules as $ruleName => $customRuleData) {
         ValidationRuleRegistry::registerClosure($customRuleData[0], $customRuleData[1]);
     }
     //Creating validator
     $validatorFactory = new ValidatorFactory($this->validatorFactory);
     $validator = $validatorFactory->create($rules, $objectData);
     $validator->setCustomMessages($this->preProcessValidationErrorMessages($this->customValidationMessages, $rules, $objectData));
     $this->setupValidator($validator);
     $method_name = 'setupValidatorFor' . Str::studly($this->lastState);
     if (method_exists($this, $method_name)) {
         $this->{$method_name}($validator);
     }
     $this->validationPassed = !$validator->fails();
     if ($this->validationPassed) {
         $this->dataStorage = new ArrayDataStorage($this->keyCase);
         $this->dataStorage->setItems(Arr::only($objectData, array_keys($rules)));
         $this->failedMessages = new MessageBag();
         $this->failedRules = [];
     } else {
         $this->failedMessages = $validator->getMessageBag();
         $this->failedRules = $validator->failed();
         $this->dataStorage = null;
     }
     return $this->validationPassed;
 }
 /**
  * @throws Exception
  */
 public function testSetKeyNormalizerException()
 {
     $this->storage->setItems(['testItem1' => 'testValue1', 'testItem2' => 'testValue2']);
     $this->setExpectedException(Exception::class);
     $this->storage->setKeyNormalizer(ArrayDataStorage::KEY_CASE_NO_CHANGE);
 }