Skip to content

Commit

Permalink
Merge pull request #16 from dotkernel/issue-15
Browse files Browse the repository at this point in the history
Issue #15: Fixed incorrect config passed to the ConfigCollector
  • Loading branch information
alexmerlin authored Jul 26, 2023
2 parents 7559142 + 4273afb commit 2d6f338
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/DebugBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(Configuration $configuration, array $config)
$this->addCollector($this->timeDataCollector = new TimeDataCollector());
$this->addCollector($this->exceptionsCollector = new ExceptionsCollector());

$this->config = $config;
$this->config = $config[self::class];

$this->getJavascriptRenderer()->addAssets(
[
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/DebugBarFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __invoke(ContainerInterface $container): DebugBar
$em = $container->get(EntityManager::class);
return new DebugBar(
$em->getConnection()->getConfiguration(),
$config
$container->get('config')
);
}
}
61 changes: 27 additions & 34 deletions test/DebugBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public function testCanCreate(): void
*/
public function testWillNotEnableIfConfigDisabled(): void
{
$config = $this->config[DebugBar::class];
$config['enabled'] = false;
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$config = $this->config;
$config[DebugBar::class]['enabled'] = false;
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$this->assertFalse($dotDebugBar->shouldEnable(''));
}

Expand All @@ -44,9 +44,8 @@ public function testWillNotEnableIfConfigDisabled(): void
*/
public function testWillNotEnableIfConfigEnabledButIpAddressIsInvalid(): void
{
$config = $this->config[DebugBar::class];
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$dotDebugBar = new DebugBar($configuration, $this->config);
$this->assertFalse($dotDebugBar->shouldEnable('test'));
}

Expand All @@ -56,9 +55,8 @@ public function testWillNotEnableIfConfigEnabledButIpAddressIsInvalid(): void
*/
public function testWillNotEnableIfConfigEnabledAndValidIpv4AddressNotWhitelisted(): void
{
$config = $this->config[DebugBar::class];
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$dotDebugBar = new DebugBar($configuration, $this->config);
$this->assertFalse($dotDebugBar->shouldEnable('127.0.0.1'));
}

