[Issue-380] Throw exception if log_dir is defined but doesn't exists

This commit is contained in:
Andrés Montañez 2018-03-29 16:48:14 -03:00
parent 1c654e4eac
commit ceb07a306f
4 changed files with 27 additions and 0 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/vendor/
/build
composer.lock
.mage.yml

View file

@ -1,6 +1,10 @@
CHANGELOG for 3.X
=================
* 3.4.0 (2018-03-29)
* [Issue#380] Throw exception if log_dir is defined but directory doesn't exists
* 3.3.0 (2017-07-22)
* [PR#386] Allow to define timeout (default 120s) for symfony/assetic-dump task.
* [PR#392] Allow to define Host Port in Host configuration.

View file

@ -84,6 +84,9 @@ class MageApplication extends Application
$logger = new Logger('magephp');
$logger->pushHandler(new StreamHandler($logfile));
} elseif (array_key_exists('log_dir', $config['magephp']) && !is_dir($config['magephp']['log_dir'])) {
throw new RuntimeException(sprintf('The configured log_dir "%s" does not exists or is not a directory.', $config['magephp']['log_dir']));
}
$this->runtime->setConfiguration($config['magephp']);

View file

@ -11,6 +11,7 @@
namespace Mage\Tests\Command\BuiltIn;
use Mage\Command\BuiltIn\DeployCommand;
use Mage\Runtime\Exception\RuntimeException;
use Mage\Tests\MageApplicationMockup;
use Mage\Command\AbstractCommand;
use Symfony\Component\Console\Tester\CommandTester;
@ -36,6 +37,24 @@ class DeployCommandMiscTest extends TestCase
$this->assertEquals(0, $tester->getStatusCode());
}
public function testInvalidLog()
{
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/invalid-log.yml');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
try {
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
} catch (RuntimeException $exception) {
$this->assertEquals('The configured log_dir "/no-temp" does not exists or is not a directory.', $exception->getMessage());
} catch (\Exception $exception) {
$this->assertFalse(true, sprintf('Exception "%s" catched, message: "%s"', get_class($exception), $exception->getMessage()));
}
}
public function testDeploymentWithSudo()
{
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-sudo.yml');