Skip to content

Commit d930eec

Browse files
committed
ci-phpunit-testのアップデート
composer update kenjis/ci-phpunit-test php vendor/kenjis/ci-phpunit-test/update.php
1 parent 1b58ee9 commit d930eec

10 files changed

Lines changed: 761 additions & 36 deletions

File tree

application/tests/_ci_phpunit_test/CIPHPUnitTest.php

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ public static function init()
2222
];
2323
$_SERVER['argc'] = 2;
2424

25-
require __DIR__ . '/CIPHPUnitTestCase.php';
26-
require __DIR__ . '/CIPHPUnitTestRequest.php';
27-
require __DIR__ . '/CIPHPUnitTestDouble.php';
28-
require __DIR__ . '/exceptions/CIPHPUnitTestRedirectException.php';
29-
require __DIR__ . '/exceptions/CIPHPUnitTestShow404Exception.php';
30-
require __DIR__ . '/exceptions/CIPHPUnitTestShowErrorException.php';
25+
self::loadCIPHPUnitTestClasses();
3126

3227
// Replace a few Common functions
3328
require __DIR__ . '/replacing/core/Common.php';
@@ -36,15 +31,8 @@ public static function init()
3631
// Load new functions of CIPHPUnitTest
3732
require __DIR__ . '/functions.php';
3833

39-
// Replace Loader
40-
require __DIR__ . '/replacing/core/Loader.php';
41-
$my_loader_file = APPPATH . 'core/' . config_item('subclass_prefix') . 'Loader.php';
42-
if (file_exists($my_loader_file))
43-
{
44-
self::$loader_class = config_item('subclass_prefix') . 'Loader';
45-
require $my_loader_file;
46-
}
47-
self::loadLoader();
34+
self::replaceLoader();
35+
self::replaceHelpers();
4836

4937
// Load autoloader for CIPHPUnitTest
5038
require __DIR__ . '/autoloader.php';
@@ -65,9 +53,7 @@ public static function init()
6553
// If controller Welcome is called in bootstrap, we can't test
6654
// the same name sub controller Welcome even when we use
6755
// `@runInSeparateProcess` and `@preserveGlobalState disabled`
68-
ob_start();
6956
require_once BASEPATH . 'core/CodeIgniter.php';
70-
ob_end_clean();
7157
} catch (CIPHPUnitTestShow404Exception $e) {
7258
// Catch 404 exception
7359
new CI_Controller();
@@ -77,6 +63,75 @@ public static function init()
7763

7864
// Restore $_SERVER
7965
$_SERVER = $_server_backup;
66+
67+
if (isset(TestCase::$enable_patcher) && TestCase::$enable_patcher)
68+
{
69+
self::enablePatcher();
70+
}
71+
}
72+
73+
protected static function replaceLoader()
74+
{
75+
require __DIR__ . '/replacing/core/Loader.php';
76+
$my_loader_file = APPPATH . 'core/' . config_item('subclass_prefix') . 'Loader.php';
77+
if (file_exists($my_loader_file))
78+
{
79+
self::$loader_class = config_item('subclass_prefix') . 'Loader';
80+
require $my_loader_file;
81+
}
82+
self::loadLoader();
83+
}
84+
85+
protected static function replaceHelpers()
86+
{
87+
$my_helper_file = APPPATH . 'helpers/' . config_item('subclass_prefix') . 'url_helper.php';
88+
if (file_exists($my_helper_file))
89+
{
90+
require $my_helper_file;
91+
}
92+
require __DIR__ . '/replacing/helpers/url_helper.php';
93+
}
94+
95+
protected static function loadCIPHPUnitTestClasses()
96+
{
97+
require __DIR__ . '/CIPHPUnitTestCase.php';
98+
require __DIR__ . '/CIPHPUnitTestRequest.php';
99+
require __DIR__ . '/CIPHPUnitTestDouble.php';
100+
require __DIR__ . '/exceptions/CIPHPUnitTestRedirectException.php';
101+
require __DIR__ . '/exceptions/CIPHPUnitTestShow404Exception.php';
102+
require __DIR__ . '/exceptions/CIPHPUnitTestShowErrorException.php';
103+
require __DIR__ . '/exceptions/CIPHPUnitTestExitException.php';
104+
}
105+
106+
protected static function enablePatcher()
107+
{
108+
require __DIR__ . '/patcher/CIPHPUnitTestIncludeStream.php';
109+
require __DIR__ . '/patcher/CIPHPUnitTestPatchPathChecker.php';
110+
require __DIR__ . '/patcher/CIPHPUnitTestPatcher.php';
111+
112+
// Register include stream wrapper for monkey patching
113+
CIPHPUnitTestIncludeStream::wrap();
114+
115+
CIPHPUnitTestPatchPathChecker::setWhitelistDir(
116+
[
117+
APPPATH,
118+
]
119+
);
120+
CIPHPUnitTestPatchPathChecker::setBlacklistDir(
121+
[
122+
realpath(APPPATH . '../vendor/'),
123+
APPPATH . 'tests/',
124+
]
125+
);
126+
127+
self::setPatcherCacheDir();
128+
}
129+
130+
public static function setPatcherCacheDir()
131+
{
132+
CIPHPUnitTestPatcher::setCacheDir(
133+
APPPATH . 'tests/_ci_phpunit_test/tmp/cache'
134+
);
80135
}
81136

