Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update CI allow usage of custom user class and methods to be add in e…
…xtra info + tests (#4)
- Loading branch information
Showing
9 changed files
with
340 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/vendor | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
Tests/DependencyInjection/DeamonLoggerExtraExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?php | ||
|
||
namespace DependencyInjection; | ||
|
||
use Deamon\LoggerExtraBundle\DependencyInjection\DeamonLoggerExtraExtension; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class DeamonLoggerExtraExtensionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var DeamonLoggerExtraExtension | ||
*/ | ||
private $extension; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $root; | ||
|
||
/** | ||
* @var ContainerBuilder | ||
*/ | ||
private $container; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->extension = new DeamonLoggerExtraExtension(); | ||
$this->root = 'deamon_logger_extra'; | ||
$this->container = new ContainerBuilder(); | ||
} | ||
|
||
public function testLoad() | ||
{ | ||
$configs = [ | ||
$this->getValidConfigFull(), | ||
]; | ||
$this->extension->load($configs, $this->container); | ||
|
||
$this->assertTrue($this->container->hasDefinition('deamon.logger_extra.context')); | ||
$this->assertTrue($this->container->hasDefinition('deamon.logger_extra.processors.web_processor')); | ||
|
||
$definition1 = $this->container->getDefinition('deamon.logger_extra.context'); | ||
$this->assertEquals('foo', $definition1->getArgument(1)); | ||
|
||
$definition2 = $this->container->getDefinition('deamon.logger_extra.processors.web_processor'); | ||
$this->assertEquals($configs[0]['config'], $definition2->getArgument(1)); | ||
|
||
$this->assertTrue($definition2->hasTag('monolog.processor')); | ||
$tag = $definition2->getTag('monolog.processor'); | ||
$this->assertCount(1, $tag); | ||
$this->assertEquals('bar', $tag[0]['handler']); | ||
} | ||
|
||
public function testDefaultValue() | ||
{ | ||
$configs = [ | ||
$this->getValidConfigMin(), | ||
]; | ||
|
||
$defaultConfigValues = [ | ||
'channel_prefix' => null, | ||
'user_class' => '\Symfony\Component\Security\Core\User\UserInterface', | ||
'user_methods' => [ | ||
'user_name' => 'getUsername', | ||
], | ||
'display' => [ | ||
'env' => true, | ||
'locale' => true, | ||
'application_name' => true, | ||
'url' => true, | ||
'route' => true, | ||
'user_agent' => true, | ||
'accept_encoding' => true, | ||
'client_ip' => true, | ||
'user' => true, | ||
'global_channel' => true, | ||
], | ||
]; | ||
$this->extension->load($configs, $this->container); | ||
|
||
$this->assertTrue($this->container->hasDefinition('deamon.logger_extra.context')); | ||
$this->assertTrue($this->container->hasDefinition('deamon.logger_extra.processors.web_processor')); | ||
|
||
$definition1 = $this->container->getDefinition('deamon.logger_extra.context'); | ||
$this->assertNull($definition1->getArgument(1)); | ||
|
||
$definition2 = $this->container->getDefinition('deamon.logger_extra.processors.web_processor'); | ||
$this->assertEquals($defaultConfigValues, $definition2->getArgument(1)); | ||
} | ||
|
||
public function testConvertStringHandlerToArray() | ||
{ | ||
$configs = [ | ||
[ | ||
'application' => null, | ||
'handlers' => 'bar', | ||
'config' => null, | ||
], | ||
]; | ||
$this->extension->load($configs, $this->container); | ||
|
||
$this->assertTrue($this->container->hasDefinition('deamon.logger_extra.context')); | ||
$this->assertTrue($this->container->hasDefinition('deamon.logger_extra.processors.web_processor')); | ||
|
||
$definition = $this->container->getDefinition('deamon.logger_extra.processors.web_processor'); | ||
|
||
$this->assertTrue($definition->hasTag('monolog.processor')); | ||
$tag = $definition->getTag('monolog.processor'); | ||
$this->assertCount(1, $tag); | ||
$this->assertEquals('bar', $tag[0]['handler']); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getValidConfigFull() | ||
{ | ||
return [ | ||
'application' => [ | ||
'name' => 'foo', | ||
], | ||
'handlers' => ['bar'], | ||
'config' => [ | ||
'channel_prefix' => 'barPrefix', | ||
'user_class' => '\Symfony\Component\Security\Core\User\UserInterface', | ||
'user_methods' => [ | ||
'user_name' => 'getUsername', | ||
], | ||
'display' => [ | ||
'env' => true, | ||
'locale' => true, | ||
'application_name' => true, | ||
'url' => true, | ||
'route' => true, | ||
'user_agent' => true, | ||
'accept_encoding' => true, | ||
'client_ip' => true, | ||
'user' => true, | ||
'global_channel' => true, | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getValidConfigMin() | ||
{ | ||
return [ | ||
'application' => null, | ||
'handlers' => ['bar'], | ||
'config' => null, | ||
]; | ||
} | ||
} |
Oops, something went wrong.