mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
unify engine to not require the suffix (as Cache and other places do).
This commit is contained in:
parent
0d486bdab4
commit
cb24dbb084
5 changed files with 129 additions and 25 deletions
|
@ -34,7 +34,7 @@ App::uses('LogEngineCollection', 'Log');
|
|||
* A sample configuration would look like:
|
||||
*
|
||||
* {{{
|
||||
* CakeLog::config('my_log', array('engine' => 'FileLog'));
|
||||
* CakeLog::config('my_log', array('engine' => 'File'));
|
||||
* }}}
|
||||
*
|
||||
* See the documentation on CakeLog::config() for more detail.
|
||||
|
@ -133,7 +133,7 @@ class CakeLog {
|
|||
*
|
||||
* {{{
|
||||
* CakeLog::config('second_file', array(
|
||||
* 'engine' => 'FileLog',
|
||||
* 'engine' => 'File',
|
||||
* 'path' => '/var/logs/my_app/'
|
||||
* ));
|
||||
* }}}
|
||||
|
@ -378,7 +378,7 @@ class CakeLog {
|
|||
*/
|
||||
protected static function _autoConfig() {
|
||||
self::$_Collection->load('default', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'path' => LOGS,
|
||||
));
|
||||
}
|
||||
|
|
|
@ -63,7 +63,9 @@ class LogEngineCollection extends ObjectCollection {
|
|||
*/
|
||||
protected static function _getLogger($loggerName) {
|
||||
list($plugin, $loggerName) = pluginSplit($loggerName, true);
|
||||
|
||||
if (substr($loggerName, -3) !== 'Log') {
|
||||
$loggerName .= 'Log';
|
||||
}
|
||||
App::uses($loggerName, $plugin . 'Log/Engine');
|
||||
if (!class_exists($loggerName)) {
|
||||
throw new CakeLogException(__d('cake_dev', 'Could not load class %s', $loggerName));
|
||||
|
|
|
@ -87,6 +87,18 @@ class CakeLogTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testValidKeyName() {
|
||||
CakeLog::config('valid', array('engine' => 'File'));
|
||||
$stream = CakeLog::stream('valid');
|
||||
$this->assertInstanceOf('FileLog', $stream);
|
||||
CakeLog::drop('valid');
|
||||
}
|
||||
|
||||
/**
|
||||
* test config() with valid key name including the deprecated Log suffix
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidKeyNameLogSuffix() {
|
||||
CakeLog::config('valid', array('engine' => 'FileLog'));
|
||||
$stream = CakeLog::stream('valid');
|
||||
$this->assertInstanceOf('FileLog', $stream);
|
||||
|
@ -100,7 +112,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testInvalidKeyName() {
|
||||
CakeLog::config('1nv', array('engine' => 'FileLog'));
|
||||
CakeLog::config('1nv', array('engine' => 'File'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,7 +156,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
*/
|
||||
public function testConfig() {
|
||||
CakeLog::config('file', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'path' => LOGS
|
||||
));
|
||||
$result = CakeLog::configured();
|
||||
|
@ -168,7 +180,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
*/
|
||||
public function testDrop() {
|
||||
CakeLog::config('file', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'path' => LOGS
|
||||
));
|
||||
$result = CakeLog::configured();
|
||||
|
@ -214,12 +226,12 @@ class CakeLogTest extends CakeTestCase {
|
|||
unlink(LOGS . 'eggs.log');
|
||||
}
|
||||
CakeLog::config('spam', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => 'debug',
|
||||
'file' => 'spam',
|
||||
));
|
||||
CakeLog::config('eggs', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('eggs', 'debug', 'error', 'warning'),
|
||||
'file' => 'eggs',
|
||||
));
|
||||
|
@ -253,7 +265,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
*/
|
||||
public function testStreamEnable() {
|
||||
CakeLog::config('spam', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'file' => 'spam',
|
||||
));
|
||||
$this->assertTrue(CakeLog::enabled('spam'));
|
||||
|
@ -268,7 +280,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
*/
|
||||
public function testStreamDisable() {
|
||||
CakeLog::config('spam', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'file' => 'spam',
|
||||
));
|
||||
$this->assertTrue(CakeLog::enabled('spam'));
|
||||
|
@ -298,12 +310,12 @@ class CakeLogTest extends CakeTestCase {
|
|||
|
||||
protected function _resetLogConfig() {
|
||||
CakeLog::config('debug', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('notice', 'info', 'debug'),
|
||||
'file' => 'debug',
|
||||
));
|
||||
CakeLog::config('error', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
|
||||
'file' => 'error',
|
||||
));
|
||||
|
@ -339,7 +351,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
$this->_resetLogConfig();
|
||||
|
||||
CakeLog::config('shops', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('info', 'notice', 'warning'),
|
||||
'scopes' => array('transactions', 'orders'),
|
||||
'file' => 'shops',
|
||||
|
@ -393,13 +405,13 @@ class CakeLogTest extends CakeTestCase {
|
|||
$this->_deleteLogs();
|
||||
|
||||
CakeLog::config('shops', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('info', 'notice', 'warning'),
|
||||
'scopes' => array('transactions', 'orders'),
|
||||
'file' => 'shops.log',
|
||||
));
|
||||
CakeLog::config('eggs', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('info', 'notice', 'warning'),
|
||||
'scopes' => array('eggs'),
|
||||
'file' => 'eggs.log',
|
||||
|
@ -426,7 +438,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
$this->_deleteLogs();
|
||||
|
||||
CakeLog::config('string-scope', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('info', 'notice', 'warning'),
|
||||
'scopes' => 'string-scope',
|
||||
'file' => 'string-scope.log'
|
||||
|
@ -437,7 +449,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
CakeLog::drop('string-scope');
|
||||
|
||||
CakeLog::config('shops', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('info', 'notice', 'warning'),
|
||||
'scopes' => array('transactions', 'orders'),
|
||||
'file' => 'shops.log',
|
||||
|
@ -526,7 +538,7 @@ class CakeLogTest extends CakeTestCase {
|
|||
|
||||
$this->_resetLogConfig();
|
||||
CakeLog::config('shops', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('info', 'debug', 'notice', 'warning'),
|
||||
'scopes' => array('transactions', 'orders'),
|
||||
'file' => 'shops',
|
||||
|
@ -563,12 +575,12 @@ class CakeLogTest extends CakeTestCase {
|
|||
$this->_deleteLogs();
|
||||
|
||||
CakeLog::config('debug', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('notice', 'info', 'debug'),
|
||||
'file' => 'debug',
|
||||
));
|
||||
CakeLog::config('error', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('emergency', 'alert', 'critical', 'error', 'warning'),
|
||||
'file' => 'error',
|
||||
));
|
||||
|
@ -677,12 +689,12 @@ class CakeLogTest extends CakeTestCase {
|
|||
$this->assertContains('Error: ' . $testMessage, $contents);
|
||||
|
||||
CakeLog::config('spam', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'file' => 'spam.log',
|
||||
'types' => 'spam',
|
||||
));
|
||||
CakeLog::config('eggs', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'file' => 'eggs.log',
|
||||
'types' => array('spam', 'eggs'),
|
||||
));
|
||||
|
|
|
@ -52,12 +52,12 @@ class ConsoleLogTest extends CakeTestCase {
|
|||
public function setUp() {
|
||||
parent::setUp();
|
||||
CakeLog::config('debug', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('notice', 'info', 'debug'),
|
||||
'file' => 'debug',
|
||||
));
|
||||
CakeLog::config('error', array(
|
||||
'engine' => 'FileLog',
|
||||
'engine' => 'File',
|
||||
'types' => array('error', 'warning'),
|
||||
'file' => 'error',
|
||||
));
|
||||
|
|
90
lib/Cake/Test/Case/Log/LogEngineCollectionTest.php
Normal file
90
lib/Cake/Test/Case/Log/LogEngineCollectionTest.php
Normal file
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
/**
|
||||
* LogEngineCollectionTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Log
|
||||
* @since CakePHP(tm) v 2.4
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
App::uses('LogEngineCollection', 'Log');
|
||||
App::uses('FileLog', 'Log/Engine');
|
||||
|
||||
/**
|
||||
* LoggerEngineLog class
|
||||
*/
|
||||
class LoggerEngineLog extends FileLog {
|
||||
}
|
||||
|
||||
/**
|
||||
* LogEngineCollectionTest class
|
||||
*
|
||||
* @package Cake.Test.Case.Log
|
||||
*/
|
||||
class LogEngineCollectionTest extends CakeTestCase {
|
||||
|
||||
public $Collection;
|
||||
|
||||
/**
|
||||
* Start test callback
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->Collection = new LogEngineCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* test load
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoad() {
|
||||
$result = $this->Collection->load('key', array('engine' => 'File'));
|
||||
$this->assertInstanceOf('CakeLogInterface', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test load with deprecated Log suffix
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadWithSuffix() {
|
||||
$result = $this->Collection->load('key', array('engine' => 'FileLog'));
|
||||
$this->assertInstanceOf('CakeLogInterface', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that engines starting with Log also work properly
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadWithSuffixAtBeginning() {
|
||||
$result = $this->Collection->load('key', array('engine' => 'LoggerEngine'));
|
||||
$this->assertInstanceOf('CakeLogInterface', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test load with invalid Log
|
||||
*
|
||||
* @return void
|
||||
* @expectedException CakeLogException
|
||||
*/
|
||||
public function testLoadInvalid() {
|
||||
$result = $this->Collection->load('key', array('engine' => 'ImaginaryFile'));
|
||||
$this->assertInstanceOf('CakeLogInterface', $result);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue