diff --git a/.gitignore b/.gitignore index 263233c..11aaa0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor/ /build composer.lock +.mage.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index d40ac36..c81798a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/MageApplication.php b/src/MageApplication.php index cb20d30..77fe4e2 100644 --- a/src/MageApplication.php +++ b/src/MageApplication.php @@ -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']); diff --git a/tests/Command/BuiltIn/DeployCommandMiscTest.php b/tests/Command/BuiltIn/DeployCommandMiscTest.php index 9ffa09d..8df52ef 100644 --- a/tests/Command/BuiltIn/DeployCommandMiscTest.php +++ b/tests/Command/BuiltIn/DeployCommandMiscTest.php @@ -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');