[Nostromo] Improve tests. Mess Detector recommendations.

This commit is contained in:
Andrés Montañez 2017-01-07 19:08:25 -03:00
parent 193265e424
commit 93af5ee8cc
3 changed files with 29 additions and 4 deletions

View file

@ -20,7 +20,8 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Application;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Exception\ParseException;
use ReflectionClass;
use Mage\Runtime\Exception\RuntimeException;
@ -62,7 +63,13 @@ class MageApplication extends Application
throw new RuntimeException(sprintf('The file "%s" does not exists or is not readable.', $file));
}
$config = Yaml::parse(file_get_contents($file));
try {
$parser = new Parser();
$config = $parser->parse(file_get_contents($file));
} catch (ParseException $exception) {
throw new RuntimeException(sprintf('Error parsing the file "%s".', $file));
}
if (array_key_exists('magephp', $config)) {
$config = $config['magephp'];
@ -80,9 +87,10 @@ class MageApplication extends Application
$this->runtime->setLogger($logger);
$this->loadBuiltInCommands();
} else {
throw new RuntimeException(sprintf('The file "%s" does not have a valid Magallanes configuration.', $file));
return true;
}
throw new RuntimeException(sprintf('The file "%s" does not have a valid Magallanes configuration.', $file));
}
/**

View file

@ -36,6 +36,17 @@ class MageApplicationTest extends TestCase
}
}
public function testParserError()
{
try {
$application = new MageApplication();
$application->configure(__DIR__ . '/Resources/invalid-yaml.yml');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('Error parsing the file "%s".', __DIR__ . '/Resources/invalid-yaml.yml'), $exception->getMessage());
}
}
public function testInvalidFile()
{
try {

View file

@ -0,0 +1,6 @@
magephp:
environments:
hosts:
- host1
- host2
- host3