Expand All @@ -68,9 +66,8 @@ public function testWillNotEnableIfConfigEnabledAndValidIpv4AddressNotWhiteliste
*/
public function testWillNotEnableIfConfigEnabledAndValidIpv6AddressNotWhitelisted(): void
{
$config = $this->config[DebugBar::class];
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$dotDebugBar = new DebugBar($configuration, $this->config);
$this->assertFalse(
$dotDebugBar->shouldEnable('::1')
);
Expand All @@ -82,10 +79,10 @@ public function testWillNotEnableIfConfigEnabledAndValidIpv6AddressNotWhiteliste
*/
public function testWillEnableIfConfigEnabledAndValidWhitelistedIpv4Address(): void
{
$config = $this->config[DebugBar::class];
$config['ipv4Whitelist'][] = '127.0.0.1';
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$config = $this->config;
$config[DebugBar::class]['ipv4Whitelist'][] = '127.0.0.1';
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$this->assertTrue($dotDebugBar->shouldEnable('127.0.0.1'));
}

Expand All @@ -95,10 +92,10 @@ public function testWillEnableIfConfigEnabledAndValidWhitelistedIpv4Address(): v
*/
public function testWillEnableIfConfigEnabledAndValidWhitelistedIpv6Address(): void
{
$config = $this->config[DebugBar::class];
$config['ipv6Whitelist'][] = '::1';
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$config = $this->config;
$config[DebugBar::class]['ipv6Whitelist'][] = '::1';
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$this->assertTrue($dotDebugBar->shouldEnable('::1'));
}

Expand All @@ -108,10 +105,10 @@ public function testWillEnableIfConfigEnabledAndValidWhitelistedIpv6Address(): v
*/
public function testWillEnableIfConfigEnabledAndAllowAnyValidIpv4Address(): void
{
$config = $this->config[DebugBar::class];
$config['ipv4Whitelist'][] = '*';
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$config = $this->config;
$config[DebugBar::class]['ipv4Whitelist'][] = '*';
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$this->assertTrue($dotDebugBar->shouldEnable('127.0.0.1'));
}

Expand All @@ -121,10 +118,10 @@ public function testWillEnableIfConfigEnabledAndAllowAnyValidIpv4Address(): void
*/
public function testWillEnableIfConfigEnabledAndAllowAnyValidIpv6Address(): void
{
$config = $this->config[DebugBar::class];
$config['ipv6Whitelist'][] = '*';
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$config = $this->config;
$config[DebugBar::class]['ipv6Whitelist'][] = '*';
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$this->assertTrue($dotDebugBar->shouldEnable('::1'));
}

Expand All @@ -134,9 +131,8 @@ public function testWillEnableIfConfigEnabledAndAllowAnyValidIpv6Address(): void
*/
public function testWillToggle(): void
{
$config = $this->config[DebugBar::class];
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$dotDebugBar = new DebugBar($configuration, $this->config);
$this->assertFalse($dotDebugBar->isEnabled());
$dotDebugBar->enable();
$this->assertInstanceOf(DebugBar::class, $dotDebugBar);
Expand All @@ -152,9 +148,8 @@ public function testWillToggle(): void
*/
public function testWillAddMessage(): void
{
$config = $this->config[DebugBar::class];
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$dotDebugBar = new DebugBar($configuration, $this->config);
$this->assertCount(0, $dotDebugBar->getMessagesCollector()->getMessages());
$dotDebugBar->addMessage('test');
$this->assertInstanceOf(DebugBar::class, $dotDebugBar);
Expand All @@ -167,9 +162,8 @@ public function testWillAddMessage(): void
*/
public function testWillStartStopMeasureTimer(): void
{
$config = $this->config[DebugBar::class];
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$dotDebugBar = new DebugBar($configuration, $this->config);
$this->assertFalse($dotDebugBar->getTimeDataCollector()->hasStartedMeasure('test'));
$dotDebugBar->startTimer('test');
$this->assertInstanceOf(DebugBar::class, $dotDebugBar);
Expand All @@ -185,9 +179,8 @@ public function testWillStartStopMeasureTimer(): void
*/
public function testWillAddThrowable(): void
{
$config = $this->config[DebugBar::class];
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, $config);
$dotDebugBar = new DebugBar($configuration, $this->config);
$this->assertCount(0, $dotDebugBar->getExceptionsCollector()->getExceptions());
$dotDebugBar->addThrowable(new \Exception('test'));
$this->assertInstanceOf(DebugBar::class, $dotDebugBar);
Expand Down
24 changes: 18 additions & 6 deletions test/Extension/DebugBarExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public function testGetFunctions(): void
public function testRenderDebugBarEnabledReturnsTrueWhenEnabled(): void
{
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, []);
$dotDebugBar = new DebugBar($configuration, [
DebugBar::class => [],
]);
$dotDebugBar->enable();

$extension = new DebugBarExtension($dotDebugBar, $this->config['application']['url']);
Expand All @@ -61,7 +63,9 @@ public function testRenderDebugBarEnabledReturnsTrueWhenEnabled(): void
public function testRenderDebugBarEnabledReturnsFalseWhenDisabled(): void
{
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, []);
$dotDebugBar = new DebugBar($configuration, [
DebugBar::class => [],
]);
$dotDebugBar->disable();

$extension = new DebugBarExtension($dotDebugBar, $this->config['application']['url']);
Expand All @@ -75,7 +79,9 @@ public function testRenderDebugBarEnabledReturnsFalseWhenDisabled(): void
public function testWillNotRenderDebugBarCssWhenDisabled(): void
{
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, []);
$dotDebugBar = new DebugBar($configuration, [
DebugBar::class => [],
]);
$dotDebugBar->disable();

$extension = new DebugBarExtension($dotDebugBar, $this->config['application']['url']);
Expand All @@ -89,7 +95,9 @@ public function testWillNotRenderDebugBarCssWhenDisabled(): void
public function testWillRenderDebugBarCssWhenEnabled(): void
{
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, []);
$dotDebugBar = new DebugBar($configuration, [
DebugBar::class => [],
]);
$dotDebugBar->enable();

$extension = new DebugBarExtension($dotDebugBar, $this->config['application']['url']);
Expand All @@ -105,7 +113,9 @@ public function testWillRenderDebugBarCssWhenEnabled(): void
public function testWillNotRenderDebugBarJsWhenDisabled(): void
{
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, []);
$dotDebugBar = new DebugBar($configuration, [
DebugBar::class => [],
]);
$dotDebugBar->disable();

$extension = new DebugBarExtension($dotDebugBar, $this->config['application']['url']);
Expand All @@ -119,7 +129,9 @@ public function testWillNotRenderDebugBarJsWhenDisabled(): void
public function testWillRenderDebugBarJsWhenEnabled(): void
{
$configuration = $this->createMock(Configuration::class);
$dotDebugBar = new DebugBar($configuration, []);
$dotDebugBar = new DebugBar($configuration, [
DebugBar::class => [],
]);
$dotDebugBar->enable();

$extension = new DebugBarExtension($dotDebugBar, $this->config['application']['url']);
Expand Down

0 comments on commit 2d6f338

Please sign in to comment.