Exemple #1
0
 /**
  * Runa a command in and returns the commandTester object. This method can
  * run either a blend command or a sub-application command
  * @param string $projectFolder
  * @param string $commandName
  * @param string $params
  * @param string $app In case of null it will be set to blend. In case of
  * className as string, the application's class name will be used
  * @return CommandTester
  */
 public static function runCommand($projectFolder, $commandName, array $params = [], $app = null, $runOptions = [])
 {
     $loader = new ClassLoader();
     $curDir = getcwd();
     chdir($projectFolder);
     if ($app === null) {
         $app = new SetupApplication($projectFolder);
     } else {
         if (is_string($app)) {
             $classes = explode('\\', $app);
             $loader->addPsr4("{$classes[0]}\\", $projectFolder . '/src/');
             $loader->register(true);
             $c = new Container();
             $c->defineSingletonWithInterface('app', $app, ['scriptPath' => $projectFolder . '/bin']);
             $app = $c->get('app');
         }
     }
     $commandTester = new CommandTester($app->find($commandName));
     $commandTester->execute($params, $runOptions);
     chdir($curDir);
     $c = null;
     if ($loader) {
         $loader->unregister();
     }
     return $commandTester;
 }
 public function testCreateSingletonByFactory()
 {
     $c = new Container();
     $c->defineSingletonWithInterface(Counter::class, CounterFactory::class);
     $o1 = $c->get(Counter::class);
     $o1->increment();
     $o2 = $c->get(Counter::class);
     $this->assertEquals(2, $o2->increment());
 }