Example #1
0
/**
 * Creates a console application with all of the commands attached.
 * @return Application
 */
function createApplication()
{
    //    $rpmCommand = new Command('rpmdir', ['Bastion\RPMProcess', 'packageSingleDirectory']);
    //    $rpmCommand->addArgument('directory', InputArgument::REQUIRED, "The directory containing the composer'd project to build into an RPM.");
    ////$uploadCommand->addOption('dir', null, InputArgument::OPTIONAL, 'Which directory to upload from', './');
    //    $rpmCommand->setDescription("Build an RPM from an directory that contains all the files of a project. Allows for faster testing than having to re-tag, and download zip files repeatedly.");
    $statsCommand = new Command('statsRunner', 'Stats\\SimpleStats::run');
    $statsCommand->setDescription("Run the stats collector and send the results to Librato.");
    $taskCommand = new Command('imageRunner', 'ImagickDemo\\Queue\\ImagickTaskRunner::run');
    $taskCommand->setDescription("Pull image request jobs off the queue and generated the images.");
    $clearCacheCommand = new Command('clearCache', 'ImagickDemo\\Config\\APCCacheEnvReader::clearCache');
    $clearCacheCommand->setDescription("Clear the apc cache.");
    $envWriteCommand = new Command('genEnvSettings', 'ImagickDemo\\Config\\EnvConfWriter::writeEnvFile');
    $envWriteCommand->setDescription("Write an env setting bash script.");
    $envWriteCommand->addArgument('env', InputArgument::REQUIRED, 'Which environment the settings should be generated for.');
    $envWriteCommand->addArgument('filename', InputArgument::REQUIRED, 'The file name that the env settings should be written to.');
    $clearRedisCommand = new Command('clearRedis', 'ImagickDemo\\Queue\\ImagickTaskQueue::clearStatusQueue');
    $clearRedisCommand->setDescription("Clear the imagick task queue.");
    $console = new Application("ImagickDemos", "1.0.0");
    $console->add($statsCommand);
    $console->add($taskCommand);
    $console->add($clearCacheCommand);
    $console->add($clearRedisCommand);
    $console->add($envWriteCommand);
    return $console;
}
Example #2
0
/**
 * Creates a console application with all of the commands attached.
 * @return Application
 */
function createApplication()
{
    $statsCommand = new Command('statsRunner', 'Stats\\SimpleStats::run');
    $statsCommand->setDescription("Run the stats collector and send the results to Librato.");
    $taskCommand = new Command('imageRunner', 'ImagickDemo\\Queue\\ImagickTaskRunner::run');
    $taskCommand->setDescription("Pull image request jobs off the queue and generated the images.");
    $clearCacheCommand = new Command('clearCache', 'ImagickDemo\\Config\\APCCacheEnvReader::clearCache');
    $clearCacheCommand->setDescription("Clear the apc cache.");
    $envWriteCommand = new Command('genEnvSettings', 'ImagickDemo\\Config\\EnvConfWriter::writeEnvFile');
    $envWriteCommand->setDescription("Write an env setting bash script.");
    $envWriteCommand->addArgument('env', InputArgument::REQUIRED, 'Which environment the settings should be generated for.');
    $envWriteCommand->addArgument('filename', InputArgument::REQUIRED, 'The file name that the env settings should be written to.');
    $clearRedisCommand = new Command('clearRedis', 'ImagickDemo\\Queue\\ImagickTaskQueue::clearStatusQueue');
    $clearRedisCommand->setDescription("Clear the imagick task queue.");
    $console = new Application("ImagickDemos", "1.0.0");
    $console->add($statsCommand);
    $console->add($taskCommand);
    $console->add($clearCacheCommand);
    $console->add($clearRedisCommand);
    $console->add($envWriteCommand);
    return $console;
}
Example #3
0
 public function testCommandFromApplication()
 {
     $application = new Application();
     $application->setAutoExit(false);
     $callable = function ($input, $output) {
         $output->writeln('foo');
     };
     $command = new Command('foo', $callable);
     $application->add($command);
     $tester = new CommandTester($application->find('foo'));
     $result = $tester->execute(array());
     $this->assertInstanceOf('Danack\\Console\\Command\\ParsedCommand', $result);
 }
Example #4
0
    public function testExecuteListsCommandsWithNamespaceArgument()
    {
        require_once realpath(__DIR__ . '/../Fixtures/FooCommand.php');
        $application = new Application();
        $application->add(new \FooCommand());
        $commandTester = new CommandTester($command = $application->get('list'));
        $parsedCommand = $commandTester->execute(array('command' => $command->getName(), 'namespace' => 'foo', '--raw' => true));
        /** @var $parsedCommand ParsedCommand */
        $injector = new \Auryn\Provider();
        $injector->execute($parsedCommand->getCallable());
        $output = <<<EOF
foo:bar   The foo:bar command

EOF;
        $this->assertEquals($output, $commandTester->getDisplay(true));
    }
Example #5
0
function uploadFile($filename, $dir)
{
    echo "Need to upload the file {$filename} in the directory {$dir}" . PHP_EOL;
}
//Auryn needs scalars prefixed with a colon and we only
//have scalars here.
function lowrey($params)
{
    $newParams = [];
    foreach ($params as $key => $value) {
        $newParams[':' . $key] = $value;
    }
    return $newParams;
}
$console = new Application();
$console->add(new AboutCommand());
$uploadCommand = new Command('upload', 'uploadFile');
$uploadCommand->addArgument('filename', InputArgument::REQUIRED, 'The name of the file to upload');
$uploadCommand->addOption('dir', null, InputArgument::OPTIONAL, 'Which directory to upload from', './');
$console->add($uploadCommand);
$helloWorldCallable = function ($name) {
    echo "Hello world, and particularly {$name}" . PHP_EOL;
};
$callableCommand = new Command('greet', $helloWorldCallable);
$callableCommand->addArgument('name', InputArgument::REQUIRED, 'The name of the person to say hello to.');
$callableCommand->setDescription("Says hello to the world and one named person");
$console->add($callableCommand);
try {
    $parsedCommand = $console->parseCommandLine();
} catch (\Exception $e) {
    $output = new BufferedOutput();
Example #6
0
 public function testSetRunCustomDefaultCommand()
 {
     $command = new \FooCommand();
     $application = new Application();
     $application->setAutoExit(false);
     $application->add($command);
     $application->setDefaultCommand($command->getName());
     $tester = new ApplicationTester($application);
     $parsedCommand = $tester->run(array());
     $provider = new Provider();
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertEquals('interact called' . PHP_EOL . 'called' . PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command');
     $application = new CustomDefaultCommandApplication();
     $application->setAutoExit(false);
     $tester = new ApplicationTester($application);
     $parsedCommand = $tester->run(array());
     $provider->execute($parsedCommand->getCallable(), []);
     $this->assertEquals('interact called' . PHP_EOL . 'called' . PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command');
 }