Parses the raw console arguments and returns the parsed arguments.
public parseArgs ( Webmozart\Console\Api\Args\RawArgs $args, boolean $lenient = null ) : |
||
$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. |
Результат | The parsed console arguments. |
/** * @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); }
/** * @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)); }
/** * @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); }
/** * @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); }
/** * @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); }
/** * @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)); }
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()); }
private function parse() { try { $this->parsedArgs = $this->command->parseArgs($this->rawArgs); } catch (CannotParseArgsException $e) { $this->parseError = $e; } $this->parsed = true; }
/** * @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); }
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()); }
/** * @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); }
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()); }
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()); }
/** * @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()); }
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); }
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()); }
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)); }