From e64bc5e982b5db08464f358513223ea9a0460915 Mon Sep 17 00:00:00 2001 From: Guillaume Poirier-Morency Date: Tue, 25 Nov 2014 12:49:01 -0500 Subject: [PATCH] Provide basic integration testing with Request and Response objects. --- .../Kohana/Unittest/Integration/TestCase.php | 73 +++++++++++++++++++ classes/Unittest/Integration/TestCase.php | 3 + 2 files changed, 76 insertions(+) create mode 100644 classes/Kohana/Unittest/Integration/TestCase.php create mode 100644 classes/Unittest/Integration/TestCase.php diff --git a/classes/Kohana/Unittest/Integration/TestCase.php b/classes/Kohana/Unittest/Integration/TestCase.php new file mode 100644 index 0000000..20a065b --- /dev/null +++ b/classes/Kohana/Unittest/Integration/TestCase.php @@ -0,0 +1,73 @@ + + * @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); + } + +} diff --git a/classes/Unittest/Integration/TestCase.php b/classes/Unittest/Integration/TestCase.php new file mode 100644 index 0000000..70539f9 --- /dev/null +++ b/classes/Unittest/Integration/TestCase.php @@ -0,0 +1,3 @@ +