mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
添加Hook类测试
This commit is contained in:
15
tests/thinkphp/library/think/behavior/One.php
Normal file
15
tests/thinkphp/library/think/behavior/One.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace tests\thinkphp\library\think\behavior;
|
||||
|
||||
class One
|
||||
{
|
||||
public function run(&$data){
|
||||
$data['id'] = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function test(&$data){
|
||||
$data['name'] = 'test';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
9
tests/thinkphp/library/think/behavior/Three.php
Normal file
9
tests/thinkphp/library/think/behavior/Three.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace tests\thinkphp\library\think\behavior;
|
||||
|
||||
class Three
|
||||
{
|
||||
public function run(&$data){
|
||||
$data['id'] = 3;
|
||||
}
|
||||
}
|
||||
9
tests/thinkphp/library/think/behavior/Two.php
Normal file
9
tests/thinkphp/library/think/behavior/Two.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace tests\thinkphp\library\think\behavior;
|
||||
|
||||
class Two
|
||||
{
|
||||
public function run(&$data){
|
||||
$data['id'] = 2;
|
||||
}
|
||||
}
|
||||
63
tests/thinkphp/library/think/hookTest.php
Normal file
63
tests/thinkphp/library/think/hookTest.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Hook类测试
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user