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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
<?php /** * Klein (klein.php) - A fast & flexible router for PHP * * @author Chris O'Hara <cohara87@gmail.com> * @author Trevor Suarez (Rican7) (contributor and v2 refactorer) * @copyright (c) Chris O'Hara * @link https://github.com/klein/klein.php * @license MIT */
namespace Klein\Tests;
use Klein\HttpStatus;
/** * HttpStatusTests */ class HttpStatusTests extends AbstractKleinTest {
public function testStaticMessageFromCode() { // Set our test data $code = 404; $message = 'Not Found'; // HTTP 1.1 404 status message
$this->assertSame($message, HttpStatus::getMessageFromCode($code)); }
public function testManualEntryViaConstructor() { // Set our manual test data $code = 666; $message = 'The devil\'s mark';
$http_status = new HttpStatus($code, $message);
$this->assertSame($code, $http_status->getCode()); $this->assertSame($message, $http_status->getMessage()); }
public function testManualEntryViaSetters() { // Set our manual test data $constructor_code = 123; $code = 666; $message = 'The devil\'s mark';
$http_status = new HttpStatus($constructor_code); $http_status->setCode($code); $http_status->setMessage($message);
$this->assertNotSame($constructor_code, $http_status->getCode()); $this->assertSame($code, $http_status->getCode()); $this->assertSame($message, $http_status->getMessage()); }
public function testAutomaticMessage() { $code = 201; $expected_message = 'Created';
$http_status = new HttpStatus($code);
$this->assertSame($code, $http_status->getCode()); $this->assertSame($expected_message, $http_status->getMessage()); }
public function testStringOutput() { // Set our manual test data $code = 404; $expected_string = '404 Not Found';
// Create and echo our status $http_status = new HttpStatus($code); echo $http_status;
$this->expectOutputString($expected_string);
$this->assertSame($expected_string, $http_status->getFormattedString()); } }
|