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:
|
* 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.
|
* See the documentation on CakeLog::config() for more detail.
|
||||||
|
@ -133,7 +133,7 @@ class CakeLog {
|
||||||
*
|
*
|
||||||
* {{{
|
* {{{
|
||||||
* CakeLog::config('second_file', array(
|
* CakeLog::config('second_file', array(
|
||||||
* 'engine' => 'FileLog',
|
* 'engine' => 'File',
|
||||||
* 'path' => '/var/logs/my_app/'
|
* 'path' => '/var/logs/my_app/'
|
||||||
* ));
|
* ));
|
||||||
* }}}
|
* }}}
|
||||||
|
@ -378,7 +378,7 @@ class CakeLog {
|
||||||
*/
|
*/
|
||||||
protected static function _autoConfig() {
|
protected static function _autoConfig() {
|
||||||
self::$_Collection->load('default', array(
|
self::$_Collection->load('default', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'path' => LOGS,
|
'path' => LOGS,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,9 @@ class LogEngineCollection extends ObjectCollection {
|
||||||
*/
|
*/
|
||||||
protected static function _getLogger($loggerName) {
|
protected static function _getLogger($loggerName) {
|
||||||
list($plugin, $loggerName) = pluginSplit($loggerName, true);
|
list($plugin, $loggerName) = pluginSplit($loggerName, true);
|
||||||
|
if (substr($loggerName, -3) !== 'Log') {
|
||||||
|
$loggerName .= 'Log';
|
||||||
|
}
|
||||||
App::uses($loggerName, $plugin . 'Log/Engine');
|
App::uses($loggerName, $plugin . 'Log/Engine');
|
||||||
if (!class_exists($loggerName)) {
|
if (!class_exists($loggerName)) {
|
||||||
throw new CakeLogException(__d('cake_dev', 'Could not load class %s', $loggerName));
|
throw new CakeLogException(__d('cake_dev', 'Could not load class %s', $loggerName));
|
||||||
|
|
|
@ -87,6 +87,18 @@ class CakeLogTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testValidKeyName() {
|
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'));
|
CakeLog::config('valid', array('engine' => 'FileLog'));
|
||||||
$stream = CakeLog::stream('valid');
|
$stream = CakeLog::stream('valid');
|
||||||
$this->assertInstanceOf('FileLog', $stream);
|
$this->assertInstanceOf('FileLog', $stream);
|
||||||
|
@ -100,7 +112,7 @@ class CakeLogTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testInvalidKeyName() {
|
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() {
|
public function testConfig() {
|
||||||
CakeLog::config('file', array(
|
CakeLog::config('file', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'path' => LOGS
|
'path' => LOGS
|
||||||
));
|
));
|
||||||
$result = CakeLog::configured();
|
$result = CakeLog::configured();
|
||||||
|
@ -168,7 +180,7 @@ class CakeLogTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testDrop() {
|
public function testDrop() {
|
||||||
CakeLog::config('file', array(
|
CakeLog::config('file', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'path' => LOGS
|
'path' => LOGS
|
||||||
));
|
));
|
||||||
$result = CakeLog::configured();
|
$result = CakeLog::configured();
|
||||||
|
@ -214,12 +226,12 @@ class CakeLogTest extends CakeTestCase {
|
||||||
unlink(LOGS . 'eggs.log');
|
unlink(LOGS . 'eggs.log');
|
||||||
}
|
}
|
||||||
CakeLog::config('spam', array(
|
CakeLog::config('spam', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => 'debug',
|
'types' => 'debug',
|
||||||
'file' => 'spam',
|
'file' => 'spam',
|
||||||
));
|
));
|
||||||
CakeLog::config('eggs', array(
|
CakeLog::config('eggs', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('eggs', 'debug', 'error', 'warning'),
|
'types' => array('eggs', 'debug', 'error', 'warning'),
|
||||||
'file' => 'eggs',
|
'file' => 'eggs',
|
||||||
));
|
));
|
||||||
|
@ -253,7 +265,7 @@ class CakeLogTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testStreamEnable() {
|
public function testStreamEnable() {
|
||||||
CakeLog::config('spam', array(
|
CakeLog::config('spam', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'file' => 'spam',
|
'file' => 'spam',
|
||||||
));
|
));
|
||||||
$this->assertTrue(CakeLog::enabled('spam'));
|
$this->assertTrue(CakeLog::enabled('spam'));
|
||||||
|
@ -268,7 +280,7 @@ class CakeLogTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testStreamDisable() {
|
public function testStreamDisable() {
|
||||||
CakeLog::config('spam', array(
|
CakeLog::config('spam', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'file' => 'spam',
|
'file' => 'spam',
|
||||||
));
|
));
|
||||||
$this->assertTrue(CakeLog::enabled('spam'));
|
$this->assertTrue(CakeLog::enabled('spam'));
|
||||||
|
@ -298,12 +310,12 @@ class CakeLogTest extends CakeTestCase {
|
||||||
|
|
||||||
protected function _resetLogConfig() {
|
protected function _resetLogConfig() {
|
||||||
CakeLog::config('debug', array(
|
CakeLog::config('debug', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('notice', 'info', 'debug'),
|
'types' => array('notice', 'info', 'debug'),
|
||||||
'file' => 'debug',
|
'file' => 'debug',
|
||||||
));
|
));
|
||||||
CakeLog::config('error', array(
|
CakeLog::config('error', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
|
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
|
||||||
'file' => 'error',
|
'file' => 'error',
|
||||||
));
|
));
|
||||||
|
@ -339,7 +351,7 @@ class CakeLogTest extends CakeTestCase {
|
||||||
$this->_resetLogConfig();
|
$this->_resetLogConfig();
|
||||||
|
|
||||||
CakeLog::config('shops', array(
|
CakeLog::config('shops', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('info', 'notice', 'warning'),
|
'types' => array('info', 'notice', 'warning'),
|
||||||
'scopes' => array('transactions', 'orders'),
|
'scopes' => array('transactions', 'orders'),
|
||||||
'file' => 'shops',
|
'file' => 'shops',
|
||||||
|
@ -393,13 +405,13 @@ class CakeLogTest extends CakeTestCase {
|
||||||
$this->_deleteLogs();
|
$this->_deleteLogs();
|
||||||
|
|
||||||
CakeLog::config('shops', array(
|
CakeLog::config('shops', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('info', 'notice', 'warning'),
|
'types' => array('info', 'notice', 'warning'),
|
||||||
'scopes' => array('transactions', 'orders'),
|
'scopes' => array('transactions', 'orders'),
|
||||||
'file' => 'shops.log',
|
'file' => 'shops.log',
|
||||||
));
|
));
|
||||||
CakeLog::config('eggs', array(
|
CakeLog::config('eggs', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('info', 'notice', 'warning'),
|
'types' => array('info', 'notice', 'warning'),
|
||||||
'scopes' => array('eggs'),
|
'scopes' => array('eggs'),
|
||||||
'file' => 'eggs.log',
|
'file' => 'eggs.log',
|
||||||
|
@ -426,7 +438,7 @@ class CakeLogTest extends CakeTestCase {
|
||||||
$this->_deleteLogs();
|
$this->_deleteLogs();
|
||||||
|
|
||||||
CakeLog::config('string-scope', array(
|
CakeLog::config('string-scope', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('info', 'notice', 'warning'),
|
'types' => array('info', 'notice', 'warning'),
|
||||||
'scopes' => 'string-scope',
|
'scopes' => 'string-scope',
|
||||||
'file' => 'string-scope.log'
|
'file' => 'string-scope.log'
|
||||||
|
@ -437,7 +449,7 @@ class CakeLogTest extends CakeTestCase {
|
||||||
CakeLog::drop('string-scope');
|
CakeLog::drop('string-scope');
|
||||||
|
|
||||||
CakeLog::config('shops', array(
|
CakeLog::config('shops', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('info', 'notice', 'warning'),
|
'types' => array('info', 'notice', 'warning'),
|
||||||
'scopes' => array('transactions', 'orders'),
|
'scopes' => array('transactions', 'orders'),
|
||||||
'file' => 'shops.log',
|
'file' => 'shops.log',
|
||||||
|
@ -526,7 +538,7 @@ class CakeLogTest extends CakeTestCase {
|
||||||
|
|
||||||
$this->_resetLogConfig();
|
$this->_resetLogConfig();
|
||||||
CakeLog::config('shops', array(
|
CakeLog::config('shops', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('info', 'debug', 'notice', 'warning'),
|
'types' => array('info', 'debug', 'notice', 'warning'),
|
||||||
'scopes' => array('transactions', 'orders'),
|
'scopes' => array('transactions', 'orders'),
|
||||||
'file' => 'shops',
|
'file' => 'shops',
|
||||||
|
@ -563,12 +575,12 @@ class CakeLogTest extends CakeTestCase {
|
||||||
$this->_deleteLogs();
|
$this->_deleteLogs();
|
||||||
|
|
||||||
CakeLog::config('debug', array(
|
CakeLog::config('debug', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('notice', 'info', 'debug'),
|
'types' => array('notice', 'info', 'debug'),
|
||||||
'file' => 'debug',
|
'file' => 'debug',
|
||||||
));
|
));
|
||||||
CakeLog::config('error', array(
|
CakeLog::config('error', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('emergency', 'alert', 'critical', 'error', 'warning'),
|
'types' => array('emergency', 'alert', 'critical', 'error', 'warning'),
|
||||||
'file' => 'error',
|
'file' => 'error',
|
||||||
));
|
));
|
||||||
|
@ -677,12 +689,12 @@ class CakeLogTest extends CakeTestCase {
|
||||||
$this->assertContains('Error: ' . $testMessage, $contents);
|
$this->assertContains('Error: ' . $testMessage, $contents);
|
||||||
|
|
||||||
CakeLog::config('spam', array(
|
CakeLog::config('spam', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'file' => 'spam.log',
|
'file' => 'spam.log',
|
||||||
'types' => 'spam',
|
'types' => 'spam',
|
||||||
));
|
));
|
||||||
CakeLog::config('eggs', array(
|
CakeLog::config('eggs', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'file' => 'eggs.log',
|
'file' => 'eggs.log',
|
||||||
'types' => array('spam', 'eggs'),
|
'types' => array('spam', 'eggs'),
|
||||||
));
|
));
|
||||||
|
|
|
@ -52,12 +52,12 @@ class ConsoleLogTest extends CakeTestCase {
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
CakeLog::config('debug', array(
|
CakeLog::config('debug', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('notice', 'info', 'debug'),
|
'types' => array('notice', 'info', 'debug'),
|
||||||
'file' => 'debug',
|
'file' => 'debug',
|
||||||
));
|
));
|
||||||
CakeLog::config('error', array(
|
CakeLog::config('error', array(
|
||||||
'engine' => 'FileLog',
|
'engine' => 'File',
|
||||||
'types' => array('error', 'warning'),
|
'types' => array('error', 'warning'),
|
||||||
'file' => 'error',
|
'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