From 781773d2703c9a0619fac360e81695783483c1dd Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Thu, 13 Dec 2018 18:28:53 +0800 Subject: [PATCH] add some tests for sandbox --- src/Server/Sandbox.php | 8 -------- tests/Server/SandboxTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Server/Sandbox.php b/src/Server/Sandbox.php index cc3d1c8d..1ab2041b 100644 --- a/src/Server/Sandbox.php +++ b/src/Server/Sandbox.php @@ -323,14 +323,6 @@ public function getSnapshot() return Context::getApp(); } - /** - * Remove current request. - */ - public function removeRequest() - { - return Context::removeData('_request'); - } - /** * Get current request. */ diff --git a/tests/Server/SandboxTest.php b/tests/Server/SandboxTest.php index 9f04a1e6..56414f9f 100644 --- a/tests/Server/SandboxTest.php +++ b/tests/Server/SandboxTest.php @@ -99,6 +99,31 @@ public function testGetApplication() $this->assertTrue($sandbox->getSnapshot() instanceof Container); } + public function testGetCachedSnapshot() + { + $container = m::mock(Container::class); + $snapshot = m::mock(Container::class); + $snapshot->shouldReceive('offsetGet') + ->with('foo') + ->once() + ->andReturn($result = 'bar'); + + $sandbox = new Sandbox; + $sandbox->setBaseApp($container); + $sandbox->setSnapshot($snapshot); + + $this->assertTrue($sandbox->getApplication() instanceof Container); + $this->assertEquals($result, $sandbox->getApplication()->foo); + } + + public function testRunWithoutSnapshot() + { + $this->expectException(SandboxException::class); + + $sandbox = new Sandbox; + $sandbox->run($request = m::mock(Request::class)); + } + public function testSetRequest() { $request = m::mock(Request::class);