Skip to content

Commit

Permalink
Update Log usage of StaticConfigTrait
Browse files Browse the repository at this point in the history
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 f6709f1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Log/Log.php
Expand Up @@ -105,7 +105,7 @@ class Log
{

use StaticConfigTrait {
config as protected _config;
setConfig as protected _setConfig;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
27 changes: 27 additions & 0 deletions tests/TestCase/Log/LogTest.php
Expand Up @@ -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.
Expand All @@ -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
*
Expand Down

0 comments on commit f6709f1

Please sign in to comment.