Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 26f6396

Browse files
committed
fix reset config in sandbox for Lumen
1 parent 5b70272 commit 26f6396

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/Server/Sandbox.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class Sandbox
1919
*/
2020
protected $snapshot;
2121

22+
/**
23+
* @var \Illuminate\Config\Repository
24+
*/
25+
protected $config;
26+
2227
/**
2328
* @var boolean
2429
*/
@@ -41,6 +46,7 @@ public static function make(Application $application)
4146
public function __construct(Application $application)
4247
{
4348
$this->setApplication($application);
49+
$this->setInitialConfig($application);
4450
}
4551

4652
/**
@@ -53,6 +59,16 @@ public function setApplication(Application $application)
5359
$this->application = $application;
5460
}
5561

62+
/**
63+
* Set config snapshot.
64+
*
65+
* @param \SwooleTW\Http\Server\Application
66+
*/
67+
protected function setInitialConfig(Application $application)
68+
{
69+
$this->config = clone $application->getApplication()['config'];
70+
}
71+
5672
/**
5773
* Get an application snapshot
5874
*
@@ -75,20 +91,19 @@ public function getApplication()
7591
*/
7692
protected function resetLaravelApp($application)
7793
{
78-
if ($this->isFramework('laravel')) {
79-
$application->bootstrapWith([
80-
'Illuminate\Foundation\Bootstrap\LoadConfiguration'
81-
]);
82-
} elseif ($this->isFramework('lumen')) {
83-
$reflector = new \ReflectionMethod(LumenApplication::class, 'registerConfigBindings');
84-
$reflector->setAccessible(true);
85-
$reflector->invoke($application);
86-
}
87-
94+
$this->resetConfigInstance($application);
8895
$this->rebindRouterContainer($application);
8996
$this->rebindViewContainer($application);
9097
}
9198

99+
/**
100+
* Reset laravel/lumen's config to initial values.
101+
*/
102+
protected function resetConfigInstance($application)
103+
{
104+
$application->instance('config', clone $this->config);
105+
}
106+
92107
/**
93108
* Rebind laravel's container in router.
94109
*/

tests/Server/SandboxTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public function testGetSandbox()
1919

2020
public function testMakeSandbox()
2121
{
22-
$application = m::mock(Application::class);
23-
$sandbox = Sandbox::make($application);
22+
$sandbox = Sandbox::make($this->getApplication());
2423

2524
$this->assertTrue($sandbox instanceof Sandbox);
2625
}
@@ -55,8 +54,8 @@ protected function getSandbox()
5554
protected function getContainer()
5655
{
5756
$container = m::mock(Container::class);
58-
$container->shouldReceive('bootstrapWith')
59-
->andReturnNull();
57+
$container->shouldReceive('offsetGet')
58+
->andReturn((object)[]);
6059

6160
return $container;
6261
}

0 commit comments

Comments
 (0)