82137
public static function loadLoader()

application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
<?php
2+
/**
3+
* Part of CI PHPUnit Test
4+
*
5+
* @author Kenji Suzuki <https://github.com/kenjis>
6+
* @license MIT License
7+
* @copyright 2015 Kenji Suzuki
8+
* @link https://github.com/kenjis/ci-phpunit-test
9+
*/
210

311
class CIPHPUnitTestRequest
412
{
13+
/**
14+
* @var callable callable post controller constructor
15+
*/
516
protected $callable;
17+
18+
/**
19+
* @var callable callable pre controller constructor
20+
*/
21+
protected $callablePreConstructor;
22+
623
protected $enableHooks = false;
724
protected $CI;
8-
25+
926
/**
1027
* @var bool whether throwing PHPUnit_Framework_Exception or not
1128
*
@@ -25,6 +42,16 @@ public function setCallable(callable $callable)
2542
$this->callable = $callable;
2643
}
2744

45+
/**
46+
* Set callable pre constructor
47+
*
48+
* @param callable $callable function to run before controller instantiation
49+
*/
50+
public function setCallablePreConstructor(callable $callable)
51+
{
52+
$this->callablePreConstructor = $callable;
53+
}
54+
2855
/**
2956
* Enable Hooks for Controllres
3057
* This enables only pre_controller, post_controller_constructor, post_controller
@@ -226,6 +253,13 @@ protected function createAndCallController($class, $method, $params)
226253
$EXT->call_hook('pre_controller');
227254
}
228255

256+
// Run callablePreConstructor
257+
if (is_callable($this->callablePreConstructor))
258+
{
259+
$callable = $this->callablePreConstructor;
260+
$callable();
261+
}
262+
229263
// Create controller
230264
$controller = new $class;
231265
$this->CI =& get_instance();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Part of CI PHPUnit Test
4+
*
5+
* @author Kenji Suzuki <https://github.com/kenjis>
6+
* @license MIT License
7+
* @copyright 2015 Kenji Suzuki
8+
* @link https://github.com/kenjis/ci-phpunit-test
9+
*/
10+
11+
class CIPHPUnitTestExitException extends RuntimeException
12+
{
13+
public $file;
14+
public $line;
15+
public $class;
16+
public $method;
17+
public $exit_status;
18+
}
19+
20+
function exit__($status = null)
21+
{
22+
$trace = debug_backtrace();
23+
$file = $trace[0]['file'];
24+
$line = $trace[0]['line'];
25+
$class = isset($trace[1]['class']) ? $trace[1]['class'] : null;
26+
$method = $trace[1]['function'];
27+
28+
if ($class === null)
29+
{
30+
$message = 'exit() called in ' . $method . '() function';
31+
}
32+
else
33+
{
34+
$message = 'exit() called in ' . $class . '::' . $method . '()';
35+
}
36+
37+
38+
$exception = new CIPHPUnitTestExitException($message);
39+
$exception->file = $file;
40+
$exception->line = $line;
41+
$exception->class = $class;
42+
$exception->method = $method;
43+
$exception->exit_status = $status;
44+
45+
throw $exception;
46+
}

application/tests/_ci_phpunit_test/functions.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ function reset_instance()
4343
CIPHPUnitTest::loadLoader();
4444
}
4545

46-
/**
47-
* Get new CodeIgniter instance
48-
* @deprecated
49-
*
50-
* @return CI_Controller
51-
*/
52-
function get_new_instance()
53-
{
54-
reset_instance();
55-
56-
$controller = new CI_Controller();
57-
return $controller;
58-
}
59-
6046
/**
6147
* Set return value of is_cli() function
6248
*

0 commit comments

Comments
 (0)