ResponseTest::testSetResponseCodeAndText()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Torpedo\Test;
4
use Torpedo\Response;
5
6
class ResponseTest extends \PHPUnit_Framework_TestCase {
7
8
	public $response; 
9
10
	public function setup(){
11
		$this->response = new \Torpedo\Http\Response; 
12
	}
13
14
	// set HTTP response code and test
15
	public function testSetResponseCode(){
16
		$this->response->setCode(301); 
17
		$this->assertEquals($this->response->getCode(), 301);
18
	}
19
	
20
	// set HTTP code and text and test
21
	public function testSetResponseCodeAndText(){
22
		$this->response->setResponse(400, 'Four Hundred'); 
23
		$this->assertEquals($this->response->getCode(), 400);
24
		$this->assertEquals($this->response->getText(), 'Four Hundred');
25
	}
26
	
27
	// set a redirect command and test code/location separately
28
	public function testRedirectLocationAndCode(){
29
		$this->response->redirect('/foo', 301);
30
		$this->assertEquals($this->response->getCode(), 301);
31
		$this->assertContains('/foo', $this->response->getHeaders()); 
32
	}
33
34
	/**
35
	* use the exception anotation to test an exception triggered by invalid 
36
	* HTTP code value
37
	* @expectedException \LogicException
38
	* @expectedExceptionMessage 987654321 is unsuported HTTP status code
39
	*/
40
	public function testSetStatusThrowsLogicExceptionOnInvalidStatusCodeRange(){
41
		$this->response->setCode(987654321);
42
	}
43
44
}