parseArgs() public method

Parses the raw console arguments and returns the parsed arguments.
public parseArgs ( Webmozart\Console\Api\Args\RawArgs $args, boolean $lenient = null ) : Args
$args Webmozart\Console\Api\Args\RawArgs The raw console arguments.
$lenient boolean Whether the parser should ignore parse errors. If `true`, the parser will not throw any exceptions when parse errors occur.
return Webmozart\Console\Api\Args\Args The parsed console arguments.
コード例 #1
0
 /**
  * @expectedException \Puli\Manager\Api\Server\NoSuchServerException
  */
 public function testDeleteServerFailsIfNotFound()
 {
     $this->serverManager->expects($this->once())->method('hasServer')->with('localhost')->willReturn(false);
     $this->serverManager->expects($this->never())->method('removeServer');
     $args = self::$deleteCommand->parseArgs(new StringArgs('localhost'));
     $this->handler->handleDelete($args);
 }
コード例 #2
0
ファイル: MapCommandHandlerTest.php プロジェクト: rejinka/cli
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage The path "/path1" is not mapped in the package "vendor/root".
  */
 public function testDeleteMappingFailsIfNotFound()
 {
     $args = self::$deleteCommand->parseArgs(new StringArgs('/path1'));
     $this->repoManager->expects($this->once())->method('hasRootPathMapping')->with('/path1')->willReturn(false);
     $this->repoManager->expects($this->never())->method('removeRootPathMapping')->with('/path1');
     $this->assertSame(0, $this->handler->handleDelete($args));
 }
コード例 #3
0
 /**
  * @expectedException \RuntimeException
  */
 public function testDeletePluginFailsIfNotInstalled()
 {
     $args = self::$deleteCommand->parseArgs(new StringArgs('My\\Plugin\\Class'));
     $this->manager->expects($this->once())->method('hasPluginClass')->with('My\\Plugin\\Class')->willReturn(false);
     $this->manager->expects($this->never())->method('removePluginClass');
     $this->handler->handleDelete($args);
 }
コード例 #4
0
 /**
  * @expectedException \RuntimeException
  */
 public function testDeleteInstallerFailsIfNotFound()
 {
     $args = self::$deleteCommand->parseArgs(new StringArgs('symlink'));
     $this->installerManager->expects($this->once())->method('hasInstallerDescriptor')->with('symlink')->willReturn(false);
     $this->installerManager->expects($this->never())->method('removeRootInstallerDescriptor');
     $this->handler->handleDelete($args);
 }
コード例 #5
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage No search criteria specified
  */
 public function testFailIfNoCriteria()
 {
     $args = self::$findCommand->parseArgs(new StringArgs(''));
     $this->repo->expects($this->never())->method('find');
     $this->discovery->expects($this->never())->method('findByType');
     $this->handler->handle($args, $this->io);
 }
コード例 #6
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage The type "my/type" does not exist in the package "vendor/root".
  */
 public function testDeleteTypeFailsIfNotFound()
 {
     $args = self::$deleteCommand->parseArgs(new StringArgs('my/type'));
     $this->discoveryManager->expects($this->once())->method('hasRootBindingType')->with('my/type')->willReturn(false);
     $this->discoveryManager->expects($this->never())->method('removeRootBindingType');
     $this->assertSame(0, $this->handler->handleRemove($args));
 }
コード例 #7
0
 public function testResetKey()
 {
     $args = self::$resetCommand->parseArgs(new StringArgs('the-key'));
     $this->manager->expects($this->once())->method('removeConfigKey')->with('the-key');
     $statusCode = $this->handler->handleReset($args);
     $this->assertSame(0, $statusCode);
     $this->assertEmpty($this->io->fetchOutput());
     $this->assertEmpty($this->io->fetchErrors());
 }
コード例 #8
0
ファイル: ResolveResult.php プロジェクト: webmozart/console
 private function parse()
 {
     try {
         $this->parsedArgs = $this->command->parseArgs($this->rawArgs);
     } catch (CannotParseArgsException $e) {
         $this->parseError = $e;
     }
     $this->parsed = true;
 }
コード例 #9
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Cannot disable bindings in the package "vendor/root".
  */
 public function testDisableBindingFailsIfRoot()
 {
     $args = self::$disableCommand->parseArgs(new StringArgs('ab12'));
     $descriptor = new BindingDescriptor('/path', 'my/type', array(), 'glob');
     $descriptor->load($this->packages->getRootPackage());
     $this->discoveryManager->expects($this->once())->method('findBindings')->with($this->uuid('ab12'))->willReturn(array($descriptor));
     $this->discoveryManager->expects($this->never())->method('disableBinding');
     $this->handler->handleDisable($args, $this->io);
 }
コード例 #10
0
 public function testGetDefaultTarget()
 {
     $target = new InstallTarget('local', 'symlink', 'public_html');
     $this->targetManager->expects($this->once())->method('getDefaultTarget')->willReturn($target);
     $args = self::$getDefaultCommand->parseArgs(new StringArgs(''));
     $this->assertSame(0, $this->handler->handleGetDefault($args, $this->io));
     $this->assertSame("local\n", $this->io->fetchOutput());
     $this->assertEmpty($this->io->fetchErrors());
 }
