then() public method

Hand off the response functions to the original promise and return a custom response or exception.
public then ( callable $onFulfilled = null, callable $onRejected = null )
$onFulfilled callable - function to be called if the promise is fulfilled
$onRejected callable - function to be called if the promise is rejected
 public function testUnsuccessfulAsyncRequestWithThen()
 {
     $responseBody = ['results' => 'failed'];
     $exceptionMock = Mockery::mock('Http\\Client\\Exception\\HttpException');
     $exceptionMock->shouldReceive('getResponse->getStatusCode')->andReturn(500);
     $exceptionMock->shouldReceive('getResponse->getBody->__toString')->andReturn(json_encode($responseBody));
     $guzzlePromise = new GuzzleRejectedPromise($exceptionMock);
     $promise = new SparkPostPromise(new GuzzleAdapterPromise($guzzlePromise, $this->resource->buildRequest('POST', 'transmissions', $this->postTransmissionPayload, [])));
     $promise->then(null, function ($exception) use($responseBody) {
         $this->assertEquals(500, $exception->getCode());
         $this->assertEquals($responseBody, $exception->getBody());
     })->wait();
 }