Skip to content

Commit

Permalink
Merge pull request #1425 from jim-parry/fix/filehandlertest
Browse files Browse the repository at this point in the history
Ensure FileHandlerTest uses MockFileHandler
  • Loading branch information
jim-parry authored Nov 8, 2018
2 parents 6c86e11 + 05cee78 commit 86587e6
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions tests/system/Log/FileHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,44 @@ class FileHandlerTest extends \CIUnitTestCase

public function setUp()
{
$this->root = vfsStream::setup('root');
$this->root = vfsStream::setup('root');
$this->start = $this->root->url() . '/';
}

public function testHandle()
{
$config = new LoggerConfig();
$config = new LoggerConfig();
$config->handlers['Tests\Support\Log\Handlers\TestHandler']['handles'] = ['critical'];

$logger = new FileHandler($config->handlers['Tests\Support\Log\Handlers\TestHandler']);
$logger->setDateFormat("Y-m-d H:i:s:u");
$this->assertTrue($logger->handle("warning", "This is a test log"));
$logger = new MockFileHandler($config->handlers['Tests\Support\Log\Handlers\TestHandler']);
$logger->setDateFormat('Y-m-d H:i:s:u');
$this->assertTrue($logger->handle('warning', 'This is a test log'));
}

//--------------------------------------------------------------------

public function testBasicHandle()
{
$config = new LoggerConfig();
$config->path = $this->start . 'charlie/';
$config = new LoggerConfig();
$config->path = $this->start . 'charlie/';
$config->handlers['Tests\Support\Log\Handlers\TestHandler']['handles'] = ['critical'];
$logger = new MockFileHandler($config->handlers['Tests\Support\Log\Handlers\TestHandler']);
$logger->setDateFormat("Y-m-d H:i:s:u");
$this->assertTrue($logger->handle("warning", "This is a test log"));
$logger = new MockFileHandler($config->handlers['Tests\Support\Log\Handlers\TestHandler']);
$logger->setDateFormat('Y-m-d H:i:s:u');
$this->assertTrue($logger->handle('warning', 'This is a test log'));
}

public function testHandleCreateFile()
{
$config = new LoggerConfig();
$config = new LoggerConfig();
$config->path = $this->start;
$logger = new MockFileHandler((array) $config);
$logger = new MockFileHandler((array) $config);

$logger->setDateFormat("Y-m-d H:i:s:u");
$logger->handle("warning", "This is a test log");
$logger->setDateFormat('Y-m-d H:i:s:u');
$logger->handle('warning', 'This is a test log');

$expected = 'log-' . date('Y-m-d') . '.php';
$fp = fopen($config->path . $expected, 'r');
$line = fgets($fp);
$fp = fopen($config->path . $expected, 'r');
$line = fgets($fp);
fclose($fp);

// did the log file get created?
Expand All @@ -56,16 +56,16 @@ public function testHandleCreateFile()

public function testHandleDateTimeCorrectly()
{
$config = new LoggerConfig();
$config = new LoggerConfig();
$config->path = $this->start;
$logger = new MockFileHandler((array) $config);
$logger = new MockFileHandler((array) $config);

$logger->setDateFormat('Y-m-d');
$expected = 'log-' . date('Y-m-d') . '.php';

$logger->handle('debug', 'Test message');

$fp = fopen($config->path . $expected, 'r');
$fp = fopen($config->path . $expected, 'r');
$line = fgets($fp); // skip opening PHP tag
$line = fgets($fp); // skip blank line
$line = fgets($fp); // and get the second line
Expand Down

0 comments on commit 86587e6

Please sign in to comment.