Skip to content

Commit 81829b4

Browse files
authored
Merge pull request #609 from cakephp/fix-toolbar-config
Fixed configuration passing in middleware
2 parents a4584a4 + 87ce81d commit 81829b4

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/Middleware/DebugKitMiddleware.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
namespace DebugKit\Middleware;
1313

14+
use Cake\Core\Configure;
1415
use Cake\Event\EventManager;
1516
use DebugKit\ToolbarService;
1617

@@ -31,7 +32,7 @@ class DebugKitMiddleware
3132
*/
3233
public function __construct(ToolbarService $service = null)
3334
{
34-
$service = $service ?: new ToolbarService(EventManager::instance(), []);
35+
$service = $service ?: new ToolbarService(EventManager::instance(), (array)Configure::read('DebugKit'));
3536
$this->service = $service;
3637
}
3738

tests/TestCase/Middleware/DebugKitMiddlewareTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class DebugKitMiddlewareTest extends TestCase
3939
'plugin.debug_kit.requests',
4040
'plugin.debug_kit.panels'
4141
];
42+
4243
/**
4344
* setup
4445
*
@@ -50,6 +51,19 @@ public function setUp()
5051

5152
$connection = ConnectionManager::get('test');
5253
$this->skipIf($connection->getDriver() instanceof Sqlite, 'Schema insertion/removal breaks SQLite');
54+
$this->oldConfig = Configure::read('DebugKit');
55+
}
56+
57+
/**
58+
* tearDown
59+
*
60+
* @return void
61+
*/
62+
public function tearDown()
63+
{
64+
parent::tearDown();
65+
66+
Configure::write('DebugKit', $this->oldConfig);
5367
}
5468

5569
/**
@@ -205,4 +219,20 @@ public function testInvokeNoModifyRequestAction()
205219
$body = $result->getBody();
206220
$this->assertNotContains('<script', '' . $body);
207221
}
222+
223+
/**
224+
* Test that configuration is correctly passed to the service
225+
*
226+
* @return void
227+
*/
228+
public function testConfigIsPassed()
229+
{
230+
$config = ['foo' => 'bar'];
231+
Configure::write('DebugKit', $config);
232+
$layer = new DebugKitMiddleware();
233+
$prop = new \ReflectionProperty(DebugKitMiddleware::class, 'service');
234+
$prop->setAccessible(true);
235+
$service = $prop->getValue($layer);
236+
$this->assertEquals('bar', $service->getConfig('foo'));
237+
}
208238
}

0 commit comments

Comments
 (0)