Skip to content

Commit

Permalink
Merge pull request #11 from ezsystems/ezp-25599_symfony_system_info_c…
Browse files Browse the repository at this point in the history
…ollector

Fix EZP-25599: Symfony kernel system info collector
  • Loading branch information
glye committed Mar 31, 2016
2 parents f47d030 + df76319 commit b594d79
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ parameters:
support_tools.info_collectors.database.doctrine.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\DoctrineDatabaseSystemInfoCollector
support_tools.info_collectors.hardware.ezc.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\EzcHardwareSystemInfoCollector
support_tools.info_collectors.php.ezc.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\EzcPhpSystemInfoCollector
support_tools.info_collectors.symfony.kernel.config.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\ConfigurationSymfonyKernelSystemInfoCollector

services:
support_tools.info_collector.system_info.ezc:
Expand All @@ -31,3 +32,9 @@ services:
class: %support_tools.info_collectors.php.ezc.class%
arguments:
- @support_tools.info_collector.system_info.ezc

support_tools.info_collectors.symfony.kernel.config:
class: %support_tools.info_collectors.symfony.kernel.config.class%
arguments:
- @kernel
- %kernel.bundles%
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(),
]);
}
}
102 changes: 102 additions & 0 deletions SystemInfo/Value/SymfonyKernelSystemInfo.php
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;
}
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);
}
}

0 comments on commit b594d79

Please sign in to comment.