Skip to content

Commit

Permalink
updating tests for CakeLog
Browse files Browse the repository at this point in the history
- ObjectCollection operations
- Selective logging
  • Loading branch information
rchavik committed May 11, 2012
1 parent 68b4995 commit 70177e4
Showing 1 changed file with 112 additions and 1 deletion.
113 changes: 112 additions & 1 deletion lib/Cake/Test/Case/Log/CakeLogTest.php
Expand Up @@ -78,6 +78,28 @@ public function testImportingLoggerFailure() {
CakeLog::config('fail', array());
}

/**
* test config() with valid key name
*
* @return void
*/
public function testValidKeyName() {
CakeLog::config('valid', array('engine' => 'FileLog'));
$stream = CakeLog::stream('valid');
$this->assertInstanceOf('FileLog', $stream);
CakeLog::drop('valid');
}

/**
* test config() with invalid key name
*
* @expectedException CakeLogException
* @return void
*/
public function testInvalidKeyName() {
CakeLog::config('1nv', array('engine' => 'FileLog'));
}

/**
* test that loggers have to implement the correct interface.
*
Expand All @@ -102,7 +124,7 @@ public function testAutoConfig() {
$this->assertTrue(file_exists(LOGS . 'error.log'));

$result = CakeLog::configured();
$this->assertEquals(array('default'), $result);
$this->assertEquals(array('error'), $result);
unlink(LOGS . 'error.log');
}

Expand Down Expand Up @@ -170,4 +192,93 @@ public function testLogFileWriting() {
unlink(LOGS . 'error.log');
}

/**
* test selective logging
*/
public function testSelectiveLogging() {
if (file_exists(LOGS . 'spam.log')) {
unlink(LOGS . 'spam.log');
}
if (file_exists(LOGS . 'eggs.log')) {
unlink(LOGS . 'eggs.log');
}
CakeLog::config('spam', array(
'engine' => 'FileLog',
'types' => 'info',
'file' => 'spam',
));
CakeLog::config('eggs', array(
'engine' => 'FileLog',
'types' => array('eggs', 'info', 'error', 'warning'),
'file' => 'eggs',
));

$testMessage = 'selective logging';
CakeLog::write(LOG_WARNING, $testMessage);

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

CakeLog::write(LOG_INFO, $testMessage);
$this->assertTrue(file_exists(LOGS . 'spam.log'));

$contents = file_get_contents(LOGS . 'spam.log');
$this->assertContains('Info: ' . $testMessage, $contents);
$contents = file_get_contents(LOGS . 'eggs.log');
$this->assertContains('Info: ' . $testMessage, $contents);

if (file_exists(LOGS . 'spam.log')) {
unlink(LOGS . 'spam.log');
}
if (file_exists(LOGS . 'eggs.log')) {
unlink(LOGS . 'eggs.log');
}
}

/**
* test enable
* @expectedException CakeLogException
*/
public function testStreamEnable() {
CakeLog::config('spam', array(
'engine' => 'FileLog',
'file' => 'spam',
));
$this->assertTrue(CakeLog::enabled('spam'));
CakeLog::drop('spam');
CakeLog::enable('bogus_stream');
}

/**
* test disable
* @expectedException CakeLogException
*/
public function testStreamDisable() {
CakeLog::config('spam', array(
'engine' => 'FileLog',
'file' => 'spam',
));
$this->assertTrue(CakeLog::enabled('spam'));
CakeLog::disable('spam');
$this->assertFalse(CakeLog::enabled('spam'));
CakeLog::drop('spam');
CakeLog::enable('bogus_stream');
}

/**
* test enabled() invalid stream
* @expectedException CakeLogException
*/
public function testStreamEnabledInvalid() {
CakeLog::enabled('bogus_stream');
}

/**
* test disable invalid stream
* @expectedException CakeLogException
*/
public function testStreamDisableInvalid() {
CakeLog::disable('bogus_stream');
}

}

0 comments on commit 70177e4

Please sign in to comment.