diff --git a/_config.php b/_config.php index 1ab6c06..72970fe 100644 --- a/_config.php +++ b/_config.php @@ -26,11 +26,11 @@ function d() if (isset($args[0]) && $args[0] instanceof \SilverStripe\Dev\SapphireTest) { $doExit = false; array_shift($args); - } - - // Clean buffer that may be in the way - if (ob_get_contents()) { - ob_end_clean(); + } else { + // Clean buffer that may be in the way + if (ob_get_contents()) { + ob_end_clean(); + } } $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); @@ -72,23 +72,22 @@ function d() } foreach ($args as $arg) { if ($isPlain && $arg === "") { - echo "(empty)"; - continue; - } - if ($isPlain && $arg === null) { - echo "(null)"; - continue; - } - if (is_string($arg)) { - echo $arg; - } else { + $arg = "(empty)"; + } elseif ($isPlain && $arg === null) { + $arg = "(null)"; + } elseif (!is_string($arg)) { // Avoid print_r on object as it can cause massive recursion if (is_object($arg)) { - echo get_class($arg) . "\n"; + $arg = get_class($arg); + } else { + $arg = json_encode($arg, JSON_PRETTY_PRINT, 5); } - echo json_encode($arg, JSON_PRETTY_PRINT, 5); } - echo "\n"; + $arg = trim($arg); + if (strlen($arg) > 255) { + $arg = substr($arg, 0, 252) . "..."; + } + echo $arg . "\n"; } if (!$isPlain) { echo ''; diff --git a/code/DebugBar.php b/code/DebugBar.php index 78e45af..102360e 100644 --- a/code/DebugBar.php +++ b/code/DebugBar.php @@ -36,16 +36,16 @@ use LeKoala\DebugBar\Collector\ConfigCollector; use LeKoala\DebugBar\Proxy\ConfigManifestProxy; use LeKoala\DebugBar\Collector\PhpInfoCollector; +use LeKoala\DebugBar\Extension\ProxyDBExtension; use LeKoala\DebugBar\Collector\DatabaseCollector; use LeKoala\DebugBar\Collector\TimeDataCollector; use DebugBar\Bridge\SwiftMailer\SwiftLogCollector; use DebugBar\Bridge\SwiftMailer\SwiftMailCollector; +use LeKoala\DebugBar\Proxy\DeltaConfigManifestProxy; use LeKoala\DebugBar\Collector\PartialCacheCollector; use LeKoala\DebugBar\Collector\SilverStripeCollector; -use LeKoala\DebugBar\Middleware\DebugBarConfigMiddleware; -use LeKoala\DebugBar\Proxy\DeltaConfigManifestProxy; -use SilverStripe\Config\Collections\CachedConfigCollection; use SilverStripe\Config\Collections\DeltaConfigCollection; +use SilverStripe\Config\Collections\CachedConfigCollection; /** * A simple helper @@ -266,6 +266,12 @@ protected static function setProtectedValue($object, $property, $newValue) public static function clearDebugBar() { self::$debugbar = null; + self::$bufferingEnabled = false; + self::$renderer = null; + self::$showQueries = false; + self::$request = null; + self::$extraTimes = []; + ProxyDBExtension::resetQueries(); } /** diff --git a/tests/Collector/ConfigCollectorTest.php b/tests/Collector/ConfigCollectorTest.php index 031be73..268d92e 100644 --- a/tests/Collector/ConfigCollectorTest.php +++ b/tests/Collector/ConfigCollectorTest.php @@ -26,6 +26,14 @@ protected function setUp() $this->collector = new ConfigCollector(); } + public function tearDown() + { + DebugBar::clearDebugBar(); + $this->collector = null; + + parent::tearDown(); + } + public function testGetName() { $this->assertNotEmpty($this->collector->getName()); diff --git a/tests/Collector/DatabaseCollectorTest.php b/tests/Collector/DatabaseCollectorTest.php index 207af0a..ae37009 100644 --- a/tests/Collector/DatabaseCollectorTest.php +++ b/tests/Collector/DatabaseCollectorTest.php @@ -26,6 +26,14 @@ public function setUp() $this->collector = DebugBar::getDebugBar()->getCollector('db'); } + public function tearDown() + { + DebugBar::clearDebugBar(); + $this->collector = null; + + parent::tearDown(); + } + public function testCollectorExists() { $this->assertInstanceOf(DatabaseCollector::class, $this->collector); @@ -63,9 +71,6 @@ public function testCollect() $this->assertNotEmpty($result['statements']); $statement = array_shift($result['statements']); $this->assertTrue($statement['warn']); - - // Avoid memory leaks - ProxyDBExtension::resetQueries(); } public function testGetWidgets() diff --git a/tests/Collector/PartialCacheCollectorTest.php b/tests/Collector/PartialCacheCollectorTest.php index d2f6d89..12aa3d2 100644 --- a/tests/Collector/PartialCacheCollectorTest.php +++ b/tests/Collector/PartialCacheCollectorTest.php @@ -2,8 +2,9 @@ namespace LeKoala\DebugBar\Test\Collector; -use LeKoala\DebugBar\Collector\PartialCacheCollector; +use LeKoala\DebugBar\DebugBar; use SilverStripe\Dev\SapphireTest; +use LeKoala\DebugBar\Collector\PartialCacheCollector; class PartialCacheCollectorTest extends SapphireTest { @@ -18,6 +19,14 @@ protected function setUp() $this->collector = new PartialCacheCollector(); } + public function tearDown() + { + DebugBar::clearDebugBar(); + $this->collector = null; + + parent::tearDown(); + } + public function testGetName() { $this->assertNotEmpty($this->collector->getName()); diff --git a/tests/Collector/SilverStripeCollectorTest.php b/tests/Collector/SilverStripeCollectorTest.php index 9526397..e818cf8 100644 --- a/tests/Collector/SilverStripeCollectorTest.php +++ b/tests/Collector/SilverStripeCollectorTest.php @@ -28,6 +28,14 @@ public function setUp() $this->collector = DebugBar::getDebugBar()->getCollector('silverstripe'); } + public function tearDown() + { + DebugBar::clearDebugBar(); + $this->collector = null; + + parent::tearDown(); + } + public function testCollectorExists() { $this->assertInstanceOf(SilverStripeCollector::class, $this->collector); diff --git a/tests/Collector/TimeDataCollectorTest.php b/tests/Collector/TimeDataCollectorTest.php index d76052c..f1e9c89 100644 --- a/tests/Collector/TimeDataCollectorTest.php +++ b/tests/Collector/TimeDataCollectorTest.php @@ -20,6 +20,14 @@ public function setUp() $this->collector = new TimeDataCollector(microtime(true)); } + public function tearDown() + { + DebugBar::clearDebugBar(); + $this->collector = null; + + parent::tearDown(); + } + public function testCollectorTooltip() { $result = $this->collector->getWidgets(); diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index e57edda..f07afd7 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -8,6 +8,7 @@ class ControllerTest extends FunctionalTest { + public function tearDown() { parent::tearDown(); diff --git a/tests/Proxy/SSViewerProxyTest.php b/tests/Proxy/SSViewerProxyTest.php index 5441d31..6d54b65 100644 --- a/tests/Proxy/SSViewerProxyTest.php +++ b/tests/Proxy/SSViewerProxyTest.php @@ -2,14 +2,23 @@ namespace LeKoala\DebugBar\Test\Proxy; -use LeKoala\DebugBar\Proxy\SSViewerProxy; -use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\FunctionalTest; -use SilverStrpe\Forms\TextField; +use LeKoala\DebugBar\DebugBar; use SilverStripe\View\SSViewer; +use SilverStrpe\Forms\TextField; +use SilverStripe\Dev\FunctionalTest; +use SilverStripe\Core\Injector\Injector; +use LeKoala\DebugBar\Proxy\SSViewerProxy; class SSViewerProxyTest extends FunctionalTest { + public function setUp() + { + parent::setUp(); + + // Init manually because we are running tests + DebugBar::initDebugBar(); + } + public function testOverloadsSSViewer() { $templateParser = Injector::inst()->create(SSViewer::class, ['SilverStripe/Forms/Includes/Form']); @@ -21,6 +30,11 @@ public function testTrackTemplatesUsed() { $this->get('/Security/login'); + if (!DebugBar::getDebugBar()) { + $this->markTestSkipped("No instance available"); + return; + } + $templates = SSViewerProxy::getTemplatesUsed(); $formPath = '/vendor/silverstripe/framework/templates/SilverStripe/Forms/Includes/Form.ss';