Skip to content

Commit

Permalink
Merge pull request #958 from wheniwork/support_env-adapter_input
Browse files Browse the repository at this point in the history
Allow console input to be used within adapters
  • Loading branch information
robmorgan committed Sep 19, 2016
2 parents d701ee0 + f7a607f commit 1d644d6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Phinx/Migration/Manager.php
Expand Up @@ -489,6 +489,7 @@ public function getEnvironment($name)
// create an environment instance and cache it
$environment = new Environment($name, $this->getConfig()->getEnvironment($name));
$this->environments[$name] = $environment;
$environment->setInput($this->getInput());
$environment->setOutput($this->getOutput());

return $environment;
Expand Down
32 changes: 32 additions & 0 deletions src/Phinx/Migration/Manager/Environment.php
Expand Up @@ -32,6 +32,7 @@
use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Migration\MigrationInterface;
use Phinx\Seed\SeedInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Environment
Expand All @@ -46,6 +47,11 @@ class Environment
*/
protected $options;

/**
* @var InputInterface
*/
protected $input;

/**
* @var OutputInterface
*/
Expand Down Expand Up @@ -196,6 +202,28 @@ public function getOptions()
return $this->options;
}

/**
* Sets the console input.
*
* @param InputInterface $input
* @return Environment
*/
public function setInput(InputInterface $input)
{
$this->input = $input;
return $this;
}

/**
* Gets the console input.
*
* @return InputInterface
*/
public function getInput()
{
return $this->input;
}

/**
* Sets the console output.
*
Expand Down Expand Up @@ -312,6 +340,10 @@ public function getAdapter()
->getWrapper($this->options['wrapper'], $adapter);
}

if ($this->getInput()) {
$adapter->setInput($this->getInput());
}

if ($this->getOutput()) {
$adapter->setOutput($this->getOutput());
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Phinx/Migration/Manager/EnvironmentTest.php
Expand Up @@ -211,4 +211,11 @@ public function testExecutingAChangeMigrationDown()

$this->environment->executeMigration($migration, MigrationInterface::DOWN);
}

public function testGettingInputObject()
{
$this->environment->setInput($this->getMock('\Symfony\Component\Console\Input\InputInterface'));
$inputObject = $this->environment->getInput();
$this->assertInstanceOf('\Symfony\Component\Console\Input\InputInterface', $inputObject);
}
}

0 comments on commit 1d644d6

Please sign in to comment.