-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide basic integration testing with Request and Response objects. #41
base: 3.3/develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be better as a first-class PHPUnit assertion, so that if it fails it can show the whole of the status/location header/etc in a useful failure message that describes the overall assertion and what was incorrect, rather than a chain of assertEquals. For example, |
||
{ | ||
$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); | ||
} | ||
|
||
} |
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 {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this potentially dump an enormous HTML string into your PHPUnit output? Don't think I like that idea.