/** * {@inheritdoc} */ public function run() { ob_start(); $input = $this->container->get('input'); $output = $this->container->get('output'); // Create reactor and register custom options $reactor = new Reactor($input, $output, $this->container); $reactor->setLogo($this->loadLogo()); $reactor->registerCustomOption('env', 'Overrides the Mako environment', function (Config $config, $option) { putenv('MAKO_ENV=' . $option); $config->setEnvironment($option); }); $reactor->registerCustomOption('database', 'Overrides the default database connection', function (Config $config, $option) { $config->set('database.default', $option); }); $reactor->registerCustomOption('mute', 'Mutes all output', function (Output $output) { $output->mute(); }); // Register reactor commands foreach ($this->getCommands() as $command => $class) { $reactor->registerCommand($command, $class); } // Run the reactor $reactor->run(); }
/** * */ public function testNoInput() { $input = m::mock('mako\\cli\\input\\Input'); $input->shouldReceive('getArgument')->once()->with(1)->andReturn(null); $input->shouldReceive('getArgument')->once()->with('option')->andReturn(null); // $output = m::mock('mako\\cli\\output\\Output'); $output->shouldReceive('getFormatter')->andReturn(null); $output->shouldReceive('write')->times(8)->with(PHP_EOL); $output->shouldReceive('writeLn')->once()->with('logo'); $output->shouldReceive('writeLn')->once()->with('<yellow>Usage:</yellow>'); $output->shouldReceive('writeLn')->once()->with('php reactor [command] [arguments] [options]'); $output->shouldReceive('writeLn')->once()->with('<yellow>Global options:</yellow>'); $optionsTable = <<<EOF ------------------------------------------------------ | <green>Option</green> | <green>Description</green> | ------------------------------------------------------ | --option | option description | ------------------------------------------------------ EOF; $output->shouldReceive('write')->once()->with($optionsTable, 1); $output->shouldReceive('writeLn')->once()->with('<yellow>Available commands:</yellow>'); $commandsTable = <<<EOF ------------------------------------------------------- | <green>Command</green> | <green>Description</green> | ------------------------------------------------------- | foo | foo description | ------------------------------------------------------- EOF; $output->shouldReceive('write')->once()->with($commandsTable, 1); // $container = m::mock('mako\\syringe\\Container'); $command = m::mock('mako\\reactor\\Command'); $command->shouldReceive('getCommandDescription')->once()->andReturn('foo description'); $container->shouldReceive('get')->once()->andReturn($command); // $dispatcher = m::mock('mako\\reactor\\Dispatcher'); // $reactor = new Reactor($input, $output, $container, $dispatcher); $reactor->setLogo('logo'); $reactor->registerCustomOption('option', 'option description', function () { }); $reactor->registerCommand('foo', 'mako\\tests\\unit\\reactor\\Foo'); $reactor->run(); }