This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zend-log for the canonical source repository | ||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Log; | ||
|
||
use Interop\Container\ContainerInterface; | ||
|
||
/** | ||
* PSR Logger abstract service factory. | ||
* | ||
* Allow to configure multiple loggers for application. | ||
*/ | ||
class PsrLoggerAbstractAdapterFactory extends LoggerAbstractServiceFactory | ||
{ | ||
/** | ||
* Configuration key holding logger configuration | ||
* | ||
* @var string | ||
*/ | ||
protected $configKey = 'psr_log'; | ||
|
||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) | ||
{ | ||
$logger = parent::__invoke($container, $requestedName, $options); | ||
|
||
return new PsrLoggerAdapter($logger); | ||
} | ||
} |
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,90 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zend-log for the canonical source repository | ||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Log; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Zend\Log\LoggerAbstractServiceFactory; | ||
use Zend\Log\PsrLoggerAbstractAdapterFactory; | ||
use Zend\ServiceManager\Config; | ||
use Zend\ServiceManager\Exception\ServiceNotFoundException; | ||
use Zend\ServiceManager\Factory\AbstractFactoryInterface; | ||
use Zend\ServiceManager\ServiceManager; | ||
|
||
class PsrLoggerAbstractAdapterFactoryTest extends TestCase | ||
{ | ||
/** | ||
* @var \Zend\ServiceManager\ServiceLocatorInterface | ||
*/ | ||
protected $serviceManager; | ||
|
||
/** | ||
* Set up LoggerAbstractServiceFactory and loggers configuration. | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->serviceManager = new ServiceManager(); | ||
$config = new Config([ | ||
'abstract_factories' => [PsrLoggerAbstractAdapterFactory::class], | ||
'services' => [ | ||
'config' => [ | ||
'psr_log' => [ | ||
'Application\Frontend' => [], | ||
'Application\Backend' => [], | ||
], | ||
], | ||
], | ||
]); | ||
$config->configureServiceManager($this->serviceManager); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function providerValidLoggerService() | ||
{ | ||
return [ | ||
['Application\Frontend'], | ||
['Application\Backend'], | ||
]; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function providerInvalidLoggerService() | ||
{ | ||
return [ | ||
['Logger\Application\Unknown'], | ||
['Logger\Application\Frontend'], | ||
['Application\Backend\Logger'], | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $service | ||
* @dataProvider providerValidLoggerService | ||
*/ | ||
public function testValidLoggerService($service) | ||
{ | ||
$actual = $this->serviceManager->get($service); | ||
$this->assertInstanceOf('Zend\Log\PsrLoggerAdapter', $actual); | ||
} | ||
|
||
/** | ||
* @dataProvider providerInvalidLoggerService | ||
* | ||
* @param string $service | ||
*/ | ||
public function testInvalidLoggerService($service) | ||
{ | ||
$this->expectException(ServiceNotFoundException::class); | ||
$this->serviceManager->get($service); | ||
} | ||
} |