Repository navigation
Expand file tree
/
Copy pathApiProblemTest.php
More file actions
41 lines (33 loc) · 1.55 KB
/
Copy pathApiProblemTest.php
File metadata and controls
41 lines (33 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace NilPortugues\Tests\Api\Problem;
use NilPortugues\Api\Problem\ApiProblem;
class ApiProblemTest extends \PHPUnit_Framework_TestCase
{
public function testItCanConstruct()
{
$problem = new ApiProblem(404, 'User with id 5 not found.', 'Not Found', 'user.not_found', ['errors' => ['more']]);
$this->assertEquals(404, $problem->status());
$this->assertEquals('User with id 5 not found.', $problem->detail());
$this->assertEquals('Not Found', $problem->title());
$this->assertEquals('user.not_found', $problem->type());
$this->assertEquals(['errors' => ['more']], $problem->additionalDetails());
}
public function testItCanConstructFromException()
{
$exception = new \Exception('User with id 5 not found.', 404);
$problem = ApiProblem::fromException($exception);
$this->assertEquals(404, $problem->status());
$this->assertEquals('User with id 5 not found.', $problem->detail());
$this->assertEquals('Not Found', $problem->title());
$this->assertEquals(ApiProblem::RFC2616, $problem->type());
}
public function testItCanUseExceptionName()
{
$exception = new \PDOException();
$problem = ApiProblem::fromException($exception);
$this->assertEquals(500, $problem->status());
$this->assertEquals('PDOException', $problem->detail());
$this->assertEquals('Internal Server Error', $problem->title());
$this->assertEquals('http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html', $problem->type());
}
}