Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Mar 2, 2021
1 parent b906443 commit 2a25756
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 29 deletions.
35 changes: 17 additions & 18 deletions _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 '</pre>';
Expand Down
12 changes: 9 additions & 3 deletions code/DebugBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/Collector/ConfigCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
11 changes: 8 additions & 3 deletions tests/Collector/DatabaseCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 10 additions & 1 deletion tests/Collector/PartialCacheCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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());
Expand Down
8 changes: 8 additions & 0 deletions tests/Collector/SilverStripeCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions tests/Collector/TimeDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions tests/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class ControllerTest extends FunctionalTest
{

public function tearDown()
{
parent::tearDown();
Expand Down
22 changes: 18 additions & 4 deletions tests/Proxy/SSViewerProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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';
Expand Down

0 comments on commit 2a25756

Please sign in to comment.