/**
  * @depends testSetAndGet
  */
 public function testResolveByWorkflowIdAndModel()
 {
     $model2 = new WorkflowModelTestItem();
     $model2->lastName = 'Engel';
     $model2->string = 'string';
     $saved = $model2->save();
     $this->assertTrue($saved);
     $savedWorkflows = SavedWorkflow::getByName('some workflow');
     $models = WorkflowModelTestItem::getByLastName('Green');
     //Test when there should be an existing model.
     $byTimeWorkflowInQueue = ByTimeWorkflowInQueue::resolveByWorkflowIdAndModel($savedWorkflows[0], $models[0]);
     $this->assertTrue($byTimeWorkflowInQueue->id > 0);
     $savedWorkflow2 = new SavedWorkflow();
     $savedWorkflow2->name = 'some workflow2';
     $savedWorkflow2->description = 'description';
     $savedWorkflow2->moduleClassName = 'moduleClassName';
     $savedWorkflow2->triggerOn = Workflow::TRIGGER_ON_NEW;
     $savedWorkflow2->type = 'some type';
     $savedWorkflow2->serializedData = serialize(array('something'));
     $saved = $savedWorkflow2->save();
     $this->assertTrue($saved);
     //Test when there should not be an existing ByTimeWorkflowInQueue because there is no existing
     //workflow attached to the model
     $byTimeWorkflowInQueue = ByTimeWorkflowInQueue::resolveByWorkflowIdAndModel($savedWorkflow2, $models[0]);
     $this->assertFalse($byTimeWorkflowInQueue->id > 0);
     //Test where we use an existing savedWorkflow but the model is not on it.
     $byTimeWorkflowInQueue = ByTimeWorkflowInQueue::resolveByWorkflowIdAndModel($savedWorkflows[0], $model2);
     $this->assertFalse($byTimeWorkflowInQueue->id > 0);
 }
 /**
  * @param Workflow $workflow
  * @param RedBeanModel $model
  * @throws FailedToSaveModelException
  */
 protected static function processToByTimeWorkflowInQueue(Workflow $workflow, RedBeanModel $model)
 {
     assert('$workflow->getId() > 0');
     try {
         $byTimeWorkflowInQueue = ByTimeWorkflowInQueue::resolveByWorkflowIdAndModel(SavedWorkflow::getById((int) $workflow->getId()), $model);
         $byTimeWorkflowInQueue->processDateTime = static::resolveProcessDateTimeByWorkflowAndModel($workflow, $model);
         $saved = $byTimeWorkflowInQueue->save();
         if (!$saved) {
             throw new FailedToSaveModelException();
         }
     } catch (ValueForProcessDateTimeIsNullException $e) {
         //For now just log this exception. If this exception is thrown it means a date or dateTime
         //somehow was set to empty, so we can't properly process this.
         WorkflowUtil::handleProcessingException($e, 'application.modules.workflows.utils.SavedWorkflowsUtil.processToByTimeWorkflowInQueue');
     }
 }