From 1cc247fa12ccf8c25e0f4bd6c47a27e1c02acee7 Mon Sep 17 00:00:00 2001 From: Gaozhen Ying Date: Wed, 11 Oct 2017 18:12:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EDebug::Inject=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/debugTest.php | 59 ++++++++++++++++++---- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/tests/thinkphp/library/think/debugTest.php b/tests/thinkphp/library/think/debugTest.php index fc2fdd47..494694a3 100644 --- a/tests/thinkphp/library/think/debugTest.php +++ b/tests/thinkphp/library/think/debugTest.php @@ -16,10 +16,15 @@ namespace tests\thinkphp\library\think; +use tests\thinkphp\library\think\config\ConfigInitTrait; +use think\Config; use think\Debug; +use think\Response; +use think\response\Redirect; class debugTest extends \PHPUnit_Framework_TestCase { + use ConfigInitTrait; /** * @@ -44,7 +49,7 @@ class debugTest extends \PHPUnit_Framework_TestCase {} /** - * @covers think\Debug::remark + * @covers \think\Debug::remark * @todo Implement testRemark(). */ public function testRemark() @@ -54,7 +59,7 @@ class debugTest extends \PHPUnit_Framework_TestCase } /** - * @covers think\Debug::getRangeTime + * @covers \think\Debug::getRangeTime * @todo Implement testGetRangeTime(). */ public function testGetRangeTime() @@ -71,7 +76,7 @@ class debugTest extends \PHPUnit_Framework_TestCase } /** - * @covers think\Debug::getUseTime + * @covers \think\Debug::getUseTime * @todo Implement testGetUseTime(). */ public function testGetUseTime() @@ -81,7 +86,7 @@ class debugTest extends \PHPUnit_Framework_TestCase } /** - * @covers think\Debug::getThroughputRate + * @covers \think\Debug::getThroughputRate * @todo Implement testGetThroughputRate(). */ public function testGetThroughputRate() @@ -92,7 +97,7 @@ class debugTest extends \PHPUnit_Framework_TestCase } /** - * @covers think\Debug::getRangeMem + * @covers \think\Debug::getRangeMem * @todo Implement testGetRangeMem(). */ public function testGetRangeMem() @@ -111,7 +116,7 @@ class debugTest extends \PHPUnit_Framework_TestCase } /** - * @covers think\Debug::getUseMem + * @covers \think\Debug::getUseMem * @todo Implement testGetUseMem(). */ public function testGetUseMem() @@ -122,7 +127,7 @@ class debugTest extends \PHPUnit_Framework_TestCase } /** - * @covers think\Debug::getMemPeak + * @covers \think\Debug::getMemPeak * @todo Implement testGetMemPeak(). */ public function testGetMemPeak() @@ -139,7 +144,7 @@ class debugTest extends \PHPUnit_Framework_TestCase } /** - * @covers think\Debug::getFile + * @covers \think\Debug::getFile * @todo Implement testGetFile(). */ public function testGetFile() @@ -155,7 +160,7 @@ class debugTest extends \PHPUnit_Framework_TestCase } /** - * @covers think\Debug::dump + * @covers \think\Debug::dump * @todo Implement testDump(). */ public function testDump() @@ -176,4 +181,40 @@ class debugTest extends \PHPUnit_Framework_TestCase $this->assertEquals("(1) {\\n 'key' =>\\n string(3) \\\"val\\\"\\n}\\n\\n\"", end($array)); } } + + /** + * @expectedException \think\exception\ClassNotFoundException + */ + public function testInjectWithErrorType() + { + Config::set('trace', ['type' => 'NullDebug']); + + $response = new Response(); + $context = 'TestWithErrorType'; + + Debug::inject($response, $context); + } + + public function testInject() + { + Config::set('trace', ['type' => 'Console']); + + $response = new Response(); + $context = 'TestWithoutBodyTag'; + Debug::inject($response, $context); + $this->assertNotEquals('TestWithoutBodyTag', $context); + $this->assertStringStartsWith('TestWithoutBodyTag', $context); + + $response = new Response(); + $context = ''; + Debug::inject($response, $context); + $this->assertNotEquals('', $context); + $this->assertStringStartsWith('', $context); + $this->assertStringEndsWith('', $context); + + $response = new Redirect(); + $context = ''; + Debug::inject($response, $context); + $this->assertEquals('', $context); + } }