Skip to content

Commit

Permalink
Test case upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
DevKCode committed Mar 5, 2023
1 parent 59a99dc commit 05982ea
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/Model/LogEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ public function getCMSFields()
{
$fields = parent::getCMSFields();

$data = Convert::json2obj($this->getField('Entry'));
$data = json_decode($this->getField('Entry'));
$fields->addFieldToTab(
'Root.Main',
LiteralField::create(
'Entry',
'<pre class="logviewer-logentry-entry"><code>'
. Convert::raw2json($data, JSON_PRETTY_PRINT)
. json_encode($data, JSON_PRETTY_PRINT)
. '</code></pre>'
)
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Admin/LogViewerAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LogViewerAdminTest extends FunctionalTest
/**
* {@inheritDoc}
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
8 changes: 4 additions & 4 deletions tests/Forms/GridField/GridFieldClearAllButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GridFieldClearAllButtonTest extends SapphireTest
/**
* {@inheritDoc}
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -67,9 +67,9 @@ public function testGetHtmlFragments()
$fragments = $this->getSubject()->getHTMLFragments($this->gridField);

$this->assertArrayHasKey('before', $fragments);
$this->assertContains('Clear all', $fragments['before']);
$this->assertContains('clear-all-logs', $fragments['before']);
$this->assertContains('font-icon-trash-bin action_clear', $fragments['before']);
$this->assertStringContainsString('Clear all', $fragments['before']);
$this->assertStringContainsString('clear-all-logs', $fragments['before']);
$this->assertStringContainsString('font-icon-trash-bin action_clear', $fragments['before']);
}

/**
Expand Down
23 changes: 12 additions & 11 deletions tests/Handler/DataObjectHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverLeague\LogViewer\Tests\Handler;

use Monolog\Logger;
use Psr\Log\LoggerInterface;
use SilverLeague\LogViewer\Handler\DataObjectHandler;
use SilverLeague\LogViewer\Model\LogEntry;
Expand All @@ -19,13 +20,13 @@ class DataObjectHandlerTest extends SapphireTest
* A Logger instance
* @var Monolog\Logger
*/
protected $logger;
protected Logger $logger;

/**
* The original logger handlers
* @var Monolog\LoggerInterface[]
*/
protected $originalHandlers = [];
protected $originalHandlers = [];

/**
* {@inheritDoc}
Expand All @@ -37,7 +38,7 @@ class DataObjectHandlerTest extends SapphireTest
*
* {@inheritDoc}
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand All @@ -54,10 +55,10 @@ public function setUp()
public function testWriteToDefaultLogger()
{
$this->logger->pushHandler(new DataObjectHandler);
$this->logger->addError('Hello world');
$this->logger->error('Hello world');

$logEntry = LogEntry::get()->first();
$this->assertContains('Hello world', $logEntry->Entry);
$this->assertStringContainsString('Hello world', $logEntry->Entry);
$this->assertSame('ERROR', $logEntry->Level);
}

Expand All @@ -70,13 +71,13 @@ public function testDontLogMessagesLowerThanMinimumLever()
LogEntry::get()->removeAll();
$this->logger->pushHandler(new DataObjectHandler);

$this->logger->addDebug('Debug');
$this->logger->debug('Debug');
$this->assertSame(0, LogEntry::get()->count());

$this->logger->addWarning('Warning');
$this->logger->warning('Warning');
$this->assertGreaterThan(0, LogEntry::get()->filter('Level', 'WARNING')->count());

$this->logger->addAlert('Alert');
$this->logger->alert('Alert');
$this->assertGreaterThan(0, LogEntry::get()->filter('Level', 'ALERT')->count());
}

Expand All @@ -85,16 +86,16 @@ public function testDontLogMessagesLowerThanMinimumLever()
*/
public function testGetMinimumLogLevelFromConfiguration()
{
Config::modify()->set(LogEntry::class, 'minimum_log_level', 123);
$this->assertSame(123, (new DataObjectHandler)->getMinimumLogLevel());
Config::modify()->set(LogEntry::class, 'minimum_log_level', 300);
$this->assertSame(300, (new DataObjectHandler)->getMinimumLogLevel());
}

/**
* Restore the original logger handlers
*
* {@inheritDoc}
*/
public function tearDown()
public function tearDown(): void
{
$this->logger->setHandlers($this->originalHandlers);

Expand Down
7 changes: 4 additions & 3 deletions tests/Model/LogEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ public function testLogEntriesAreFormattedAsJson()
];

$entry = LogEntry::create();
$entry->Entry = Convert::raw2json($data);
$entry->Entry = json_encode($data);


$fields = $entry->getCMSFields();
$field = $fields->fieldByName('Root.Main.Entry');

$this->assertInstanceOf(LiteralField::class, $field);
$this->assertContains(Convert::raw2json($data, JSON_PRETTY_PRINT), $field->getContent());
$this->assertContains('<pre class="logviewer-logentry-entry"><code>', $field->getContent());
$this->assertStringContainsString(json_encode($data, JSON_PRETTY_PRINT), $field->getContent());
$this->assertStringContainsString('<pre class="logviewer-logentry-entry"><code>', $field->getContent());
}
}
10 changes: 5 additions & 5 deletions tests/Task/RemoveOldLogEntriesTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class RemoveOldLogEntriesTaskTest extends SapphireTest
public function testClassProperties()
{
$task = new RemoveOldLogEntriesTask;
$this->assertContains('Remove LogEntry', $task->getTitle());
$this->assertContains('that are older than', $task->getDescription());
$this->assertStringContainsString('Remove LogEntry', $task->getTitle());
$this->assertStringContainsString('that are older than', $task->getDescription());
$this->assertSame('RemoveOldLogEntriesTask', Config::inst()->get(RemoveOldLogEntriesTask::class, 'segment'));
}

Expand Down Expand Up @@ -99,10 +99,10 @@ public function testRemoveOldLogEntries()
$buffer = ob_get_clean();

$this->assertTrue($result);
$this->assertContains('Removed 6 log(s)', $buffer);
$this->assertStringContainsString('Removed 6 log(s)', $buffer);
// Nothing to do the second time
$this->assertFalse($second);
$this->assertContains('Removed 0 log(s)', $buffer);
$this->assertContains('older than 1 day(s)', $buffer);
$this->assertStringContainsString('Removed 0 log(s)', $buffer);
$this->assertStringContainsString('older than 1 day(s)', $buffer);
}
}

0 comments on commit 05982ea

Please sign in to comment.