コード例 #11
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Invalid build target "foobar". Expected one of: "all", "factory", "repository", "discovery"
  */
 public function testBuildFailsIfInvalidTarget()
 {
     $args = self::$buildCommand->parseArgs(new StringArgs('foobar'));
     $this->factoryManager->expects($this->never())->method('autoGenerateFactoryClass');
     $this->repoManager->expects($this->never())->method('clearRepository');
     $this->repoManager->expects($this->never())->method('buildRepository');
     $this->discoveryManager->expects($this->never())->method('clearDiscovery');
     $this->discoveryManager->expects($this->never())->method('buildDiscovery');
     $this->handler->handle($args);
 }
コード例 #12
0
    public function testCleanPackages()
    {
        $args = self::$cleanCommand->parseArgs(new StringArgs(''));
        // The not-found package
        $this->packageManager->expects($this->once())->method('removePackage')->with('vendor/package3');
        $expected = <<<EOF
Removing vendor/package3

EOF;
        $this->assertSame(0, $this->handler->handleClean($args, $this->io));
        $this->assertSame($expected, $this->io->fetchOutput());
        $this->assertEmpty($this->io->fetchErrors());
    }
コード例 #13
0
    public function testInstallNothing()
    {
        $this->assetManager->expects($this->once())->method('getAssetMappings')->willReturn(array());
        $this->installationManager->expects($this->never())->method('prepareInstallation');
        $this->installationManager->expects($this->never())->method('installResource');
        $args = self::$installCommand->parseArgs(new StringArgs(''));
        $expected = <<<EOF
Nothing to install.

EOF;
        $this->assertSame(0, $this->handler->handleInstall($args, $this->io));
        $this->assertSame($expected, $this->io->fetchOutput());
        $this->assertEmpty($this->io->fetchErrors());
    }
コード例 #14
0
ファイル: LsCommandHandlerTest.php プロジェクト: rejinka/cli
    /**
     * @dataProvider getYears
     */
    public function testListLongFormatsYearDependingOnCurrentYear(DateTime $timestamp, $formattedYear)
    {
        $args = self::$lsCommand->parseArgs(new StringArgs('-l /app'));
        $this->repo->add('/app', new TestDirectory('/app', array($dir1 = new TestDirectory('/app/dir1'))));
        $dir1->getMetadata()->setModificationTime((int) $timestamp->format('U'));
        $dir1->getMetadata()->setSize(12);
        $statusCode = $this->handler->handle($args, $this->io);
        $expected = <<<EOF
TestDirectory 12 Feb 3 {$formattedYear} dir1

EOF;
        $this->assertSame(0, $statusCode);
        $this->assertSame($expected, $this->io->fetchOutput());
        $this->assertEmpty($this->io->fetchErrors());
    }
コード例 #15
0
ファイル: HelpHandlerTest.php プロジェクト: webmozart/console
    public function testHelpPrintsTextIfAsciiDocNotFound()
    {
        $args = $this->helpCommand->parseArgs(new StringArgs('--help'));
        $this->processLauncher->expects($this->any())->method('isSupported')->will($this->returnValue(true));
        $this->executableFinder->expects($this->never())->method('find');
        $this->processLauncher->expects($this->never())->method('launchProcess');
        $this->handler->setApplicationPage('foobar');
        $status = $this->handler->handle($args, $this->io, $this->command);
        $expected = <<<'EOF'
The Application version 1.2.3

USAGE
  the-app
EOF;
        $this->assertStringStartsWith($expected, $this->io->fetchOutput());
        $this->assertSame(0, $status);
    }
コード例 #16
0
    public function testPrintTreeWithAbsolutePath()
    {
        $args = self::$treeCommand->parseArgs(new StringArgs('/app'));
        $this->repo->add('/app', new TestDirectory('/app', array(new TestDirectory('/app/dir1', array(new TestFile('/app/dir1/file1'))), new TestDirectory('/app/dir2', array(new TestFile('/app/dir2/file1'), new TestFile('/app/dir2/file2'))), new TestFile('/app/file'), new TestFile('/app/resource1'), new TestFile('/app/resource2'))));
        $expected = <<<EOF
/app
├── dir1
│   └── file1
├── dir2
│   ├── file1
│   └── file2
├── file
├── resource1
└── resource2

8 resources

EOF;
        $this->assertSame(0, $this->handler->handle($args, $this->io));
        $this->assertSame($expected, $this->io->fetchOutput());
        $this->assertEmpty($this->io->fetchErrors());
    }
コード例 #17
0
ファイル: CommandTest.php プロジェクト: webmozart/console
 public function testParseArgs()
 {
     $rawArgs = $this->getMock('Webmozart\\Console\\Api\\Args\\RawArgs');
     $parsedArgs = new Args(new ArgsFormat());
     $parser = $this->getMock('Webmozart\\Console\\Api\\Args\\ArgsParser');
     $config = new CommandConfig('command');
     $config->setArgsParser($parser);
     $command = new Command($config);
     $parser->expects($this->once())->method('parseArgs')->with($this->identicalTo($rawArgs))->willReturn($parsedArgs);
     $this->assertSame($parsedArgs, $command->parseArgs($rawArgs));
 }