// +---------------------------------------------------------------------- /** * app类测试 * @author Haotong Lin */ namespace tests\thinkphp\library\think; use think\App; use think\Config; use think\Request; function func_trim($value) { return trim($value); } function func_strpos($haystack, $needle) { return strpos($haystack, $needle); } class AppInvokeMethodTestClass { public static function staticRun($string) { return $string; } public function run($string) { return $string; } } class appTest extends \PHPUnit_Framework_TestCase { public function testRun() { $response = App::run(Request::create("http://www.example.com")); $expectOutputString = '

:)

ThinkPHP V5
十年磨一剑 - 为API开发设计的高性能框架

[ V5.0 版本由 七牛云 独家赞助发布 ]
'; $this->assertEquals($expectOutputString, $response->getContent()); $this->assertEquals(200, $response->getCode()); $this->assertEquals(true, function_exists('lang')); $this->assertEquals(true, function_exists('config')); $this->assertEquals(true, function_exists('input')); $this->assertEquals(Config::get('default_timezone'), date_default_timezone_get()); } // function调度 public function testInvokeFunction() { $args1 = ['a b c ']; $this->assertEquals( trim($args1[0]), App::invokeFunction('tests\thinkphp\library\think\func_trim', $args1) ); $args2 = ['abcdefg', 'g']; $this->assertEquals( strpos($args2[0], $args2[1]), App::invokeFunction('tests\thinkphp\library\think\func_strpos', $args2) ); } // 类method调度 public function testInvokeMethod() { $result = App::invokeMethod(['tests\thinkphp\library\think\AppInvokeMethodTestClass', 'run'], ['thinkphp']); $this->assertEquals('thinkphp', $result); $result = App::invokeMethod('tests\thinkphp\library\think\AppInvokeMethodTestClass::staticRun', ['thinkphp']); $this->assertEquals('thinkphp', $result); } }