-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ezsystems/ezp-25599_symfony_system_info_c…
…ollector Fix EZP-25599: Symfony kernel system info collector
- Loading branch information
Showing
4 changed files
with
268 additions
and
0 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
68 changes: 68 additions & 0 deletions
68
SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.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,68 @@ | ||
<?php | ||
|
||
/** | ||
* File containing the ConfigurationSymfonyKernelSystemInfoCollector class. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\EzSupportToolsBundle\SystemInfo\Collector; | ||
|
||
use EzSystems\EzSupportToolsBundle\SystemInfo\Value; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
/** | ||
* Collects information about the Symfony kernel we are using. | ||
*/ | ||
class ConfigurationSymfonyKernelSystemInfoCollector implements SystemInfoCollector | ||
{ | ||
/** | ||
* Symfony kernel. | ||
* | ||
* @var \Symfony\Component\HttpKernel\Kernel | ||
*/ | ||
private $kernel; | ||
|
||
/** | ||
* Installed bundles. | ||
* | ||
* A hash containing the active bundles, where the key is the bundle name, and the value is the corresponding namespace. | ||
* | ||
* Example: | ||
* array ( | ||
* 'AppBundle' => 'AppBundle\\AppBundle', | ||
* 'AsseticBundle' => 'Symfony\\Bundle\\AsseticBundle\\AsseticBundle', | ||
* ) | ||
* | ||
* @var array | ||
*/ | ||
private $bundles; | ||
|
||
public function __construct(Kernel $kernel, array $bundles) | ||
{ | ||
$this->kernel = $kernel; | ||
$this->bundles = $bundles; | ||
} | ||
|
||
/** | ||
* Collects information about the Symfony kernel. | ||
* | ||
* @return Value\SymfonyKernelSystemInfo | ||
*/ | ||
public function collect() | ||
{ | ||
ksort($this->bundles, SORT_FLAG_CASE | SORT_STRING); | ||
|
||
return new Value\SymfonyKernelSystemInfo([ | ||
'environment' => $this->kernel->getEnvironment(), | ||
'debugMode' => $this->kernel->isDebug(), | ||
'version' => Kernel::VERSION, | ||
'bundles' => $this->bundles, | ||
'rootDir' => $this->kernel->getRootDir(), | ||
'name' => $this->kernel->getName(), | ||
'cacheDir' => $this->kernel->getCacheDir(), | ||
'logDir' => $this->kernel->getLogDir(), | ||
'charset' => $this->kernel->getCharset(), | ||
]); | ||
} | ||
} |
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,102 @@ | ||
<?php | ||
|
||
/** | ||
* File containing the SymfonyKernelSystemInfo class. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\EzSupportToolsBundle\SystemInfo\Value; | ||
|
||
use eZ\Publish\API\Repository\Values\ValueObject; | ||
|
||
/** | ||
* Value for information about the Symfony kernel we are using. | ||
*/ | ||
class SymfonyKernelSystemInfo extends ValueObject implements SystemInfo | ||
{ | ||
/** | ||
* Symfony environment. | ||
* | ||
* "dev" or "prod". | ||
* | ||
* @var string | ||
*/ | ||
public $environment; | ||
|
||
/** | ||
* True if Symfony is in debug mode. | ||
* | ||
* @var bool | ||
*/ | ||
public $debugMode; | ||
|
||
/** | ||
* Symfony version. | ||
* | ||
* Example: 2.7.10 | ||
* | ||
* @var string | ||
*/ | ||
public $version; | ||
|
||
/** | ||
* Installed bundles. | ||
* | ||
* A hash containing the active bundles, where the key is the bundle name, and the value is the corresponding namespace. | ||
* | ||
* Example: | ||
* array ( | ||
* 'AppBundle' => 'AppBundle\\AppBundle', | ||
* 'AsseticBundle' => 'Symfony\\Bundle\\AsseticBundle\\AsseticBundle', | ||
* ) | ||
* | ||
* @var array | ||
*/ | ||
public $bundles; | ||
|
||
/** | ||
* Root directory. | ||
* | ||
* Example: /srv/www/ezpublish-platform/app | ||
* | ||
* @var string | ||
*/ | ||
public $rootDir; | ||
|
||
/** | ||
* Name. | ||
* | ||
* Example: app | ||
* | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* Cache directory. | ||
* | ||
* Example: /srv/www/ezpublish-platform/app/cache/prod | ||
* | ||
* @var string | ||
*/ | ||
public $cacheDir; | ||
|
||
/** | ||
* Log file directory. | ||
* | ||
* Example: /srv/www/ezpublish-platform/app/logs | ||
* | ||
* @var string | ||
*/ | ||
public $logDir; | ||
|
||
/** | ||
* Character set. | ||
* | ||
* Example: UTF-8 | ||
* | ||
* @var string | ||
*/ | ||
public $charset; | ||
} |
91 changes: 91 additions & 0 deletions
91
Tests/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollectorTest.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,91 @@ | ||
<?php | ||
|
||
/** | ||
* File containing the ConfigurationSymfonyKernelSystemInfoCollectorTest class. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\EzSupportToolsBundle\Tests\SystemInfo\Collector; | ||
|
||
use EzSystems\EzSupportToolsBundle\SystemInfo\Collector\ConfigurationSymfonyKernelSystemInfoCollector; | ||
use EzSystems\EzSupportToolsBundle\SystemInfo\Value\SymfonyKernelSystemInfo; | ||
use PHPUnit_Framework_TestCase; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
class ConfigurationSymfonyKernelSystemInfoCollectorTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @covers \EzSystems\EzSupportToolsBundle\SystemInfo\Collector\ConfigurationSymfonyKernelSystemInfoCollector::collect() | ||
*/ | ||
public function testCollect() | ||
{ | ||
$expected = new SymfonyKernelSystemInfo([ | ||
'environment' => 'dev', | ||
'debugMode' => true, | ||
'version' => Kernel::VERSION, | ||
'bundles' => [ | ||
'AppBundle' => 'AppBundle\\AppBundle', | ||
'DoctrineBundle' => 'Doctrine\\Bundle\\DoctrineBundle\\DoctrineBundle', | ||
'eZPlatformUIBundle' => 'EzSystems\\PlatformUIBundle\\EzSystemsPlatformUIBundle', | ||
'EzPublishCoreBundle' => 'eZ\\Bundle\\EzPublishCoreBundle\\EzPublishCoreBundle', | ||
'EzSystemsEzSupportToolsBundle' => 'EzSystems\\EzSupportToolsBundle\\EzSystemsEzSupportToolsBundle', | ||
], | ||
'rootDir' => '/srv/www/ezpublish-platform/app', | ||
'name' => 'app', | ||
'cacheDir' => '/srv/www/ezpublish-platform/app/cache/prod', | ||
'logDir' => '/srv/www/ezpublish-platform/app/logs', | ||
'charset' => 'UTF-8', | ||
]); | ||
|
||
$kernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\Kernel') | ||
->setConstructorArgs([$expected->environment, $expected->debugMode]) | ||
->getMock(); | ||
|
||
$kernelMock | ||
->expects($this->once()) | ||
->method('getEnvironment') | ||
->will($this->returnValue($expected->environment)); | ||
|
||
$kernelMock | ||
->expects($this->once()) | ||
->method('isDebug') | ||
->will($this->returnValue($expected->debugMode)); | ||
|
||
$kernelMock | ||
->expects($this->once()) | ||
->method('getRootDir') | ||
->will($this->returnValue($expected->rootDir)); | ||
|
||
$kernelMock | ||
->expects($this->once()) | ||
->method('getName') | ||
->will($this->returnValue($expected->name)); | ||
|
||
$kernelMock | ||
->expects($this->once()) | ||
->method('getCacheDir') | ||
->will($this->returnValue($expected->cacheDir)); | ||
|
||
$kernelMock | ||
->expects($this->once()) | ||
->method('getLogDir') | ||
->will($this->returnValue($expected->logDir)); | ||
|
||
$kernelMock | ||
->expects($this->once()) | ||
->method('getCharset') | ||
->will($this->returnValue($expected->charset)); | ||
|
||
$symfonyCollector = new ConfigurationSymfonyKernelSystemInfoCollector( | ||
$kernelMock, | ||
$expected->bundles | ||
); | ||
|
||
$value = $symfonyCollector->collect(); | ||
|
||
self::assertInstanceOf('EzSystems\EzSupportToolsBundle\SystemInfo\Value\SymfonyKernelSystemInfo', $value); | ||
|
||
self::assertEquals($expected, $value); | ||
} | ||
} |