Skip to content

Commit

Permalink
Merge pull request #6250 from GawainLynch/hotfix/contenttype-exceptions
Browse files Browse the repository at this point in the history
Flash logging configuration validation failures
  • Loading branch information
bobdenotter committed Jan 13, 2017
2 parents 6397828 + 4225791 commit 3d48159
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 9 deletions.
17 changes: 15 additions & 2 deletions src/Configuration/Validation/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@

use Bolt\Config;
use Bolt\Controller\ExceptionControllerInterface;
use Bolt\Logger\FlashLoggerInterface;

/**
* Configuration parameters validation check.
*
* @author Gawain Lynch <gawain.lynch@gmail.com>
*/
class Configuration implements ValidationInterface, ConfigAwareInterface
class Configuration implements ValidationInterface, ConfigAwareInterface, FlashLoggerAwareInterface
{
/** @var Config */
private $config;
/** @var FlashLoggerInterface */
private $flashLogger;

/**
* Constructor.
Expand All @@ -35,7 +38,9 @@ public function check(ExceptionControllerInterface $exceptionController)
return null;
}

return $exceptionController->systemCheck(Validator::CHECK_CONFIG, $exceptions);
foreach ($exceptions as $exception) {
$this->flashLogger->error($exception);
}
}

/**
Expand All @@ -53,4 +58,12 @@ public function setConfig(Config $config)
{
$this->config = $config;
}

/**
* {@inheritdoc}
*/
public function setFlashLogger(FlashLoggerInterface $flashLogger)
{
$this->flashLogger = $flashLogger;
}
}
23 changes: 23 additions & 0 deletions src/Configuration/Validation/FlashLoggerAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Bolt\Configuration\Validation;

use Bolt\Config;
use Bolt\Logger\FlashLoggerInterface;

/**
* Interface for validation checks that require FlashLoggerInterface.
*
* @internal Do not use.
*
* @deprecated Deprecated since 3.2, to be removed in 4.0.
*
* @author Gawain Lynch <gawain.lynch@gmail.com>
*/
interface FlashLoggerAwareInterface
{
/**
* @param FlashLoggerInterface $flashLogger
*/
public function setFlashLogger(FlashLoggerInterface $flashLogger);
}
16 changes: 14 additions & 2 deletions src/Configuration/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Bolt\Configuration\ResourceManager;
use Bolt\Controller;
use Bolt\Exception\BootException;
use Bolt\Logger\FlashLoggerInterface;
use Symfony\Component\HttpFoundation\Response;

/**
Expand All @@ -32,6 +33,8 @@ class Validator extends LowlevelChecks implements ValidatorInterface
private $configManager;
/** @var ResourceManager */
private $resourceManager;
/** @var FlashLoggerInterface */
private $flashLogger;
/** @var array */
private $check = [
self::CHECK_CONFIG => Configuration::class,
Expand All @@ -48,13 +51,19 @@ class Validator extends LowlevelChecks implements ValidatorInterface
* @param Controller\Exception $exceptionController
* @param Config $config
* @param ResourceManager $resourceManager
* @param FlashLoggerInterface $flashLogger
*/
public function __construct(Controller\Exception $exceptionController, Config $config, ResourceManager $resourceManager)
{
public function __construct(
Controller\Exception $exceptionController,
Config $config,
ResourceManager $resourceManager,
FlashLoggerInterface $flashLogger
) {
parent::__construct($resourceManager);
$this->exceptionController = $exceptionController;
$this->configManager = $config;
$this->resourceManager = $resourceManager;
$this->flashLogger = $flashLogger;
}

/**
Expand Down Expand Up @@ -145,6 +154,9 @@ private function getValidator($className, $constructorArgs)
if ($validator instanceof ConfigAwareInterface) {
$validator->setConfig($this->configManager);
}
if ($validator instanceof FlashLoggerAwareInterface) {
$validator->setFlashLogger($this->flashLogger);
}

return $validator;
}
Expand Down
7 changes: 6 additions & 1 deletion src/Provider/ConfigServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ function ($app) {

$app['config.validator'] = $app->share(
function ($app) {
$validator = new ConfigValidator($app['controller.exception'], $app['config'], $app['resources']);
$validator = new ConfigValidator(
$app['controller.exception'],
$app['config'],
$app['resources'],
$app['logger.flash']
);

return $validator;
}
Expand Down
7 changes: 6 additions & 1 deletion tests/phpunit/unit/BoltUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ protected function getApp($boot = true)
$this->app = $this->makeApp();
$this->app->initialize();

$verifier = new Config\Validation\Validator($this->app['controller.exception'], $this->app['config'], $this->app['resources']);
$verifier = new Config\Validation\Validator(
$this->app['controller.exception'],
$this->app['config'],
$this->app['resources'],
$this->app['logger.flash']
);
$verifier->checks();

if ($boot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Bolt\Configuration\ResourceManager;
use Bolt\Configuration\Validation\Validator;
use Bolt\Controller;
use Bolt\Logger\FlashLogger;
use PHPUnit_Extension_FunctionMocker;

/**
Expand All @@ -25,6 +26,8 @@ abstract class AbstractValidationTest extends \PHPUnit_Framework_TestCase
protected $config;
/** @var ResourceManager */
protected $resourceManager;
/** @var FlashLogger */
protected $flashLogger;

/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $_filesystem;
Expand Down Expand Up @@ -61,11 +64,13 @@ public function setUp()
$this->extensionController = $this->prophesize(Controller\Exception::class);
$this->config = $this->prophesize(Config::class);
$this->resourceManager = $this->prophesize(ResourceManager::class);
$this->flashLogger = $this->prophesize(FlashLogger::class);

$this->validator = new Validator(
$this->extensionController->reveal(),
$this->config->reveal(),
$this->resourceManager->reveal()
$this->resourceManager->reveal(),
$this->flashLogger->reveal()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testConfigurationValid()
public function testConfigurationInvalid()
{
$this->config->getExceptions()->willReturn(['Koala detected … check for drop bear!']);
$this->extensionController->systemCheck(Validator::CHECK_CONFIG, ['Koala detected … check for drop bear!'])->shouldBeCalled();
$this->flashLogger->error('Koala detected … check for drop bear!')->shouldBeCalled();

$this->validator->check(Validator::CHECK_CONFIG);
}
Expand Down
7 changes: 6 additions & 1 deletion tests/phpunit/unit/Controller/ControllerUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ protected function makeApp()
$app = parent::makeApp();
$app->initialize();

$verifier = new Validator($app['controller.exception'], $app['config'], $app['resources']);
$verifier = new Validator(
$app['controller.exception'],
$app['config'],
$app['resources'],
$app['logger.flash']
);
$verifier->checks();

$app->boot();
Expand Down

0 comments on commit 3d48159

Please sign in to comment.