From 0df623e503404ce702bfac8edaf580ec88795829 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 21 Jul 2015 17:29:31 +0900 Subject: [PATCH] Add callablePreConstructor in CIPHPUnitTestRequest class --- .../_ci_phpunit_test/CIPHPUnitTestRequest.php | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php b/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php index 95b32748..f747cee3 100644 --- a/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php +++ b/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php @@ -1,11 +1,28 @@ + * @license MIT License + * @copyright 2015 Kenji Suzuki + * @link https://github.com/kenjis/ci-phpunit-test + */ class CIPHPUnitTestRequest { + /** + * @var callable callable post controller constructor + */ protected $callable; + + /** + * @var callable callable pre controller constructor + */ + protected $callablePreConstructor; + protected $enableHooks = false; protected $CI; - + /** * @var bool whether throwing PHPUnit_Framework_Exception or not * @@ -25,6 +42,16 @@ public function setCallable(callable $callable) $this->callable = $callable; } + /** + * Set callable pre constructor + * + * @param callable $callable function to run before controller instantiation + */ + public function setCallablePreConstructor(callable $callable) + { + $this->callablePreConstructor = $callable; + } + /** * Enable Hooks for Controllres * This enables only pre_controller, post_controller_constructor, post_controller @@ -226,6 +253,13 @@ protected function createAndCallController($class, $method, $params) $EXT->call_hook('pre_controller'); } + // Run callablePreConstructor + if (is_callable($this->callablePreConstructor)) + { + $callable = $this->callablePreConstructor; + $callable(); + } + // Create controller $controller = new $class; $this->CI =& get_instance();