ResponseTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 39
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 3 1
A testSetResponseCode() 0 4 1
A testSetResponseCodeAndText() 0 5 1
A testRedirectLocationAndCode() 0 5 1
A testSetStatusThrowsLogicExceptionOnInvalidStatusCodeRange() 0 3 1
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
}