Skip to content

Commit

Permalink
use a better assert
Browse files Browse the repository at this point in the history
at least the default error message will be meaningful
  • Loading branch information
AD7six committed Mar 29, 2014
1 parent f58b767 commit fad9410
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions tests/TestCase/Log/LogTest.php
Expand Up @@ -210,7 +210,7 @@ public function testLogFileWriting() {
}
$result = Log::write(LOG_WARNING, 'Test warning');
$this->assertTrue($result);
$this->assertTrue(file_exists(LOGS . 'error.log'));
$this->assertFileExists(LOGS . 'error.log');
unlink(LOGS . 'error.log');

Log::write(LOG_WARNING, 'Test warning 1');
Expand Down Expand Up @@ -247,11 +247,11 @@ public function testSelectiveLoggingByLevel() {
$testMessage = 'selective logging';
Log::write(LOG_WARNING, $testMessage);

$this->assertTrue(file_exists(LOGS . 'eggs.log'));
$this->assertFalse(file_exists(LOGS . 'spam.log'));
$this->assertFileExists(LOGS . 'eggs.log');
$this->assertFileNotExists(LOGS . 'spam.log');

Log::write(LOG_DEBUG, $testMessage);
$this->assertTrue(file_exists(LOGS . 'spam.log'));
$this->assertFileExists(LOGS . 'spam.log');

$contents = file_get_contents(LOGS . 'spam.log');
$this->assertContains('Debug: ' . $testMessage, $contents);
Expand Down Expand Up @@ -316,23 +316,23 @@ public function testScopedLogging() {
));

Log::write('info', 'info message', 'transactions');
$this->assertFalse(file_exists(LOGS . 'error.log'));
$this->assertTrue(file_exists(LOGS . 'shops.log'));
$this->assertTrue(file_exists(LOGS . 'debug.log'));
$this->assertFileNotExists(LOGS . 'error.log');
$this->assertFileExists(LOGS . 'shops.log');
$this->assertFileExists(LOGS . 'debug.log');

$this->_deleteLogs();

Log::write('warning', 'warning message', 'orders');
$this->assertTrue(file_exists(LOGS . 'error.log'));
$this->assertTrue(file_exists(LOGS . 'shops.log'));
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->assertFileExists(LOGS . 'error.log');
$this->assertFileExists(LOGS . 'shops.log');
$this->assertFileNotExists(LOGS . 'debug.log');

$this->_deleteLogs();

Log::write('error', 'error message', 'orders');
$this->assertTrue(file_exists(LOGS . 'error.log'));
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->assertFalse(file_exists(LOGS . 'shops.log'));
$this->assertFileExists(LOGS . 'error.log');
$this->assertFileNotExists(LOGS . 'debug.log');
$this->assertFileNotExists(LOGS . 'shops.log');

$this->_deleteLogs();

Expand Down Expand Up @@ -362,23 +362,23 @@ public function testConvenienceScopedLogging() {
));

Log::info('info message', 'transactions');
$this->assertFalse(file_exists(LOGS . 'error.log'));
$this->assertTrue(file_exists(LOGS . 'shops.log'));
$this->assertTrue(file_exists(LOGS . 'debug.log'));
$this->assertFileNotExists(LOGS . 'error.log');
$this->assertFileExists(LOGS . 'shops.log');
$this->assertFileExists(LOGS . 'debug.log');

$this->_deleteLogs();

Log::error('error message', 'orders');
$this->assertTrue(file_exists(LOGS . 'error.log'));
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->assertFalse(file_exists(LOGS . 'shops.log'));
$this->assertFileExists(LOGS . 'error.log');
$this->assertFileNotExists(LOGS . 'debug.log');
$this->assertFileNotExists(LOGS . 'shops.log');

$this->_deleteLogs();

Log::warning('warning message', 'orders');
$this->assertTrue(file_exists(LOGS . 'error.log'));
$this->assertTrue(file_exists(LOGS . 'shops.log'));
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->assertFileExists(LOGS . 'error.log');
$this->assertFileExists(LOGS . 'shops.log');
$this->assertFileNotExists(LOGS . 'debug.log');

$this->_deleteLogs();

Expand Down Expand Up @@ -407,14 +407,14 @@ public function testScopedLoggingExclusive() {
));

Log::write('info', 'transactions message', 'transactions');
$this->assertFalse(file_exists(LOGS . 'eggs.log'));
$this->assertTrue(file_exists(LOGS . 'shops.log'));
$this->assertFileNotExists(LOGS . 'eggs.log');
$this->assertFileExists(LOGS . 'shops.log');

$this->_deleteLogs();

Log::write('info', 'eggs message', 'eggs');
$this->assertTrue(file_exists(LOGS . 'eggs.log'));
$this->assertFalse(file_exists(LOGS . 'shops.log'));
$this->assertFileExists(LOGS . 'eggs.log');
$this->assertFileNotExists(LOGS . 'shops.log');
}

/**
Expand Down Expand Up @@ -465,56 +465,56 @@ public function testConvenienceMethods() {
Log::emergency($testMessage);
$contents = file_get_contents(LOGS . 'error.log');
$this->assertRegExp('/(Emergency|Critical): ' . $testMessage . '/', $contents);
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->assertFileNotExists(LOGS . 'debug.log');
$this->_deleteLogs();

$testMessage = 'alert message';
Log::alert($testMessage);
$contents = file_get_contents(LOGS . 'error.log');
$this->assertRegExp('/(Alert|Critical): ' . $testMessage . '/', $contents);
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->assertFileNotExists(LOGS . 'debug.log');
$this->_deleteLogs();

$testMessage = 'critical message';
Log::critical($testMessage);
$contents = file_get_contents(LOGS . 'error.log');
$this->assertContains('Critical: ' . $testMessage, $contents);
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->assertFileNotExists(LOGS . 'debug.log');
$this->_deleteLogs();

$testMessage = 'error message';
Log::error($testMessage);
$contents = file_get_contents(LOGS . 'error.log');
$this->assertContains('Error: ' . $testMessage, $contents);
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->assertFileNotExists(LOGS . 'debug.log');
$this->_deleteLogs();

$testMessage = 'warning message';
Log::warning($testMessage);
$contents = file_get_contents(LOGS . 'error.log');
$this->assertContains('Warning: ' . $testMessage, $contents);
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->assertFileNotExists(LOGS . 'debug.log');
$this->_deleteLogs();

$testMessage = 'notice message';
Log::notice($testMessage);
$contents = file_get_contents(LOGS . 'debug.log');
$this->assertRegExp('/(Notice|Debug): ' . $testMessage . '/', $contents);
$this->assertFalse(file_exists(LOGS . 'error.log'));
$this->assertFileNotExists(LOGS . 'error.log');
$this->_deleteLogs();

$testMessage = 'info message';
Log::info($testMessage);
$contents = file_get_contents(LOGS . 'debug.log');
$this->assertRegExp('/(Info|Debug): ' . $testMessage . '/', $contents);
$this->assertFalse(file_exists(LOGS . 'error.log'));
$this->assertFileNotExists(LOGS . 'error.log');
$this->_deleteLogs();

$testMessage = 'debug message';
Log::debug($testMessage);
$contents = file_get_contents(LOGS . 'debug.log');
$this->assertContains('Debug: ' . $testMessage, $contents);
$this->assertFalse(file_exists(LOGS . 'error.log'));
$this->assertFileNotExists(LOGS . 'error.log');
$this->_deleteLogs();
}

Expand Down

0 comments on commit fad9410

Please sign in to comment.