public function testIfWillSetDeleteScenarioOnDeletedObject()
 {
     $model = new BaseAttributesScenario();
     (new EntityManager($model))->save();
     (new EntityManager($model))->delete();
     $this->assertSame(ScenarioManager::getScenario($model), ScenariosInterface::Delete);
 }
 public function testIfWillSetDeleteScenarioOnDeletedObject()
 {
     $model = new DocumentBaseAttributes();
     $model->save();
     $model->delete();
     $this->assertSame(ScenarioManager::getScenario($model), ScenariosInterface::Delete);
 }
Exemple #3
0
 private function validateEntity($name, $validators)
 {
     $valid = [];
     foreach ($validators as $validatorMeta) {
         // Filter out validators based on scenarios
         if (!empty($validatorMeta->on)) {
             $on = (array) $validatorMeta->on;
             $enabled = false;
             foreach ($on as $scenario) {
                 if ($scenario === ScenarioManager::getScenario($this->model)) {
                     $enabled = true;
                     break;
                 }
             }
             if (!$enabled) {
                 continue;
             }
         }
         if (!empty($validatorMeta->except)) {
             $except = (array) $validatorMeta->except;
             $enabled = true;
             foreach ($except as $scenario) {
                 if ($scenario === ScenarioManager::getScenario($this->model)) {
                     $enabled = false;
                     break;
                 }
             }
             if (!$enabled) {
                 continue;
             }
         }
         // Create validator and validate
         $validator = Factory::create($this->model, $validatorMeta, $name);
         if ($validator->isValid($this->model, $name)) {
             $valid[] = true;
         } else {
             $valid[] = false;
             $this->errors[$name] = array_merge($this->errors[$name], $validator->getErrors());
             // Set errors to model instance if it implements ValidatableInterface
             if ($this->model instanceof ValidatableInterface) {
                 $this->model->setErrors($this->errors);
             }
         }
     }
     return count($valid) === array_sum($valid);
 }