完善单元测试

This commit is contained in:
Haotong Lin
2016-03-03 11:13:59 +08:00
parent 19a446c7de
commit 1db6c886a0
2 changed files with 11 additions and 8 deletions

View File

@@ -18,6 +18,7 @@ namespace tests\thinkphp\library\think;
use ReflectionClass; use ReflectionClass;
use think\Controller; use think\Controller;
use think\View;
require_once CORE_PATH . '../../helper.php'; require_once CORE_PATH . '../../helper.php';
@@ -107,17 +108,19 @@ class controllerTest extends \PHPUnit_Framework_TestCase
private function getView($controller) private function getView($controller)
{ {
$view = new View();
$rc = new ReflectionClass(get_class($controller)); $rc = new ReflectionClass(get_class($controller));
$property = $rc->getProperty('view'); $property = $rc->getProperty('view');
$property->setAccessible(true); $property->setAccessible(true);
return $property->getValue($controller); $property->setValue($controller, $view);
return $view;
} }
public function testFetch() public function testFetch()
{ {
$controller = new Foo; $controller = new Foo;
$view = $this->getView($controller); $view = $this->getView($controller);
$template = __DIR__ . '/display'; $template = dirname(__FILE__) . '/display.html';
$viewFetch = $view->fetch($template, ['name' => 'ThinkPHP']); $viewFetch = $view->fetch($template, ['name' => 'ThinkPHP']);
$controllerFetch = $controller->fetch($template, ['name' => 'ThinkPHP']); $controllerFetch = $controller->fetch($template, ['name' => 'ThinkPHP']);
$this->assertEquals($controllerFetch, $viewFetch); $this->assertEquals($controllerFetch, $viewFetch);
@@ -127,7 +130,7 @@ class controllerTest extends \PHPUnit_Framework_TestCase
{ {
$controller = new Foo; $controller = new Foo;
$view = $this->getView($controller); $view = $this->getView($controller);
$template = __DIR__ . '/display'; $template = dirname(__FILE__) . '/display.html';
$viewFetch = $view->show($template, ['name' => 'ThinkPHP']); $viewFetch = $view->show($template, ['name' => 'ThinkPHP']);
$controllerFetch = $controller->show($template, ['name' => 'ThinkPHP']); $controllerFetch = $controller->show($template, ['name' => 'ThinkPHP']);
$this->assertEquals($controllerFetch, $viewFetch); $this->assertEquals($controllerFetch, $viewFetch);

View File

@@ -37,7 +37,7 @@ class cookieTest extends \PHPUnit_Framework_TestCase
// httponly设置 // httponly设置
'httponly' => '', 'httponly' => '',
// 是否使用 setcookie // 是否使用 setcookie
'setcookie' => true, 'setcookie' => false,
]; ];
protected function setUp() protected function setUp()