App\Services\Form\Project\ProjectForm::save PHP Method

save() public method

Create a new project.
public save ( array $input ) : boolean
$input array Data to create a project
return boolean
    public function save(array $input)
    {
        $input['recipe_id'] = explode(',', $input['recipe_id_order']);
        if (!$this->valid($input)) {
            return false;
        }
        DB::transaction(function () use($input) {
            $projectAttribute = new \App\Entities\ProjectAttribute\ProjectAttributeEntity();
            if (!empty($input['deploy_path'])) {
                $projectAttribute->setDeployPath($input['deploy_path']);
            }
            $input['attributes'] = $projectAttribute;
            if (isset($input['keep_last_deployment'])) {
                $input['keep_last_deployment'] = true;
            } else {
                $input['keep_last_deployment'] = false;
            }
            $project = $this->project->create($input);
            $project->addMaxDeployment();
            $project->syncRecipes($input['recipe_id']);
        });
        return true;
    }

Usage Example

Example #1
0
 public function test_Should_FailToSave_When_ValidationFails()
 {
     $this->mockValidator->shouldReceive('with')->once()->andReturn($this->mockValidator);
     $this->mockValidator->shouldReceive('passes')->once()->andReturn(false);
     $input = ['recipe_id_order' => '3,1,2', 'deploy_path' => ''];
     $form = new ProjectForm($this->mockValidator, $this->mockProjectRepository);
     $result = $form->save($input);
     $this->assertFalse($result, 'Expected save to fail.');
 }