Skip to content

Commit

Permalink
Merge pull request #248 from kenjis/fix-strict-mode
Browse files Browse the repository at this point in the history
Fix $this->request can't be called more than once
  • Loading branch information
kenjis committed Apr 15, 2018
2 parents 22cc8ad + 1e0d9fc commit 7947926
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
9 changes: 5 additions & 4 deletions application/tests/_ci_phpunit_test/CIPHPUnitTestCase.php
Expand Up @@ -56,6 +56,11 @@ public function setCI(CI_Controller $CI)
$this->CI = $CI;
}

public function getStrictRequestErrorCheck()
{
return $this->strictRequestErrorCheck;
}

public function __get($name)
{
if (isset($this->class_map[$name]))
Expand Down Expand Up @@ -136,10 +141,6 @@ protected function tearDown()
*/
public function request($http_method, $argv, $params = [])
{
if ($this->strictRequestErrorCheck) {
$this->enableStrictErrorCheck();
}

return $this->request->request($http_method, $argv, $params);
}

Expand Down
21 changes: 18 additions & 3 deletions application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Expand Up @@ -10,6 +10,9 @@

class CIPHPUnitTestRequest
{
/**
* @var TestCase
*/
protected $testCase;

/**
Expand Down Expand Up @@ -39,7 +42,7 @@ class CIPHPUnitTestRequest
*/
protected $hooks;

public function __construct(PHPUnit_Framework_TestCase $testCase)
public function __construct(TestCase $testCase)
{
$this->testCase = $testCase;
$this->superGlobal = new CIPHPUnitTestSuperGlobal();
Expand Down Expand Up @@ -128,6 +131,10 @@ public function enableHooks()
*/
public function request($http_method, $argv, $params = [])
{
if ($this->testCase->getStrictRequestErrorCheck()) {
$this->testCase->enableStrictErrorCheck();
}

if (is_string($argv))
{
$argv = ltrim($argv, '/');
Expand All @@ -142,18 +149,23 @@ public function request($http_method, $argv, $params = [])
try {
if (is_array($argv))
{
return $this->callControllerMethod(
$ret = $this->callControllerMethod(
$http_method, $argv, $params
);
$this->testCase->disableStrictErrorCheck();
return $ret;
}
else
{
return $this->requestUri($http_method, $argv, $params);
$ret = $this->requestUri($http_method, $argv, $params);
$this->testCase->disableStrictErrorCheck();
return $ret;
}
}
// redirect()
catch (CIPHPUnitTestRedirectException $e)
{
$this->testCase->disableStrictErrorCheck();
if ($e->getCode() === 0)
{
set_status_header(200);
Expand All @@ -168,18 +180,21 @@ public function request($http_method, $argv, $params = [])
// show_404()
catch (CIPHPUnitTestShow404Exception $e)
{
$this->testCase->disableStrictErrorCheck();
$this->processError($e);
return $e->getMessage();
}
// show_error()
catch (CIPHPUnitTestShowErrorException $e)
{
$this->testCase->disableStrictErrorCheck();
$this->processError($e);
return $e->getMessage();
}
// exit()
catch (CIPHPUnitTestExitException $e)
{
$this->testCase->disableStrictErrorCheck();
$output = ob_get_clean();
return $output;
}
Expand Down
1 change: 1 addition & 0 deletions application/tests/_ci_phpunit_test/ChangeLog.md
Expand Up @@ -5,6 +5,7 @@
### Fixed

* Fix bug that installer replaces file path in `tests/Bootstrap.php` with wrong code which causes Parse error. See [#247](https://github.com/kenjis/ci-phpunit-test/pull/247).
* Fix bug that `$this->request()` can't be called more than once in a test method. See [#248](https://github.com/kenjis/ci-phpunit-test/pull/248).

### Others

Expand Down
Expand Up @@ -128,7 +128,7 @@ protected static function checkCalledMethod($function)
}
return true;
}
//Patches the functions only in the class method
// Patches the functions only in the class method
else
{
if (self::$patches_to_apply[$function] !== $class_method)
Expand Down

0 comments on commit 7947926

Please sign in to comment.