Skip to content

Commit a0949a1

Browse files
committed
Merge branch 'hotfix/14'
Close #14
2 parents f5e983b + c3b3848 commit a0949a1

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/ZF/ApiProblem/ApiProblemResponse.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,25 @@ public function getHeaders()
6161
}
6262
return $headers;
6363
}
64+
65+
/**
66+
* Override reason phrase handling
67+
*
68+
* If no corresponding reason phrase is available for the current status
69+
* code, return "Unknown Error".
70+
*
71+
* @return string
72+
*/
73+
public function getReasonPhrase()
74+
{
75+
if (! empty($this->reasonPhrase)) {
76+
return $this->reasonPhrase;
77+
}
78+
79+
if (isset($this->recommendedReasonPhrases[$this->statusCode])) {
80+
return $this->recommendedReasonPhrases[$this->statusCode];
81+
}
82+
83+
return 'Unknown Error';
84+
}
6485
}

test/ZFTest/ApiProblem/ApiProblemResponseTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,13 @@ public function testComposeApiProblemIsAccessible()
5656
$response = new ApiProblemResponse($apiProblem);
5757
$this->assertSame($apiProblem, $response->getApiProblem());
5858
}
59+
60+
/**
61+
* @group 14
62+
*/
63+
public function testOverridesReasonPhraseIfStatusCodeIsUnknown()
64+
{
65+
$response = new ApiProblemResponse(new ApiProblem(7, 'Random error'));
66+
$this->assertContains('Unknown', $response->getReasonPhrase());
67+
}
5968
}

0 commit comments

Comments
 (0)