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 Nov 25, 2014
1 parent 5cc6000 commit 5167ef9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
64 changes: 64 additions & 0 deletions classes/Kohana/Unittest/TestCase/Integration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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_TestCase_Integration extends Unittest_TestCase {

public function assertResponse(array $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->assertResponse(200, $response, $message);
}

public function assertPermanentRedirection(Response $response, $message = NULL)
{
$this->assertResponse(301, $response, $message);
}

public function assertTemporaryRedirection(Response $response, $message = NULL)
{
$this->assertResponse(302, $response, $message);
}

public function assertUnauthorized(Response $response, $message = NULL)
{
$this->assertResponse(401, $response, $message);
}

public function assertForbidden(Response $response, $message = NULL)
{
$this->assertResponse(403, $response, $message);
}

public function assertNotFound(Response $response, $message = NULL)
{
$this->assertResponse(404, $response, $message);
}

public function assertServiceUnavailable(Response $response, $message = NULL)
{
$this->assertResponse(503, $response, $message);
}

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

0 comments on commit 5167ef9

Please sign in to comment.