// +---------------------------------------------------------------------- /** * app类测试 * @author Haotong Lin */ namespace tests\thinkphp\library\think; use ReflectionClass; use think\App; use think\Config; 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() { Config::set('root_namespace', ['/path/']); App::run(); $expectOutputString = '

:)

欢迎使用 ThinkPHP5

'; $this->expectOutputString($expectOutputString); $rc = new ReflectionClass('\think\Loader'); $ns = $rc->getProperty('namespace'); $ns->setAccessible(true); $this->assertEquals(true, in_array('/path/', $ns->getValue())); $this->assertEquals(true, function_exists('L')); $this->assertEquals(true, function_exists('C')); $this->assertEquals(true, function_exists('I')); $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() { $_GET = ['thinkphp']; $result = App::invokeMethod(['tests\thinkphp\library\think\AppInvokeMethodTestClass', 'run']); $this->assertEquals('thinkphp', $result); $_GET = ['thinkphp']; $result = App::invokeMethod('tests\thinkphp\library\think\AppInvokeMethodTestClass::staticRun'); $this->assertEquals('thinkphp', $result); } }