-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide basic integration testing with Request and Response objects.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php defined('SYSPATH') or die('No direct script access.'); | ||
|
||
/** | ||
* TestCase for testing in integration with Request and Response objects. | ||
* | ||
* This is inspired from the Play framework in which a test case provides | ||
* primitives to test Response objects. | ||
* | ||
* Testing a real application is feasible by self-requesting endpoints and | ||
* asserting pre-conditions and post-conditions. | ||
* | ||
* @package Kohana/UnitTest | ||
* @author Guillaume Poirier-Morency <[email protected]> | ||
* @copyright (c) 2008-2009 Kohana Team | ||
* @license http://kohanaphp.com/license | ||
*/ | ||
abstract class Kohana_Unittest_Integration_TestCase extends Unittest_TestCase { | ||
|
||
/** | ||
* Assert that a given Response status match the expected value. | ||
* | ||
* @param integer $code expected status code | ||
* @param Response $response Response object | ||
* @param string $message message displayed if the test fail | ||
*/ | ||
public function assertStatus($code, Response $response, $message = NULL) | ||
{ | ||
if ($message === NULL) | ||
{ | ||
$message = $response->body(); | ||
} | ||
|
||
$this->assertEquals($code, $response->status(), $message); | ||
} | ||
|
||
public function assertOk(Response $response, $message = NULL) | ||
{ | ||
$this->assertStatus(200, $response, $message); | ||
} | ||
|
||
public function assertPermanentRedirection($location, Response $response, $message = NULL) | ||
{ | ||
$this->assertStatus(301, $response, $message); | ||
$this->assertEquals($location, $response->headers('Location')); | ||
} | ||
|
||
public function assertTemporaryRedirection($location, Response $response, $message = NULL) | ||
{ | ||
$this->assertStatus(302, $response, $message); | ||
$this->assertEquals($location, $response->headers('Location')); | ||
} | ||
|
||
public function assertUnauthorized(Response $response, $message = NULL) | ||
{ | ||
$this->assertStatus(401, $response, $message); | ||
} | ||
|
||
public function assertForbidden(Response $response, $message = NULL) | ||
{ | ||
$this->assertStatus(403, $response, $message); | ||
} | ||
|
||
public function assertNotFound(Response $response, $message = NULL) | ||
{ | ||
$this->assertStatus(404, $response, $message); | ||
} | ||
|
||
public function assertServiceUnavailable(Response $response, $message = NULL) | ||
{ | ||
$this->assertStatus(503, $response, $message); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php defined('SYSPATH') or die('No direct script access.'); | ||
|
||
abstract class Unittest_Integration_TestCase extends Kohana_Unittest_Integration_TestCase {} |