Ejemplo n.º 1
0
 /**
  * {@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();
 }
Ejemplo n.º 2
0
 /**
  *
  */
 public function testCommandWithCustomOption()
 {
     $closure = function () {
     };
     //
     $input = m::mock('mako\\cli\\input\\Input');
     $input->shouldReceive('getArgument')->once()->with(1)->andReturn('foo');
     $input->shouldReceive('getArgument')->once()->with('option')->andReturn(true);
     $input->shouldReceive('getArguments')->once()->andReturn(['reactor', 'foo']);
     //
     $output = m::mock('mako\\cli\\output\\Output');
     $output->shouldReceive('write')->times(2);
     //
     $container = m::mock('mako\\syringe\\Container');
     $container->shouldReceive('call')->once()->with($closure, ['option' => true]);
     //
     $dispatcher = m::mock('mako\\reactor\\Dispatcher');
     $dispatcher->shouldReceive('dispatch')->once()->with('mako\\tests\\unit\\reactor\\Foo', ['reactor', 'foo']);
     //
     $reactor = new Reactor($input, $output, $container, $dispatcher);
     $reactor->registerCustomOption('option', 'option description', $closure);
     $reactor->registerCommand('foo', 'mako\\tests\\unit\\reactor\\Foo');
     $reactor->run();
 }