Skip to content

Commit

Permalink
Add callablePreConstructor in CIPHPUnitTestRequest class
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 21, 2015
1 parent 7e22417 commit 0df623e
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
@@ -1,11 +1,28 @@
<?php
/**
* Part of CI PHPUnit Test
*
* @author Kenji Suzuki <https://github.com/kenjis>
* @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
*
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 0df623e

Please sign in to comment.