mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
完善单元测试
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user