From 5e592de087f576a8e7efc9e3f2fe4626c48dbf0a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 28 Feb 2016 16:08:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Hook=E7=B1=BB=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/behavior/One.php | 15 +++++ .../thinkphp/library/think/behavior/Three.php | 9 +++ tests/thinkphp/library/think/behavior/Two.php | 9 +++ tests/thinkphp/library/think/hookTest.php | 63 +++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 tests/thinkphp/library/think/behavior/One.php create mode 100644 tests/thinkphp/library/think/behavior/Three.php create mode 100644 tests/thinkphp/library/think/behavior/Two.php create mode 100644 tests/thinkphp/library/think/hookTest.php diff --git a/tests/thinkphp/library/think/behavior/One.php b/tests/thinkphp/library/think/behavior/One.php new file mode 100644 index 00000000..ae8fa49d --- /dev/null +++ b/tests/thinkphp/library/think/behavior/One.php @@ -0,0 +1,15 @@ + +// +---------------------------------------------------------------------- + +/** + * Hook类测试 + * @author liu21st + */ + +namespace tests\thinkphp\library\think; + +use think\Hook; +class hookTest extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + + } + + public function testRun() + { + 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\Three',true); + $data['id'] = 0; + $data['name'] = 'thinkphp'; + Hook::listen('my_pos',$data); + $this->assertEquals(2,$data['id']); + $this->assertEquals('thinkphp',$data['name']); + $this->assertEquals([ + '\tests\thinkphp\library\think\behavior\Three', + '\tests\thinkphp\library\think\behavior\One', + '\tests\thinkphp\library\think\behavior\Two'], + Hook::get('my_pos')); + } + + public function testImport(){ + Hook::import(['my_pos'=>[ + '\tests\thinkphp\library\think\behavior\One', + '\tests\thinkphp\library\think\behavior\Three'] + ]); + $data['id'] = 0; + $data['name'] = 'thinkphp'; + Hook::listen('my_pos',$data); + $this->assertEquals(3,$data['id']); + } + + public function testExec(){ + $data['id'] = 0; + $data['name'] = 'thinkphp'; + $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('test',$data['name']); + } + +}