Skip to content

Commit e64bc5e

Browse files
committed
Provide basic integration testing with Request and Response objects.
1 parent 5cc6000 commit e64bc5e

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php defined('SYSPATH') or die('No direct script access.');
2+
3+
/**
4+
* TestCase for testing in integration with Request and Response objects.
5+
*
6+
* This is inspired from the Play framework in which a test case provides
7+
* primitives to test Response objects.
8+
*
9+
* Testing a real application is feasible by self-requesting endpoints and
10+
* asserting pre-conditions and post-conditions.
11+
*
12+
* @package Kohana/UnitTest
13+
* @author Guillaume Poirier-Morency <[email protected]>
14+
* @copyright (c) 2008-2009 Kohana Team
15+
* @license http://kohanaphp.com/license
16+
*/
17+
abstract class Kohana_Unittest_Integration_TestCase extends Unittest_TestCase {
18+
19+
/**
20+
* Assert that a given Response status match the expected value.
21+
*
22+
* @param integer $code expected status code
23+
* @param Response $response Response object
24+
* @param string $message message displayed if the test fail
25+
*/
26+
public function assertStatus($code, Response $response, $message = NULL)
27+
{
28+
if ($message === NULL)
29+
{
30+
$message = $response->body();
31+
}
32+
33+
$this->assertEquals($code, $response->status(), $message);
34+
}
35+
36+
public function assertOk(Response $response, $message = NULL)
37+
{
38+
$this->assertStatus(200, $response, $message);
39+
}
40+
41+
public function assertPermanentRedirection($location, Response $response, $message = NULL)
42+
{
43+
$this->assertStatus(301, $response, $message);
44+
$this->assertEquals($location, $response->headers('Location'));
45+
}
46+
47+
public function assertTemporaryRedirection($location, Response $response, $message = NULL)
48+
{
49+
$this->assertStatus(302, $response, $message);
50+
$this->assertEquals($location, $response->headers('Location'));
51+
}
52+
53+
public function assertUnauthorized(Response $response, $message = NULL)
54+
{
55+
$this->assertStatus(401, $response, $message);
56+
}
57+
58+
public function assertForbidden(Response $response, $message = NULL)
59+
{
60+
$this->assertStatus(403, $response, $message);
61+
}
62+
63+
public function assertNotFound(Response $response, $message = NULL)
64+
{
65+
$this->assertStatus(404, $response, $message);
66+
}
67+
68+
public function assertServiceUnavailable(Response $response, $message = NULL)
69+
{
70+
$this->assertStatus(503, $response, $message);
71+
}
72+
73+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php defined('SYSPATH') or die('No direct script access.');
2+
3+
abstract class Unittest_Integration_TestCase extends Kohana_Unittest_Integration_TestCase {}

0 commit comments

Comments
 (0)