Skip to content

Commit b543a07

Browse files
authored
Merge pull request #5 from harryosmar/json-encode
add parameter `$errorCode` null
2 parents 1615abb + 28058ff commit b543a07

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/Contracts/PhpRestfulApiResponse.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function withCollection($data, $transformer, $code = 200, $resourceKey =
5555
* @param array $headers
5656
* @return mixed
5757
*/
58-
public function withError($message, int $statusCode, $errorCode, array $headers = []);
58+
public function withError($message, int $statusCode, $errorCode = null, array $headers = []);
5959

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

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

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

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

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

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

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

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

140140
/**
141141
* Generates a Response with a 422 HTTP header and a given message.
@@ -145,5 +145,5 @@ public function errorUnwillingToProcess(string $message = '', $errorCode, array
145145
* @param array $headers
146146
* @return mixed
147147
*/
148-
public function errorUnprocessable(string $message = '', $errorCode, array $headers = []);
148+
public function errorUnprocessable(string $message = '', $errorCode = null, array $headers = []);
149149
}

tests/unit/ResponseTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PhpRestfulApiResponse\Tests\unit\Lib\Book;
1313
use ReflectionClass;
1414
use InvalidArgumentException;
15+
use Zend\Diactoros\Response\ArraySerializer;
1516

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

0 commit comments

Comments
 (0)