Skip to content

Commit

Permalink
Provide basic integration testing with Request and Response objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
arteymix committed Dec 12, 2014
1 parent 5cc6000 commit e64bc5e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
73 changes: 73 additions & 0 deletions classes/Kohana/Unittest/Integration/TestCase.php
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);
}

}
3 changes: 3 additions & 0 deletions classes/Unittest/Integration/TestCase.php
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 {}

0 comments on commit e64bc5e

Please sign in to comment.