Pantheon\Terminus\Models\SSHKey::delete PHP Method

delete() public method

Deletes a specific SSH key
public delete ( ) : array
return array
    public function delete()
    {
        $response = $this->request->request('users/' . $this->user->id . '/keys/' . $this->id, ['method' => 'delete']);
        if ($response['status_code'] !== 200) {
            throw new TerminusException('There was an problem deleting the SSH key.');
        }
    }

Usage Example

 public function testDeleteFail()
 {
     $collection = $this->getMockBuilder(SSHKeys::class)->disableOriginalConstructor()->getMock();
     $collection->expects($this->once())->method('getUser')->willReturn((object) ['id' => '123']);
     $sshkey = new SSHKey((object) ['id' => '456'], ['collection' => $collection]);
     $this->request->expects($this->at(0))->method('request')->with("users/123/keys/456", ['method' => 'delete'])->willReturn(['status_code' => 404]);
     $sshkey->setRequest($this->request);
     $this->setExpectedException(TerminusException::class);
     $sshkey->delete();
 }