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 3cd695d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 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
2 changes: 1 addition & 1 deletion 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
19 changes: 10 additions & 9 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 @@ -94,7 +95,7 @@ public function testGetMinimumLogLevelFromConfiguration()
*
* {@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 3cd695d

Please sign in to comment.