Skip to content

Commit

Permalink
Fixed missing-var bug, brushed up internal documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sara McCutcheon committed Sep 9, 2016
1 parent 6a4d1d6 commit 223eda4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 34 deletions.
22 changes: 15 additions & 7 deletions bin/terminus.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@
}
}

use League\Container\Container;
use Pantheon\Terminus\Config;
use Pantheon\Terminus\Runner;
use Pantheon\Terminus\Terminus;
use Robo\Robo;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;

$container = new \League\Container\Container();
$input = new \Symfony\Component\Console\Input\ArgvInput($_SERVER['argv']);
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
\Robo\Robo::configureContainer($container, $input, $output, $app);

// Initializing the Terminus application
$config = new Config();
$terminus = new Terminus('Terminus', $config->get('version'), $config);
$runner = new Runner(['application' => $terminus, 'config' => $config, 'container' => $container]);
$application = new Terminus('Terminus', $config->get('version'), $config);

// Configuring the dependency-injection container
$container = new Container();
$input = new ArgvInput($_SERVER['argv']);
$output = new ConsoleOutput();
Robo::configureContainer($container, $input, $output, $application);

// Running Terminus
$runner = new Runner($container);
$status_code = $runner->run($input, $output);
exit($status_code);
27 changes: 10 additions & 17 deletions src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
namespace Pantheon\Terminus;

use Consolidation\AnnotatedCommand\CommandFileDiscovery;
use Symfony\Component\Console\Application;
use League\Container\Container;
use Robo\Runner as RoboRunner;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Runner
{
/**
* @var Application
*/
private $application;
/**
* @var \Robo\Runner
*/
Expand All @@ -20,29 +18,24 @@ class Runner
/**
* Object constructor
*
* @param array $options Elements as follow:
* Application application An instance of a Symfony Console Application
* Config config A Terminus config instance
* Container container The Dependency Injection Container
* @param Container $container Container The dependency injection container
*/
public function __construct(array $options = ['application' => null, 'config' => null, 'container' => null])
public function __construct(Container $container = null)
{
$this->application = $options['application'];
$this->config = $options['config'];

$commands_directory = __DIR__ . '/Commands';
$top_namespace = 'Pantheon\Terminus\Commands';
$commands = $this->getCommands(['path' => $commands_directory, 'namespace' => $top_namespace,]);
$this->runner = new RoboRunner($commands, null, $options['container']);
$this->runner = new RoboRunner($commands, null, $container);
}

/**
* Runs the instantiated Terminus application
*
* @param string[] $arguments Argv from the command line
* @return integer The exiting status code of the application
* @param InputInterface $input An input object to run the application with
* @param OutputInterface $output An output object to run the application with
* @return integer $status_code The exiting status code of the application
*/
public function run($input, $output)
public function run(InputInterface $input, OutputInterface $output)
{
$this->runner->init($input, $output);
$status_code = $this->runner->run($input, $output);
Expand Down
2 changes: 1 addition & 1 deletion tests/active_features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public function iRestoreTheEnvironmentOfFromBackup($env, $site) {
public function iRun($command) {
$command = $this->_replacePlaceholders($command);
$regex = '/(?<!\.)terminus/';
$terminus_cmd = sprintf('bin/terminus', $this->cliroot);
$terminus_cmd = sprintf('bin/terminus.php', $this->cliroot);
if ($this->_cassette_name) {
$command = 'TERMINUS_VCR_CASSETTE=' . $this->_cassette_name . ' ' . $command;
}
Expand Down
37 changes: 28 additions & 9 deletions tests/new_unit_tests/RunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

namespace Pantheon\Terminus\UnitTests;

use League\Container\Container;
use Pantheon\Terminus\Config;
use Pantheon\Terminus\Runner;
use Pantheon\Terminus\Terminus;
use Robo\Robo;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Testing class for Pantheon\Terminus\Terminus
Expand All @@ -19,6 +24,14 @@ class RunnerTest extends \PHPUnit_Framework_TestCase
* @var Config
*/
private $config;
/**
* @var Container
*/
private $container;
/**
* @var OutputInterface
*/
private $output;
/**
* @var Runner
*/
Expand All @@ -30,9 +43,18 @@ class RunnerTest extends \PHPUnit_Framework_TestCase
public function __construct($name = null, array $data = [], $dataName = null)
{
parent::__construct($name, $data, $dataName);
// Initializing the Terminus application
$this->config = new Config();
$this->application = new Terminus('Terminus', $this->config->get('version'), $this->config);
$this->runner = new Runner(['application' => $this->application, 'config' => $this->config,]);

// Configuring the dependency-injection container
$this->container = new Container();
$input = new ArgvInput($_SERVER['argv']);
$this->output = new ConsoleOutput();
Robo::configureContainer($this->container, $input, $this->output, $this->application);

// Instantiating the Runner
$this->runner = new Runner($this->container);
}

/**
Expand All @@ -42,26 +64,23 @@ public function __construct($name = null, array $data = [], $dataName = null)
*/
public function testConstructor()
{
$runner = new Runner(['application' => $this->application, 'config' => $this->config,]);
$this->assertAttributeInstanceOf('Symfony\Component\Console\Application', 'application', $runner);
$this->assertAttributeInstanceOf('Pantheon\Terminus\Config', 'config', $runner);
$runner = new Runner($this->container);
$this->assertAttributeInstanceOf('Robo\Runner', 'runner', $runner);
}

/**
* Tests the run function
*
* @return void
* @expectedException \Error
*/
public function testRun()
{
$runner = new Runner();

$status_code = $runner->run([null, '-V', '--quiet']);
$input = new ArgvInput([null, '-V', '--quiet']);
$status_code = $this->runner->run($input, $this->output);
$this->assertEquals(0, $status_code);

$status_code = $runner->run([null, 'DNE', '--quiet']);
$input = new ArgvInput([null, 'DNE', '--quiet']);
$status_code = $this->runner->run($input, $this->output);
$this->assertEquals(1, $status_code);
}
}

0 comments on commit 223eda4

Please sign in to comment.