本文整理汇总了PHP中LimeTest::fail方法的典型用法代码示例。如果您正苦于以下问题:PHP LimeTest::fail方法的具体用法?PHP LimeTest::fail怎么用?PHP LimeTest::fail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LimeTest
的用法示例。
在下文中一共展示了LimeTest::fail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: BuilderConfiguration
$configuration = new BuilderConfiguration(array(), array('foo' => 'bar'));
$configuration->setParameter('bar', 'foo');
$t->is($configuration->getParameter('bar'), 'foo', '->setParameter() sets the value of a new parameter');
$configuration->setParameter('foo', 'baz');
$t->is($configuration->getParameter('foo'), 'baz', '->setParameter() overrides previously set parameter');
$configuration->setParameter('Foo', 'baz1');
$t->is($configuration->getParameter('foo'), 'baz1', '->setParameter() converts the key to lowercase');
$t->is($configuration->getParameter('FOO'), 'baz1', '->getParameter() converts the key to lowercase');
try
{
$configuration->getParameter('baba');
$t->fail('->getParameter() throws an \InvalidArgumentException if the key does not exist');
}
catch (\InvalidArgumentException $e)
{
$t->pass('->getParameter() throws an \InvalidArgumentException if the key does not exist');
}
// ->hasParameter()
$t->diag('->hasParameter()');
$configuration = new BuilderConfiguration(array(), array('foo' => 'bar'));
$t->ok($configuration->hasParameter('foo'), '->hasParameter() returns true if a parameter is defined');
$t->ok($configuration->hasParameter('Foo'), '->hasParameter() converts the key to lowercase');
$t->ok(!$configuration->hasParameter('bar'), '->hasParameter() returns false if a parameter is not defined');
// ->addParameters()
$t->diag('->addParameters()');
示例2: catch
$sc->setParameter('bar', 'foo');
$t->is($sc->getParameter('bar'), 'foo', '->setParameter() sets the value of a new parameter');
$t->is($sc['bar'], 'foo', '->offsetGet() gets the value of a parameter');
$sc['bar1'] = 'foo1';
$t->is($sc['bar1'], 'foo1', '->offsetset() sets the value of a parameter');
unset($sc['bar1']);
$t->ok(!isset($sc['bar1']), '->offsetUnset() removes a parameter');
$sc->setParameter('foo', 'baz');
$t->is($sc->getParameter('foo'), 'baz', '->setParameter() overrides previously set parameter');
$sc->setParameter('Foo', 'baz1');
$t->is($sc->getParameter('foo'), 'baz1', '->setParameter() converts the key to lowercase');
$t->is($sc->getParameter('FOO'), 'baz1', '->getParameter() converts the key to lowercase');
$t->is($sc['FOO'], 'baz1', '->offsetGet() converts the key to lowercase');
try {
$sc->getParameter('baba');
$t->fail('->getParameter() thrown an \\InvalidArgumentException if the key does not exist');
} catch (\InvalidArgumentException $e) {
$t->pass('->getParameter() thrown an \\InvalidArgumentException if the key does not exist');
}
try {
$sc['baba'];
$t->fail('->offsetGet() thrown an \\InvalidArgumentException if the key does not exist');
} catch (\InvalidArgumentException $e) {
$t->pass('->offsetGet() thrown an \\InvalidArgumentException if the key does not exist');
}
// ->hasParameter()
$t->diag('->hasParameter()');
$sc = new Container(array('foo' => 'bar'));
$t->ok($sc->hasParameter('foo'), '->hasParameter() returns true if a parameter is defined');
$t->ok($sc->hasParameter('Foo'), '->hasParameter() converts the key to lowercase');
$t->ok(isset($sc['Foo']), '->offsetExists() converts the key to lowercase');
示例3: Builder
// ->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()
$t->diag('->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()');
$builder = new Builder();
$definitions = array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass'));
$builder->setDefinitions($definitions);
$t->is($builder->getDefinitions(), $definitions, '->setDefinitions() sets the service definitions');
$t->ok($builder->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
$t->ok(!$builder->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$builder->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$t->is($builder->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
$t->ok($builder->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');
$builder->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$t->is($builder->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');
try {
$builder->getDefinition('baz');
$t->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
} catch (InvalidArgumentException $e) {
$t->pass('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
// ->register()
$t->diag('->register()');
$builder = new Builder();
$builder->register('foo', 'FooClass');
$t->ok($builder->hasDefinition('foo'), '->register() registers a new service definition');
$t->ok($builder->getDefinition('foo') instanceof Definition, '->register() returns the newly created Definition instance');
// ->hasService()
$t->diag('->hasService()');
$builder = new Builder();
$t->ok(!$builder->hasService('foo'), '->hasService() returns false if the service does not exist');
$builder->register('foo', 'FooClass');
$t->ok($builder->hasService('foo'), '->hasService() returns true if a service definition exists');
示例4: array
$definition->addArguments(array($bar));
$t->is($definition->getArguments(), array('foo' => $foo, 'bar' => $bar), '->addArguments() does not clear existing InputArgument objects');
// ->addArgument()
$t->diag('->addArgument()');
$definition = new InputDefinition();
$definition->addArgument($foo);
$t->is($definition->getArguments(), array('foo' => $foo), '->addArgument() adds a InputArgument object');
$definition->addArgument($bar);
$t->is($definition->getArguments(), array('foo' => $foo, 'bar' => $bar), '->addArgument() adds a InputArgument object');
// arguments must have different names
try
{
$definition->addArgument($foo1);
$t->fail('->addArgument() throws a Exception if another argument is already registered with the same name');
}
catch (\Exception $e)
{
$t->pass('->addArgument() throws a Exception if another argument is already registered with the same name');
}
// cannot add a parameter after an array parameter
$definition->addArgument(new InputArgument('fooarray', InputArgument::IS_ARRAY));
try
{
$definition->addArgument(new InputArgument('anotherbar'));
$t->fail('->addArgument() throws a Exception if there is an array parameter already registered');
}
catch (\Exception $e)
{
示例5: LimeTest
use Symfony\Components\DependencyInjection\Builder;
use Symfony\Components\DependencyInjection\Loader\IniFileLoader;
$t = new LimeTest(3);
$fixturesPath = realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/');
$loader = new IniFileLoader($fixturesPath.'/ini');
$config = $loader->load('parameters.ini');
$t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%'), '->load() takes a single file name as its first argument');
try
{
$loader->load('foo.ini');
$t->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
}
catch (InvalidArgumentException $e)
{
$t->pass('->load() throws an InvalidArgumentException if the loaded file does not exist');
}
try
{
@$loader->load('nonvalid.ini');
$t->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable');
}
catch (InvalidArgumentException $e)
{
$t->pass('->load() throws an InvalidArgumentException if the loaded file is not parseable');
}
示例6: Safe
$t->is($output->getTitle(), '<strong>escaped!</strong>', '::escape() escapes all methods of the original object');
$t->is($output->title, '<strong>escaped!</strong>', '::escape() escapes all properties of the original object');
$t->is($output->getTitleTitle(), '<strong>escaped!</strong>', '::escape() is recursive');
$t->is($output->getRawValue(), $input, '->getRawValue() returns the unescaped value');
$t->is(Escaper::escape('esc_entities', $output)->getTitle(), '<strong>escaped!</strong>', '::escape() does not double escape an object');
$t->ok(Escaper::escape('esc_entities', new \DirectoryIterator('.')) instanceof IteratorDecorator, '::escape() returns a IteratorDecorator object if the value to escape is an object that implements the ArrayAccess interface');
$t->diag('::escape() does not escape object marked as being safe');
$t->ok(Escaper::escape('esc_entities', new Safe(new OutputEscaperTestClass())) instanceof OutputEscaperTestClass, '::escape() returns the original value if it is marked as being safe');
Escaper::markClassAsSafe('OutputEscaperTestClass');
$t->ok(Escaper::escape('esc_entities', new OutputEscaperTestClass()) instanceof OutputEscaperTestClass, '::escape() returns the original value if the object class is marked as being safe');
$t->ok(Escaper::escape('esc_entities', new OutputEscaperTestClassChild()) instanceof OutputEscaperTestClassChild, '::escape() returns the original value if one of the object parent class is marked as being safe');
$t->diag('::escape() cannot escape resources');
$fh = fopen(__FILE__, 'r');
try {
Escaper::escape('esc_entities', $fh);
$t->fail('::escape() throws an InvalidArgumentException if the value cannot be escaped');
} catch (InvalidArgumentException $e) {
$t->pass('::escape() throws an InvalidArgumentException if the value cannot be escaped');
}
// ::unescape()
$t->diag('::unescape()');
$t->diag('::unescape() does not unescape special values');
$t->ok(Escaper::unescape(null) === null, '::unescape() returns null if the value to unescape is null');
$t->ok(Escaper::unescape(false) === false, '::unescape() returns false if the value to unescape is false');
$t->ok(Escaper::unescape(true) === true, '::unescape() returns true if the value to unescape is true');
$t->diag('::unescape() unescapes strings');
$t->is(Escaper::unescape('<strong>escaped!</strong>'), '<strong>escaped!</strong>', '::unescape() returns an unescaped string if the value to unescape is a string');
$t->is(Escaper::unescape('<strong>échappé</strong>'), '<strong>échappé</strong>', '::unescape() returns an unescaped string if the value to unescape is a string');
$t->diag('::unescape() unescapes arrays');
$input = Escaper::escape('esc_entities', array('foo' => '<strong>escaped!</strong>', 'bar' => array('foo' => '<strong>escaped!</strong>')));
$output = Escaper::unescape($input);
示例7: ArrayInput
$input = new ArrayInput(array('--foo' => 'bar', 'name' => 'Fabien'));
$t->is($input->getFirstArgument(), 'Fabien', '->getFirstArgument() returns the first passed argument');
// ->hasParameterOption()
$t->diag('->hasParameterOption()');
$input = new ArrayInput(array('name' => 'Fabien', '--foo' => 'bar'));
$t->ok($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters');
$t->ok(!$input->hasParameterOption('--bar'), '->hasParameterOption() returns false if an option is not present in the passed parameters');
$input = new ArrayInput(array('--foo'));
$t->ok($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters');
// ->parse()
$t->diag('->parse()');
$input = new ArrayInput(array('name' => 'foo'), new Definition(array(new Argument('name'))));
$t->is($input->getArguments(), array('name' => 'foo'), '->parse() parses required arguments');
try {
$input = new ArrayInput(array('foo' => 'foo'), new Definition(array(new Argument('name'))));
$t->fail('->parse() throws an \\InvalidArgumentException exception if an invalid argument is passed');
} catch (\RuntimeException $e) {
$t->pass('->parse() throws an \\InvalidArgumentException exception if an invalid argument is passed');
}
$input = new ArrayInput(array('--foo' => 'bar'), new Definition(array(new Option('foo'))));
$t->is($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options');
$input = new ArrayInput(array('--foo' => 'bar'), new Definition(array(new Option('foo', 'f', Option::PARAMETER_OPTIONAL, '', 'default'))));
$t->is($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options with a default value');
$input = new ArrayInput(array('--foo' => null), new Definition(array(new Option('foo', 'f', Option::PARAMETER_OPTIONAL, '', 'default'))));
$t->is($input->getOptions(), array('foo' => 'default'), '->parse() parses long options with a default value');
try {
$input = new ArrayInput(array('--foo' => null), new Definition(array(new Option('foo', 'f', Option::PARAMETER_REQUIRED))));
$t->fail('->parse() throws an \\InvalidArgumentException exception if a required option is passed without a value');
} catch (\RuntimeException $e) {
$t->pass('->parse() throws an \\InvalidArgumentException exception if a required option is passed without a value');
}
示例8: FooController
// @Before
$requestMock = $t->mock('Sonata_Request');
$responseMock = $t->mock('Sonata_Response');
$varHolderMock = $t->mock('Sonata_ParameterHolder');
$templateVewMock = $t->mock('Sonata_TemplateView');
$fooController = new FooController($requestMock, $responseMock, $varHolderMock);
// @After
unset($requestMock);
unset($responseMock);
unset($varHolderMock);
unset($templateVewMock);
// @Test: ->dispatch()
// @Test: general
try {
$fooController->dispatch('fail', $templateVewMock);
$t->fail('No code should be executed after calling non-existing actions');
} catch (Sonata_Exception_Controller_Action $ex) {
$t->pass('An exception is thrown for non-existing actions');
}
try {
$fooController->dispatch('myBar', $templateVewMock);
$t->pass('Existing methods are executed correctly');
} catch (Sonata_Exception_Controller_Action $ex) {
$t->fail('No exception should be thrown for existing methods');
}
try {
$fooController->dispatch('myBaz', $templateVewMock);
$t->fail('No code should be executed after calling non-existing methods');
} catch (Sonata_Exception_Controller_Action $ex) {
$t->pass('An exception is thrown for non-existing methods');
}
示例9: ProjectTemplateEngine
$t->ok($renderer->getEngine() === $engine, '__construct() registers itself on all renderers');
$engine = new ProjectTemplateEngine($loader, array('php' => $renderer));
$t->ok($engine->getRenderers() === array('php' => $renderer), '__construct() can overridde the default PHP renderer');
$engine = new ProjectTemplateEngine($loader, array(), $helperSet = new HelperSet());
$t->ok($engine->getHelperSet() === $helperSet, '__construct() takes a helper set as its third argument');
// ->getHelperSet() ->setHelperSet()
$t->diag('->getHelperSet() ->setHelperSet()');
$engine = new ProjectTemplateEngine($loader);
$engine->setHelperSet(new HelperSet(array('foo' => $helper = new SimpleHelper('bar'))));
$t->is((string) $engine->getHelperSet()->get('foo'), 'bar', '->setHelperSet() sets a helper set');
// __get()
$t->diag('__get()');
$t->is($engine->foo, $helper, '->__get() returns the value of a helper');
try {
$engine->bar;
$t->fail('->__get() throws an InvalidArgumentException if the helper is not defined');
} catch (InvalidArgumentException $e) {
$t->pass('->__get() throws an InvalidArgumentException if the helper is not defined');
}
// ->get() ->set() ->has()
$t->diag('->get() ->set() ->has()');
$engine = new ProjectTemplateEngine($loader);
$engine->set('foo', 'bar');
$t->is($engine->get('foo'), 'bar', '->set() sets a slot value');
$t->is($engine->get('bar', 'bar'), 'bar', '->get() takes a default value to return if the slot does not exist');
$t->ok($engine->has('foo'), '->has() returns true if the slot exists');
$t->ok(!$engine->has('bar'), '->has() returns false if the slot does not exist');
// ->output()
$t->diag('->output()');
ob_start();
$ret = $engine->output('foo');
示例10: TestOutput
$output->write('foo');
$t->is($output->output, '', '->write() outputs nothing if verbosity is set to VERBOSITY_QUIET');
$output = new TestOutput();
$output->write(array('foo', 'bar'));
$t->is($output->output, "foo\nbar\n", '->write() can take an array of messages to output');
$output = new TestOutput();
$output->write('<info>foo</info>', Output::OUTPUT_RAW);
$t->is($output->output, "<info>foo</info>\n", '->write() outputs the raw message if OUTPUT_RAW is specified');
$output = new TestOutput();
$output->write('<info>foo</info>', Output::OUTPUT_PLAIN);
$t->is($output->output, "foo\n", '->write() strips decoration tags if OUTPUT_PLAIN is specified');
$output = new TestOutput();
$output->setDecorated(false);
$output->write('<info>foo</info>');
$t->is($output->output, "foo\n", '->write() strips decoration tags if decoration is set to false');
$output = new TestOutput();
$output->setDecorated(true);
$output->write('<foo>foo</foo>');
$t->is($output->output, "[33;41;5mfoo[0m\n", '->write() decorates the output');
try {
$output->write('<foo>foo</foo>', 24);
$t->fail('->write() throws an \\InvalidArgumentException when the type does not exist');
} catch (\InvalidArgumentException $e) {
$t->pass('->write() throws an \\InvalidArgumentException when the type does not exist');
}
try {
$output->write('<bar>foo</bar>');
$t->fail('->write() throws an \\InvalidArgumentException when a style does not exist');
} catch (\InvalidArgumentException $e) {
$t->pass('->write() throws an \\InvalidArgumentException when a style does not exist');
}
示例11: array
// test
$r->run();
$t->diag('The exception handlers are called when a test throws an exception');
// fixtures
$mock = $t->mock('Mock', array('strict' => true));
$r = new LimeTestRunner();
$r->addTest(array($mock, 'testThrowsException'), '', '', 0);
$r->addExceptionHandler(array($mock, 'handleExceptionFailed'));
$r->addExceptionHandler(array($mock, 'handleExceptionSuccessful'));
$mock->testThrowsException()->throws('Exception');
$mock->method('handleExceptionFailed')->returns(false);
$mock->method('handleExceptionSuccessful')->returns(true);
$mock->replay();
// test
$r->run();
$t->diag('If no exception handler returns true, the exception is thrown again');
// fixtures
$mock = $t->mock('Mock', array('strict' => true));
$r = new LimeTestRunner();
$r->addTest(array($mock, 'testThrowsException'), '', '', 0);
$r->addExceptionHandler(array($mock, 'handleExceptionFailed'));
$mock->testThrowsException()->throws('Exception');
$mock->method('handleExceptionFailed')->returns(false);
$mock->replay();
// test
$t->expect('Exception');
try {
$r->run();
$t->fail('The exception was thrown');
} catch (Exception $e) {
}
示例12: array
$t->is($input->getArguments(), array('name' => 'foo'), '->parse() parses required arguments');
$input->bind(new Definition(array(new Argument('name'))));
$t->is($input->getArguments(), array('name' => 'foo'), '->parse() is stateless');
$input = new TestInput(array('cli.php', '--foo'));
$input->bind(new Definition(array(new Option('foo'))));
$t->is($input->getOptions(), array('foo' => true), '->parse() parses long options without parameter');
$input = new TestInput(array('cli.php', '--foo=bar'));
$input->bind(new Definition(array(new Option('foo', 'f', Option::PARAMETER_REQUIRED))));
$t->is($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options with a required parameter (with a = separator)');
$input = new TestInput(array('cli.php', '--foo', 'bar'));
$input->bind(new Definition(array(new Option('foo', 'f', Option::PARAMETER_REQUIRED))));
$t->is($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options with a required parameter (with a space separator)');
try {
$input = new TestInput(array('cli.php', '--foo'));
$input->bind(new Definition(array(new Option('foo', 'f', Option::PARAMETER_REQUIRED))));
$t->fail('->parse() throws a \\RuntimeException if no parameter is passed to an option when it is required');
} catch (\RuntimeException $e) {
$t->pass('->parse() throws a \\RuntimeException if no parameter is passed to an option when it is required');
}
$input = new TestInput(array('cli.php', '-f'));
$input->bind(new Definition(array(new Option('foo', 'f'))));
$t->is($input->getOptions(), array('foo' => true), '->parse() parses short options without parameter');
$input = new TestInput(array('cli.php', '-fbar'));
$input->bind(new Definition(array(new Option('foo', 'f', Option::PARAMETER_REQUIRED))));
$t->is($input->getOptions(), array('foo' => 'bar'), '->parse() parses short options with a required parameter (with no separator)');
$input = new TestInput(array('cli.php', '-f', 'bar'));
$input->bind(new Definition(array(new Option('foo', 'f', Option::PARAMETER_REQUIRED))));
$t->is($input->getOptions(), array('foo' => 'bar'), '->parse() parses short options with a required parameter (with a space separator)');
$input = new TestInput(array('cli.php', '-f', '-b', 'foo'));
$input->bind(new Definition(array(new Argument('name'), new Option('foo', 'f', Option::PARAMETER_OPTIONAL), new Option('bar', 'b'))));
$t->is($input->getOptions(), array('foo' => null, 'bar' => true), '->parse() parses short options with an optional parameter which is not present');
示例13: LimeTest
* file that was distributed with this source code.
*/
require_once __DIR__ . '/../../../../bootstrap.php';
require_once __DIR__ . '/../../../../../lib/SymfonyTests/Components/Templating/SimpleHelper.php';
use Symfony\Components\Templating\Helper\HelperSet;
use Symfony\Components\Templating\Engine;
use Symfony\Components\Templating\Loader\FilesystemLoader;
$t = new LimeTest(7);
$engine = new Engine(new FilesystemLoader('/'));
// __construct()
$t->diag('__construct()');
$helperSet = new HelperSet(array('foo' => $helper = new SimpleHelper('foo')));
$t->ok($helperSet->has('foo'), '__construct() takes an array of helpers as its first argument');
// ->setEngine()
$t->diag('->getEngine()');
$helperSet = new HelperSet(array('foo' => $helper = new SimpleHelper('foo')));
$t->ok($helper->getHelperSet() === $helperSet, '->__construct() changes the embedded helper set of the given helpers');
// ->get() ->set() ->has()
$t->diag('->getHelper() ->setHelper() ->has()');
$helperSet = new HelperSet();
$helperSet->set($helper = new SimpleHelper('bar'));
$t->ok($helper->getHelperSet() === $helperSet, '->set() changes the embedded helper set of the helper');
$t->is((string) $helperSet->get('foo'), 'bar', '->set() sets a helper value');
$t->ok($helperSet->has('foo'), '->has() returns true if the helper is defined');
$t->ok(!$helperSet->has('bar'), '->has() returns false if the helper is not defined');
try {
$helperSet->get('bar');
$t->fail('->get() throws an InvalidArgumentException if the helper is not defined');
} catch (InvalidArgumentException $e) {
$t->pass('->get() throws an InvalidArgumentException if the helper is not defined');
}
示例14: setWantHelps
$application = new Application();
$application->addCommands(array($foo = new FooCommand(), $foo1 = new Foo1Command()));
$commands = $application->getCommands();
$t->is(array($commands['foo:bar'], $commands['foo:bar1']), array($foo, $foo1), '->addCommands() registers an array of commands');
// ->hasCommand() ->getCommand()
$t->diag('->hasCommand() ->getCommand()');
$application = new Application();
$t->ok($application->hasCommand('list'), '->hasCommand() returns true if a named command is registered');
$t->ok(!$application->hasCommand('afoobar'), '->hasCommand() returns false if a named command is not registered');
$application->addCommand($foo = new FooCommand());
$t->ok($application->hasCommand('afoobar'), '->hasCommand() returns true if an alias is registered');
$t->is($application->getCommand('foo:bar'), $foo, '->getCommand() returns a command by name');
$t->is($application->getCommand('afoobar'), $foo, '->getCommand() returns a command by alias');
try {
$application->getCommand('foofoo');
$t->fail('->getCommand() throws an \\InvalidArgumentException if the command does not exist');
} catch (\InvalidArgumentException $e) {
$t->pass('->getCommand() throws an \\InvalidArgumentException if the command does not exist');
}
class TestApplication extends Application
{
public function setWantHelps()
{
$this->wantHelps = true;
}
}
$application = new TestApplication();
$application->addCommand($foo = new FooCommand());
$application->setWantHelps();
$command = $application->getCommand('foo:bar');
$t->is(get_class($command), 'Symfony\\Components\\CLI\\Command\\HelpCommand', '->getCommand() returns the help command if --help is provided as the input');
示例15: LimeTest
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\CLI\Input\Option;
use Symfony\Components\CLI\Exception;
$t = new LimeTest(34);
// __construct()
$t->diag('__construct()');
$option = new Option('foo');
$t->is($option->getName(), 'foo', '__construct() takes a name as its first argument');
$option = new Option('--foo');
$t->is($option->getName(), 'foo', '__construct() removes the leading -- of the option name');
try {
$option = new Option('foo', 'f', Option::PARAMETER_IS_ARRAY);
$t->fail('->setDefault() throws an Exception if PARAMETER_IS_ARRAY option is used when an option does not accept a value');
} catch (\Exception $e) {
$t->pass('->setDefault() throws an Exception if PARAMETER_IS_ARRAY option is used when an option does not accept a value');
}
// shortcut argument
$option = new Option('foo', 'f');
$t->is($option->getShortcut(), 'f', '__construct() can take a shortcut as its second argument');
$option = new Option('foo', '-f');
$t->is($option->getShortcut(), 'f', '__construct() removes the leading - of the shortcut');
// mode argument
$option = new Option('foo', 'f');
$t->is($option->acceptParameter(), false, '__construct() gives a "Option::PARAMETER_NONE" mode by default');
$t->is($option->isParameterRequired(), false, '__construct() gives a "Option::PARAMETER_NONE" mode by default');
$t->is($option->isParameterOptional(), false, '__construct() gives a "Option::PARAMETER_NONE" mode by default');
$option = new Option('foo', 'f', null);
$t->is($option->acceptParameter(), false, '__construct() can take "Option::PARAMETER_NONE" as its mode');