App\Services\Form\Deployment\DeploymentForm::save PHP Метод

save() публичный Метод

Create a new deployment.
public save ( array $input ) : boolean
$input array Data to create a deployment
Результат boolean
    public function save(array $input)
    {
        if (!$this->valid($input)) {
            return false;
        }
        $deployment = DB::transaction(function () use($input) {
            $project = $this->project->byId($input['project_id']);
            $maxDeployment = $project->getMaxDeployment();
            $input['number'] = $maxDeployment->number + 1;
            $project->addDeployment($input);
            $project->updateMaxDeployment(['number' => $input['number']]);
            $deployment = $project->getDeploymentByNumber($input['number']);
            return $deployment;
        });
        if (!$deployment) {
            return false;
        }
        $this->deployCommander->{$input}['task']($deployment);
        return true;
    }

Usage 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);
     $form = new DeploymentForm($this->mockValidator, $this->mockProjectRepository, $this->mockDeployCommander);
     $result = $form->save([]);
     $this->assertFalse($result, 'Expected save to fail.');
 }