Skip to content

Commit

Permalink
Merge pull request #5 from harryosmar/json-encode
Browse files Browse the repository at this point in the history
add parameter `$errorCode` null
  • Loading branch information
harryosmar authored Mar 11, 2018
2 parents 1615abb + 28058ff commit b543a07
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Contracts/PhpRestfulApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function withCollection($data, $transformer, $code = 200, $resourceKey =
* @param array $headers
* @return mixed
*/
public function withError($message, int $statusCode, $errorCode, array $headers = []);
public function withError($message, int $statusCode, $errorCode = null, array $headers = []);

/**
* Generates a response with a 403 HTTP header and a given message.
Expand All @@ -65,7 +65,7 @@ public function withError($message, int $statusCode, $errorCode, array $headers
* @param array $headers
* @return mixed
*/
public function errorForbidden(string $message = '', $errorCode, array $headers = []);
public function errorForbidden(string $message = '', $errorCode = null, array $headers = []);

/**
* Generates a response with a 500 HTTP header and a given message.
Expand All @@ -75,7 +75,7 @@ public function errorForbidden(string $message = '', $errorCode, array $headers
* @param array $headers
* @return mixed
*/
public function errorInternalError(string $message = '', $errorCode, array $headers = []);
public function errorInternalError(string $message = '', $errorCode = null, array $headers = []);

/**
* Generates a response with a 404 HTTP header and a given message.
Expand All @@ -85,7 +85,7 @@ public function errorInternalError(string $message = '', $errorCode, array $head
* @param array $headers
* @return mixed
*/
public function errorNotFound(string $message = '', $errorCode, array $headers = []);
public function errorNotFound(string $message = '', $errorCode = null, array $headers = []);

/**
* Generates a response with a 401 HTTP header and a given message.
Expand All @@ -95,7 +95,7 @@ public function errorNotFound(string $message = '', $errorCode, array $headers =
* @param array $headers
* @return mixed
*/
public function errorUnauthorized(string $message = '', $errorCode, array $headers = []);
public function errorUnauthorized(string $message = '', $errorCode = null, array $headers = []);

/**
* Generates a response with a 400 HTTP header and a given message.
Expand All @@ -105,7 +105,7 @@ public function errorUnauthorized(string $message = '', $errorCode, array $heade
* @param array $headers
* @return mixed
*/
public function errorWrongArgs(array $message, $errorCode, array $headers = []);
public function errorWrongArgs(array $message, $errorCode = null, array $headers = []);

/**
* Generates a response with a 410 HTTP header and a given message.
Expand All @@ -115,7 +115,7 @@ public function errorWrongArgs(array $message, $errorCode, array $headers = []);
* @param array $headers
* @return mixed
*/
public function errorGone(string $message = '', $errorCode, array $headers = []);
public function errorGone(string $message = '', $errorCode = null, array $headers = []);

/**
* Generates a response with a 405 HTTP header and a given message.
Expand All @@ -125,7 +125,7 @@ public function errorGone(string $message = '', $errorCode, array $headers = [])
* @param array $headers
* @return mixed
*/
public function errorMethodNotAllowed(string $message = '', $errorCode, array $headers = []);
public function errorMethodNotAllowed(string $message = '', $errorCode = null, array $headers = []);

/**
* Generates a Response with a 431 HTTP header and a given message.
Expand All @@ -135,7 +135,7 @@ public function errorMethodNotAllowed(string $message = '', $errorCode, array $h
* @param array $headers
* @return mixed
*/
public function errorUnwillingToProcess(string $message = '', $errorCode, array $headers = []);
public function errorUnwillingToProcess(string $message = '', $errorCode = null, array $headers = []);

/**
* Generates a Response with a 422 HTTP header and a given message.
Expand All @@ -145,5 +145,5 @@ public function errorUnwillingToProcess(string $message = '', $errorCode, array
* @param array $headers
* @return mixed
*/
public function errorUnprocessable(string $message = '', $errorCode, array $headers = []);
public function errorUnprocessable(string $message = '', $errorCode = null, array $headers = []);
}
2 changes: 2 additions & 0 deletions tests/unit/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpRestfulApiResponse\Tests\unit\Lib\Book;
use ReflectionClass;
use InvalidArgumentException;
use Zend\Diactoros\Response\ArraySerializer;

class ResponseTest extends Base
{
Expand All @@ -31,6 +32,7 @@ public function test_withArray()
/** @var Response $response */
$response = $this->response->withArray(['status' => 'success'], 200);
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('{"status":"success"}', ArraySerializer::toArray($response)['body']);
$this->assertEquals('{"status":"success"}', $response->getBody()->__toString());
}

Expand Down

0 comments on commit b543a07

Please sign in to comment.