Skip to content

Commit

Permalink
Fix tests for CLI App input injection
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge committed Nov 26, 2017
1 parent c01c7aa commit c3021bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions libraries/src/Application/CliApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use Joomla\CMS\Application\CLI\CliInput;
use Joomla\CMS\Application\CLI\CliOutput;
use Joomla\CMS\Application\CLI\Output\Stdout;
use Joomla\CMS\Input\Cli as CMSCli;
use Joomla\Input\Cli;
use Joomla\Input\Input;
use Joomla\DI\Container;
use Joomla\DI\ContainerAwareTrait;
use Joomla\Event\DispatcherAwareInterface;
Expand Down Expand Up @@ -60,7 +62,7 @@ abstract class CliApplication extends AbstractApplication implements DispatcherA
/**
* Class constructor.
*
* @param Cli $input An optional argument to provide dependency injection for the application's
* @param Input $input An optional argument to provide dependency injection for the application's
* input object. If the argument is a JInputCli object that object will become
* the application's input object, otherwise a default input object is created.
* @param Registry $config An optional argument to provide dependency injection for the application's
Expand All @@ -76,7 +78,7 @@ abstract class CliApplication extends AbstractApplication implements DispatcherA
*
* @since 11.1
*/
public function __construct(Cli $input = null, Registry $config = null, CliOutput $output = null, CliInput $cliInput = null,
public function __construct(Input $input = null, Registry $config = null, CliOutput $output = null, CliInput $cliInput = null,
DispatcherInterface $dispatcher = null, Container $container = null)
{
// Close the application if we are not executed from the command line.
Expand All @@ -89,6 +91,18 @@ public function __construct(Cli $input = null, Registry $config = null, CliOutpu
$this->setContainer($container);

$this->output = $output ?: new Stdout;

if ($cliInput && !($cliInput instanceof CMSCli || $cliInput instanceof Cli))
{
throw new \InvalidArgumentException(
sprintf(
'The Input object must be a %s or %s object',
CMSCli::class,
Cli::class
)
);
}

$this->cliInput = $cliInput ?: new CliInput;

if ($dispatcher)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function tearDown()
*/
public function test__construct()
{
$this->assertAttributeInstanceOf('JInput', 'input', $this->class);
$this->assertAttributeInstanceOf('\\Joomla\\Input\\Input', 'input', $this->class);
$this->assertAttributeInstanceOf('\\Joomla\\Registry\\Registry', 'config', $this->class);
$this->assertAttributeEmpty('dispatcher', $this->class);

Expand Down

0 comments on commit c3021bd

Please sign in to comment.