Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure FileHandlerTest uses MockFileHandler #1425

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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