Skip to content
Permalink
Browse files

Update Log usage of StaticConfigTrait

If people were to start using `Log::setConfig()` the `Log` class would
misbehave. By overriding the new method we avoid that potential
breakage.
  • Loading branch information...
markstory committed Jan 29, 2017
1 parent 4cc6a9a commit f6709f12864fb9f288ca75a3e2f00daf1a5cdbdf
Showing with 30 additions and 3 deletions.
  1. +3 −3 src/Log/Log.php
  2. +27 −0 tests/TestCase/Log/LogTest.php
@@ -105,7 +105,7 @@ class Log
{
use StaticConfigTrait {
config as protected _config;
setConfig as protected _setConfig;
}
/**
@@ -276,9 +276,9 @@ public static function levels()
* @return array|null Null when adding configuration and an array of configuration data when reading.
* @throws \BadMethodCallException When trying to modify an existing config.
*/
public static function config($key, $config = null)
public static function setConfig($key, $config = null)
{
$return = static::_config($key, $config);
$return = static::_setConfig($key, $config);
if ($return !== null) {
return $return;
}
@@ -171,6 +171,20 @@ public function testConfigVariants($settings)
Log::drop('test');
}
/**
* Test the various setConfig call signatures.
*
* @dataProvider configProvider
* @return void
*/
public function testSetConfigVariants($settings)
{
Log::setConfig('test', $settings);
$this->assertContains('test', Log::configured());
$this->assertInstanceOf('Cake\Log\Engine\FileLog', Log::engine('test'));
Log::drop('test');
}
/**
* Test that config() throws an exception when adding an
* adapter with the wrong type.
@@ -184,6 +198,19 @@ public function testConfigInjectErrorOnWrongType()
Log::info('testing');
}
/**
* Test that setConfig() throws an exception when adding an
* adapter with the wrong type.
*
* @expectedException \RuntimeException
* @return void
*/
public function testSetConfigInjectErrorOnWrongType()
{
Log::setConfig('test', new \StdClass);
Log::info('testing');
}
/**
* Test that config() can read data back
*

0 comments on commit f6709f1

Please sign in to comment.
You can’t perform that action at this time.