App\Services\Api\JsonRpc::rollback PHP Method

rollback() public method

Roll back a deployment.
public rollback ( integer $project_id ) : Deployment
$project_id integer
return app\models\Deployment
    public function rollback($project_id)
    {
        $input = ['status' => null, 'message' => null, 'project_id' => $project_id, 'user_id' => Auth::guard('api')->user()->id, 'task' => 'rollback'];
        if ($this->deploymentForm->save($input)) {
            $project = $this->project->byId($project_id);
            $deployment = $project->getLastDeployment();
            return $deployment;
        } else {
            throw new InvalidArgumentException($this->deploymentForm->errors());
        }
    }

Usage Example

Example #1
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function test_Should_ThrowWException_When_RollbackProcedureFails()
 {
     $this->mockAuthGuard->shouldReceive('user')->andReturn(new App\Models\User());
     Auth::shouldReceive('guard')->andReturn($this->mockAuthGuard);
     $this->mockDeploymentForm->shouldReceive('save')->once()->andReturn(false);
     $this->mockDeploymentForm->shouldReceive('errors')->once()->andReturn(new Illuminate\Support\MessageBag());
     $jsonRpc = new JsonRpc($this->mockProjectRepository, $this->mockDeploymentForm);
     $jsonRpc->rollback(1);
 }