mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
改进测试
This commit is contained in:
@@ -17,23 +17,20 @@
|
|||||||
namespace tests\thinkphp\library\think;
|
namespace tests\thinkphp\library\think;
|
||||||
|
|
||||||
use think\Hook;
|
use think\Hook;
|
||||||
|
|
||||||
class hookTest extends \PHPUnit_Framework_TestCase
|
class hookTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected function setUp()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRun()
|
public function testRun()
|
||||||
{
|
{
|
||||||
Hook::add('my_pos','\tests\thinkphp\library\think\behavior\One');
|
Hook::add('my_pos', '\tests\thinkphp\library\think\behavior\One');
|
||||||
Hook::add('my_pos','\tests\thinkphp\library\think\behavior\Two');
|
Hook::add('my_pos', '\tests\thinkphp\library\think\behavior\Two');
|
||||||
Hook::add('my_pos','\tests\thinkphp\library\think\behavior\Three',true);
|
Hook::add('my_pos', '\tests\thinkphp\library\think\behavior\Three', true);
|
||||||
$data['id'] = 0;
|
$data['id'] = 0;
|
||||||
$data['name'] = 'thinkphp';
|
$data['name'] = 'thinkphp';
|
||||||
Hook::listen('my_pos',$data);
|
Hook::listen('my_pos', $data);
|
||||||
$this->assertEquals(2,$data['id']);
|
$this->assertEquals(2, $data['id']);
|
||||||
$this->assertEquals('thinkphp',$data['name']);
|
$this->assertEquals('thinkphp', $data['name']);
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
'\tests\thinkphp\library\think\behavior\Three',
|
'\tests\thinkphp\library\think\behavior\Three',
|
||||||
'\tests\thinkphp\library\think\behavior\One',
|
'\tests\thinkphp\library\think\behavior\One',
|
||||||
@@ -41,23 +38,27 @@ class hookTest extends \PHPUnit_Framework_TestCase
|
|||||||
Hook::get('my_pos'));
|
Hook::get('my_pos'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testImport(){
|
public function testImport()
|
||||||
Hook::import(['my_pos'=>[
|
{
|
||||||
|
Hook::import(['my_pos' => [
|
||||||
'\tests\thinkphp\library\think\behavior\One',
|
'\tests\thinkphp\library\think\behavior\One',
|
||||||
'\tests\thinkphp\library\think\behavior\Three']
|
'\tests\thinkphp\library\think\behavior\Three'],
|
||||||
]);
|
]);
|
||||||
$data['id'] = 0;
|
$data['id'] = 0;
|
||||||
$data['name'] = 'thinkphp';
|
$data['name'] = 'thinkphp';
|
||||||
Hook::listen('my_pos',$data);
|
Hook::listen('my_pos', $data);
|
||||||
$this->assertEquals(3,$data['id']);
|
$this->assertEquals(3, $data['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExec(){
|
public function testExec()
|
||||||
$data['id'] = 0;
|
{
|
||||||
|
$data['id'] = 0;
|
||||||
$data['name'] = 'thinkphp';
|
$data['name'] = 'thinkphp';
|
||||||
$this->assertEquals(true,Hook::exec('\tests\thinkphp\library\think\behavior\One'));
|
$this->assertEquals(true, Hook::exec('\tests\thinkphp\library\think\behavior\One'));
|
||||||
$this->assertEquals(false,Hook::exec('\tests\thinkphp\library\think\behavior\One','test',$data));
|
$this->assertEquals(false, Hook::exec('\tests\thinkphp\library\think\behavior\One', 'test', $data));
|
||||||
$this->assertEquals('test',$data['name']);
|
$this->assertEquals('test', $data['name']);
|
||||||
|
$this->assertEquals('Closure', Hook::exec(function (&$data) {$data['name'] = 'Closure';return 'Closure';}));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user