mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-18 23:49:55 +00:00
updating tests for CakeLog
- ObjectCollection operations - Selective logging
This commit is contained in:
parent
68b49950af
commit
70177e4dbd
1 changed files with 112 additions and 1 deletions
|
@ -78,6 +78,28 @@ class CakeLogTest extends CakeTestCase {
|
||||||
CakeLog::config('fail', array());
|
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.
|
* test that loggers have to implement the correct interface.
|
||||||
*
|
*
|
||||||
|
@ -102,7 +124,7 @@ class CakeLogTest extends CakeTestCase {
|
||||||
$this->assertTrue(file_exists(LOGS . 'error.log'));
|
$this->assertTrue(file_exists(LOGS . 'error.log'));
|
||||||
|
|
||||||
$result = CakeLog::configured();
|
$result = CakeLog::configured();
|
||||||
$this->assertEquals(array('default'), $result);
|
$this->assertEquals(array('error'), $result);
|
||||||
unlink(LOGS . 'error.log');
|
unlink(LOGS . 'error.log');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,4 +192,93 @@ class CakeLogTest extends CakeTestCase {
|
||||||
unlink(LOGS . 'error.log');
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue