Best Ginkgo code snippet using command.Run
ApplicationTest.php
Source:ApplicationTest.php
...424 $application = new Application();425 $application->add(new \Foo3Command());426 $application->find($name);427 }428 public function testDontRunAlternativeNamespaceName()429 {430 $application = new Application();431 $application->add(new \Foo1Command());432 $application->setAutoExit(false);433 $tester = new ApplicationTester($application);434 $tester->run(['command' => 'foos:bar1'], ['decorated' => false]);435 $this->assertSame('436 437 There are no commands defined in the "foos" namespace. 438 439 Did you mean this? 440 foo 441 442', $tester->getDisplay(true));443 }444 public function testCanRunAlternativeCommandName()445 {446 $application = new Application();447 $application->add(new \FooWithoutAliasCommand());448 $application->setAutoExit(false);449 $tester = new ApplicationTester($application);450 $tester->setInputs(['y']);451 $tester->run(['command' => 'foos'], ['decorated' => false]);452 $display = trim($tester->getDisplay(true));453 $this->assertContains('Command "foos" is not defined', $display);454 $this->assertContains('Do you want to run "foo" instead? (yes/no) [no]:', $display);455 $this->assertContains('called', $display);456 }457 public function testDontRunAlternativeCommandName()458 {459 $application = new Application();460 $application->add(new \FooWithoutAliasCommand());461 $application->setAutoExit(false);462 $tester = new ApplicationTester($application);463 $tester->setInputs(['n']);464 $exitCode = $tester->run(['command' => 'foos'], ['decorated' => false]);465 $this->assertSame(1, $exitCode);466 $display = trim($tester->getDisplay(true));467 $this->assertContains('Command "foos" is not defined', $display);468 $this->assertContains('Do you want to run "foo" instead? (yes/no) [no]:', $display);469 }470 public function provideInvalidCommandNamesSingle()471 {472 return [473 ['foo3:barr'],474 ['fooo3:bar'],475 ];476 }477 public function testFindAlternativeExceptionMessageMultiple()478 {479 putenv('COLUMNS=120');480 $application = new Application();481 $application->add(new \FooCommand());482 $application->add(new \Foo1Command());483 $application->add(new \Foo2Command());484 // Command + plural485 try {486 $application->find('foo:baR');487 $this->fail('->find() throws a CommandNotFoundException if command does not exist, with alternatives');488 } catch (\Exception $e) {489 $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives');490 $this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');491 $this->assertRegExp('/foo1:bar/', $e->getMessage());492 $this->assertRegExp('/foo:bar/', $e->getMessage());493 }494 // Namespace + plural495 try {496 $application->find('foo2:bar');497 $this->fail('->find() throws a CommandNotFoundException if command does not exist, with alternatives');498 } catch (\Exception $e) {499 $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives');500 $this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');501 $this->assertRegExp('/foo1/', $e->getMessage());502 }503 $application->add(new \Foo3Command());504 $application->add(new \Foo4Command());505 // Subnamespace + plural506 try {507 $a = $application->find('foo3:');508 $this->fail('->find() should throw an Symfony\Component\Console\Exception\CommandNotFoundException if a command is ambiguous because of a subnamespace, with alternatives');509 } catch (\Exception $e) {510 $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e);511 $this->assertRegExp('/foo3:bar/', $e->getMessage());512 $this->assertRegExp('/foo3:bar:toh/', $e->getMessage());513 }514 }515 public function testFindAlternativeCommands()516 {517 $application = new Application();518 $application->add(new \FooCommand());519 $application->add(new \Foo1Command());520 $application->add(new \Foo2Command());521 try {522 $application->find($commandName = 'Unknown command');523 $this->fail('->find() throws a CommandNotFoundException if command does not exist');524 } catch (\Exception $e) {525 $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist');526 $this->assertSame([], $e->getAlternatives());527 $this->assertEquals(sprintf('Command "%s" is not defined.', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without alternatives');528 }529 // Test if "bar1" command throw a "CommandNotFoundException" and does not contain530 // "foo:bar" as alternative because "bar1" is too far from "foo:bar"531 try {532 $application->find($commandName = 'bar1');533 $this->fail('->find() throws a CommandNotFoundException if command does not exist');534 } catch (\Exception $e) {535 $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist');536 $this->assertSame(['afoobar1', 'foo:bar1'], $e->getAlternatives());537 $this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');538 $this->assertRegExp('/afoobar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "afoobar1"');539 $this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "foo:bar1"');540 $this->assertNotRegExp('/foo:bar(?>!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative');541 }542 }543 public function testFindAlternativeCommandsWithAnAlias()544 {545 $fooCommand = new \FooCommand();546 $fooCommand->setAliases(['foo2']);547 $application = new Application();548 $application->add($fooCommand);549 $result = $application->find('foo');550 $this->assertSame($fooCommand, $result);551 }552 public function testFindAlternativeNamespace()553 {554 $application = new Application();555 $application->add(new \FooCommand());556 $application->add(new \Foo1Command());557 $application->add(new \Foo2Command());558 $application->add(new \Foo3Command());559 try {560 $application->find('Unknown-namespace:Unknown-command');561 $this->fail('->find() throws a CommandNotFoundException if namespace does not exist');562 } catch (\Exception $e) {563 $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if namespace does not exist');564 $this->assertSame([], $e->getAlternatives());565 $this->assertEquals('There are no commands defined in the "Unknown-namespace" namespace.', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, without alternatives');566 }567 try {568 $application->find('foo2:command');569 $this->fail('->find() throws a CommandNotFoundException if namespace does not exist');570 } catch (\Exception $e) {571 $this->assertInstanceOf('Symfony\Component\Console\Exception\NamespaceNotFoundException', $e, '->find() throws a NamespaceNotFoundException if namespace does not exist');572 $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, 'NamespaceNotFoundException extends from CommandNotFoundException');573 $this->assertCount(3, $e->getAlternatives());574 $this->assertContains('foo', $e->getAlternatives());575 $this->assertContains('foo1', $e->getAlternatives());576 $this->assertContains('foo3', $e->getAlternatives());577 $this->assertRegExp('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative');578 $this->assertRegExp('/foo/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo"');579 $this->assertRegExp('/foo1/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo1"');580 $this->assertRegExp('/foo3/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo3"');581 }582 }583 public function testFindAlternativesOutput()584 {585 $application = new Application();586 $application->add(new \FooCommand());587 $application->add(new \Foo1Command());588 $application->add(new \Foo2Command());589 $application->add(new \Foo3Command());590 $expectedAlternatives = [591 'afoobar',592 'afoobar1',593 'afoobar2',594 'foo1:bar',595 'foo3:bar',596 'foo:bar',597 'foo:bar1',598 ];599 try {600 $application->find('foo');601 $this->fail('->find() throws a CommandNotFoundException if command is not defined');602 } catch (\Exception $e) {603 $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command is not defined');604 $this->assertSame($expectedAlternatives, $e->getAlternatives());605 $this->assertRegExp('/Command "foo" is not defined\..*Did you mean one of these\?.*/Ums', $e->getMessage());606 }607 }608 public function testFindNamespaceDoesNotFailOnDeepSimilarNamespaces()609 {610 $application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(['getNamespaces'])->getMock();611 $application->expects($this->once())612 ->method('getNamespaces')613 ->willReturn(['foo:sublong', 'bar:sub']);614 $this->assertEquals('foo:sublong', $application->findNamespace('f:sub'));615 }616 /**617 * @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException618 * @expectedExceptionMessage Command "foo::bar" is not defined.619 */620 public function testFindWithDoubleColonInNameThrowsException()621 {622 $application = new Application();623 $application->add(new \FooCommand());624 $application->add(new \Foo4Command());625 $application->find('foo::bar');626 }627 public function testSetCatchExceptions()628 {629 $application = new Application();630 $application->setAutoExit(false);631 putenv('COLUMNS=120');632 $tester = new ApplicationTester($application);633 $application->setCatchExceptions(true);634 $this->assertTrue($application->areExceptionsCaught());635 $tester->run(['command' => 'foo'], ['decorated' => false]);636 $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getDisplay(true), '->setCatchExceptions() sets the catch exception flag');637 $tester->run(['command' => 'foo'], ['decorated' => false, 'capture_stderr_separately' => true]);638 $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getErrorOutput(true), '->setCatchExceptions() sets the catch exception flag');639 $this->assertSame('', $tester->getDisplay(true));640 $application->setCatchExceptions(false);641 try {642 $tester->run(['command' => 'foo'], ['decorated' => false]);643 $this->fail('->setCatchExceptions() sets the catch exception flag');644 } catch (\Exception $e) {645 $this->assertInstanceOf('\Exception', $e, '->setCatchExceptions() sets the catch exception flag');646 $this->assertEquals('Command "foo" is not defined.', $e->getMessage(), '->setCatchExceptions() sets the catch exception flag');647 }648 }649 public function testAutoExitSetting()650 {651 $application = new Application();652 $this->assertTrue($application->isAutoExitEnabled());653 $application->setAutoExit(false);654 $this->assertFalse($application->isAutoExitEnabled());655 }656 public function testRenderException()657 {658 $application = new Application();659 $application->setAutoExit(false);660 putenv('COLUMNS=120');661 $tester = new ApplicationTester($application);662 $tester->run(['command' => 'foo'], ['decorated' => false, 'capture_stderr_separately' => true]);663 $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exception');664 $tester->run(['command' => 'foo'], ['decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE, 'capture_stderr_separately' => true]);665 $this->assertContains('Exception trace', $tester->getErrorOutput(), '->renderException() renders a pretty exception with a stack trace when verbosity is verbose');666 $tester->run(['command' => 'list', '--foo' => true], ['decorated' => false, 'capture_stderr_separately' => true]);667 $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $tester->getErrorOutput(true), '->renderException() renders the command synopsis when an exception occurs in the context of a command');668 $application->add(new \Foo3Command());669 $tester = new ApplicationTester($application);670 $tester->run(['command' => 'foo3:bar'], ['decorated' => false, 'capture_stderr_separately' => true]);671 $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exceptions with previous exceptions');672 $tester->run(['command' => 'foo3:bar'], ['decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE]);673 $this->assertRegExp('/\[Exception\]\s*First exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is default and verbosity is verbose');674 $this->assertRegExp('/\[Exception\]\s*Second exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is 0 and verbosity is verbose');675 $this->assertRegExp('/\[Exception \(404\)\]\s*Third exception/', $tester->getDisplay(), '->renderException() renders a pretty exception with code exception when code exception is 404 and verbosity is verbose');676 $tester->run(['command' => 'foo3:bar'], ['decorated' => true]);677 $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3decorated.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');678 $tester->run(['command' => 'foo3:bar'], ['decorated' => true, 'capture_stderr_separately' => true]);679 $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3decorated.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exceptions with previous exceptions');680 $application = new Application();681 $application->setAutoExit(false);682 putenv('COLUMNS=32');683 $tester = new ApplicationTester($application);684 $tester->run(['command' => 'foo'], ['decorated' => false, 'capture_stderr_separately' => true]);685 $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $tester->getErrorOutput(true), '->renderException() wraps messages when they are bigger than the terminal');686 putenv('COLUMNS=120');687 }688 public function testRenderExceptionWithDoubleWidthCharacters()689 {690 $application = new Application();691 $application->setAutoExit(false);692 putenv('COLUMNS=120');693 $application->register('foo')->setCode(function () {694 throw new \Exception('ã¨ã©ã¼ã¡ãã»ã¼ã¸');695 });696 $tester = new ApplicationTester($application);697 $tester->run(['command' => 'foo'], ['decorated' => false, 'capture_stderr_separately' => true]);698 $this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_renderexception_doublewidth1.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exceptions with previous exceptions');699 $tester->run(['command' => 'foo'], ['decorated' => true, 'capture_stderr_separately' => true]);700 $this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_renderexception_doublewidth1decorated.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exceptions with previous exceptions');701 $application = new Application();702 $application->setAutoExit(false);703 putenv('COLUMNS=32');704 $application->register('foo')->setCode(function () {705 throw new \Exception('ã³ãã³ãã®å®è¡ä¸ã«ã¨ã©ã¼ãçºçãã¾ããã');706 });707 $tester = new ApplicationTester($application);708 $tester->run(['command' => 'foo'], ['decorated' => false, 'capture_stderr_separately' => true]);709 $this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_renderexception_doublewidth2.txt', $tester->getErrorOutput(true), '->renderException() wraps messages when they are bigger than the terminal');710 putenv('COLUMNS=120');711 }712 public function testRenderExceptionEscapesLines()713 {714 $application = new Application();715 $application->setAutoExit(false);716 putenv('COLUMNS=22');717 $application->register('foo')->setCode(function () {718 throw new \Exception('dont break here <info>!</info>');719 });720 $tester = new ApplicationTester($application);721 $tester->run(['command' => 'foo'], ['decorated' => false]);722 $this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_renderexception_escapeslines.txt', $tester->getDisplay(true), '->renderException() escapes lines containing formatting');723 putenv('COLUMNS=120');724 }725 public function testRenderExceptionLineBreaks()726 {727 $application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(['getTerminalWidth'])->getMock();728 $application->setAutoExit(false);729 $application->expects($this->any())730 ->method('getTerminalWidth')731 ->willReturn(120);732 $application->register('foo')->setCode(function () {733 throw new \InvalidArgumentException("\n\nline 1 with extra spaces \nline 2\n\nline 4\n");734 });735 $tester = new ApplicationTester($application);736 $tester->run(['command' => 'foo'], ['decorated' => false]);737 $this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_renderexception_linebreaks.txt', $tester->getDisplay(true), '->renderException() keep multiple line breaks');738 }739 public function testRenderAnonymousException()740 {741 $application = new Application();742 $application->setAutoExit(false);743 $application->register('foo')->setCode(function () {744 throw new class('') extends \InvalidArgumentException {745 };746 });747 $tester = new ApplicationTester($application);748 $tester->run(['command' => 'foo'], ['decorated' => false]);749 $this->assertContains('[InvalidArgumentException@anonymous]', $tester->getDisplay(true));750 $application = new Application();751 $application->setAutoExit(false);752 $application->register('foo')->setCode(function () {753 throw new \InvalidArgumentException(sprintf('Dummy type "%s" is invalid.', \get_class(new class() {754 })));755 });756 $tester = new ApplicationTester($application);757 $tester->run(['command' => 'foo'], ['decorated' => false]);758 $this->assertContains('Dummy type "@anonymous" is invalid.', $tester->getDisplay(true));759 }760 public function testRenderExceptionStackTraceContainsRootException()761 {762 $application = new Application();763 $application->setAutoExit(false);764 $application->register('foo')->setCode(function () {765 throw new class('') extends \InvalidArgumentException {766 };767 });768 $tester = new ApplicationTester($application);769 $tester->run(['command' => 'foo'], ['decorated' => false]);770 $this->assertContains('[InvalidArgumentException@anonymous]', $tester->getDisplay(true));771 $application = new Application();772 $application->setAutoExit(false);773 $application->register('foo')->setCode(function () {774 throw new \InvalidArgumentException(sprintf('Dummy type "%s" is invalid.', \get_class(new class() {775 })));776 });777 $tester = new ApplicationTester($application);778 $tester->run(['command' => 'foo'], ['decorated' => false]);779 $this->assertContains('Dummy type "@anonymous" is invalid.', $tester->getDisplay(true));780 }781 public function testRun()782 {783 $application = new Application();784 $application->setAutoExit(false);785 $application->setCatchExceptions(false);786 $application->add($command = new \Foo1Command());787 $_SERVER['argv'] = ['cli.php', 'foo:bar1'];788 ob_start();789 $application->run();790 ob_end_clean();791 $this->assertInstanceOf('Symfony\Component\Console\Input\ArgvInput', $command->input, '->run() creates an ArgvInput by default if none is given');792 $this->assertInstanceOf('Symfony\Component\Console\Output\ConsoleOutput', $command->output, '->run() creates a ConsoleOutput by default if none is given');793 $application = new Application();794 $application->setAutoExit(false);795 $application->setCatchExceptions(false);796 $this->ensureStaticCommandHelp($application);797 $tester = new ApplicationTester($application);798 $tester->run([], ['decorated' => false]);799 $this->assertStringEqualsFile(self::$fixturesPath.'/application_run1.txt', $tester->getDisplay(true), '->run() runs the list command if no argument is passed');800 $tester->run(['--help' => true], ['decorated' => false]);801 $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $tester->getDisplay(true), '->run() runs the help command if --help is passed');802 $tester->run(['-h' => true], ['decorated' => false]);803 $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $tester->getDisplay(true), '->run() runs the help command if -h is passed');804 $tester->run(['command' => 'list', '--help' => true], ['decorated' => false]);805 $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $tester->getDisplay(true), '->run() displays the help if --help is passed');806 $tester->run(['command' => 'list', '-h' => true], ['decorated' => false]);807 $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $tester->getDisplay(true), '->run() displays the help if -h is passed');808 $tester->run(['--ansi' => true]);809 $this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if --ansi is passed');810 $tester->run(['--no-ansi' => true]);811 $this->assertFalse($tester->getOutput()->isDecorated(), '->run() forces color output to be disabled if --no-ansi is passed');812 $tester->run(['--version' => true], ['decorated' => false]);813 $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $tester->getDisplay(true), '->run() displays the program version if --version is passed');814 $tester->run(['-V' => true], ['decorated' => false]);815 $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $tester->getDisplay(true), '->run() displays the program version if -v is passed');816 $tester->run(['command' => 'list', '--quiet' => true]);817 $this->assertSame('', $tester->getDisplay(), '->run() removes all output if --quiet is passed');818 $this->assertFalse($tester->getInput()->isInteractive(), '->run() sets off the interactive mode if --quiet is passed');819 $tester->run(['command' => 'list', '-q' => true]);820 $this->assertSame('', $tester->getDisplay(), '->run() removes all output if -q is passed');821 $this->assertFalse($tester->getInput()->isInteractive(), '->run() sets off the interactive mode if -q is passed');822 $tester->run(['command' => 'list', '--verbose' => true]);823 $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose is passed');824 $tester->run(['command' => 'list', '--verbose' => 1]);825 $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose=1 is passed');826 $tester->run(['command' => 'list', '--verbose' => 2]);827 $this->assertSame(Output::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to very verbose if --verbose=2 is passed');828 $tester->run(['command' => 'list', '--verbose' => 3]);829 $this->assertSame(Output::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity(), '->run() sets the output to debug if --verbose=3 is passed');830 $tester->run(['command' => 'list', '--verbose' => 4]);831 $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if unknown --verbose level is passed');832 $tester->run(['command' => 'list', '-v' => true]);833 $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');834 $tester->run(['command' => 'list', '-vv' => true]);835 $this->assertSame(Output::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');836 $tester->run(['command' => 'list', '-vvv' => true]);837 $this->assertSame(Output::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');838 $application = new Application();839 $application->setAutoExit(false);840 $application->setCatchExceptions(false);841 $application->add(new \FooCommand());842 $tester = new ApplicationTester($application);843 $tester->run(['command' => 'foo:bar', '--no-interaction' => true], ['decorated' => false]);844 $this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if --no-interaction is passed');845 $tester->run(['command' => 'foo:bar', '-n' => true], ['decorated' => false]);846 $this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed');847 }848 public function testRunWithGlobalOptionAndNoCommand()849 {850 $application = new Application();851 $application->setAutoExit(false);852 $application->setCatchExceptions(false);853 $application->getDefinition()->addOption(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL));854 $output = new StreamOutput(fopen('php://memory', 'w', false));855 $input = new ArgvInput(['cli.php', '--foo', 'bar']);856 $this->assertSame(0, $application->run($input, $output));857 }858 /**859 * Issue #9285.860 *861 * If the "verbose" option is just before an argument in ArgvInput,862 * an argument value should not be treated as verbosity value.863 * This test will fail with "Not enough arguments." if broken864 */865 public function testVerboseValueNotBreakArguments()866 {867 $application = new Application();868 $application->setAutoExit(false);869 $application->setCatchExceptions(false);870 $application->add(new \FooCommand());871 $output = new StreamOutput(fopen('php://memory', 'w', false));872 $input = new ArgvInput(['cli.php', '-v', 'foo:bar']);873 $application->run($input, $output);874 $this->addToAssertionCount(1);875 $input = new ArgvInput(['cli.php', '--verbose', 'foo:bar']);876 $application->run($input, $output);877 $this->addToAssertionCount(1);878 }879 public function testRunReturnsIntegerExitCode()880 {881 $exception = new \Exception('', 4);882 $application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(['doRun'])->getMock();883 $application->setAutoExit(false);884 $application->expects($this->once())885 ->method('doRun')886 ->willThrowException($exception);887 $exitCode = $application->run(new ArrayInput([]), new NullOutput());888 $this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');889 }890 public function testRunDispatchesIntegerExitCode()891 {892 $passedRightValue = false;893 // We can assume here that some other test asserts that the event is dispatched at all894 $dispatcher = new EventDispatcher();895 $dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use (&$passedRightValue) {896 $passedRightValue = (4 === $event->getExitCode());897 });898 $application = new Application();899 $application->setDispatcher($dispatcher);900 $application->setAutoExit(false);901 $application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) {902 throw new \Exception('', 4);903 });904 $tester = new ApplicationTester($application);905 $tester->run(['command' => 'test']);906 $this->assertTrue($passedRightValue, '-> exit code 4 was passed in the console.terminate event');907 }908 public function testRunReturnsExitCodeOneForExceptionCodeZero()909 {910 $exception = new \Exception('', 0);911 $application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(['doRun'])->getMock();912 $application->setAutoExit(false);913 $application->expects($this->once())914 ->method('doRun')915 ->willThrowException($exception);916 $exitCode = $application->run(new ArrayInput([]), new NullOutput());917 $this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');918 }919 public function testRunDispatchesExitCodeOneForExceptionCodeZero()920 {921 $passedRightValue = false;922 // We can assume here that some other test asserts that the event is dispatched at all923 $dispatcher = new EventDispatcher();924 $dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use (&$passedRightValue) {925 $passedRightValue = (1 === $event->getExitCode());926 });927 $application = new Application();928 $application->setDispatcher($dispatcher);929 $application->setAutoExit(false);930 $application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) {931 throw new \Exception();932 });933 $tester = new ApplicationTester($application);934 $tester->run(['command' => 'test']);935 $this->assertTrue($passedRightValue, '-> exit code 1 was passed in the console.terminate event');936 }937 /**938 * @expectedException \LogicException939 * @expectedExceptionMessage An option with shortcut "e" already exists.940 */941 public function testAddingOptionWithDuplicateShortcut()942 {943 $dispatcher = new EventDispatcher();944 $application = new Application();945 $application->setAutoExit(false);946 $application->setCatchExceptions(false);947 $application->setDispatcher($dispatcher);948 $application->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'Environment'));949 $application950 ->register('foo')951 ->setAliases(['f'])952 ->setDefinition([new InputOption('survey', 'e', InputOption::VALUE_REQUIRED, 'My option with a shortcut.')])953 ->setCode(function (InputInterface $input, OutputInterface $output) {})954 ;955 $input = new ArrayInput(['command' => 'foo']);956 $output = new NullOutput();957 $application->run($input, $output);958 }959 /**960 * @expectedException \LogicException961 * @dataProvider getAddingAlreadySetDefinitionElementData962 */963 public function testAddingAlreadySetDefinitionElementData($def)964 {965 $application = new Application();966 $application->setAutoExit(false);967 $application->setCatchExceptions(false);968 $application969 ->register('foo')970 ->setDefinition([$def])971 ->setCode(function (InputInterface $input, OutputInterface $output) {})972 ;973 $input = new ArrayInput(['command' => 'foo']);974 $output = new NullOutput();975 $application->run($input, $output);976 }977 public function getAddingAlreadySetDefinitionElementData()978 {979 return [980 [new InputArgument('command', InputArgument::REQUIRED)],981 [new InputOption('quiet', '', InputOption::VALUE_NONE)],982 [new InputOption('query', 'q', InputOption::VALUE_NONE)],983 ];984 }985 public function testGetDefaultHelperSetReturnsDefaultValues()986 {987 $application = new Application();988 $application->setAutoExit(false);989 $application->setCatchExceptions(false);990 $helperSet = $application->getHelperSet();991 $this->assertTrue($helperSet->has('formatter'));992 }993 public function testAddingSingleHelperSetOverwritesDefaultValues()994 {995 $application = new Application();996 $application->setAutoExit(false);997 $application->setCatchExceptions(false);998 $application->setHelperSet(new HelperSet([new FormatterHelper()]));999 $helperSet = $application->getHelperSet();1000 $this->assertTrue($helperSet->has('formatter'));1001 // no other default helper set should be returned1002 $this->assertFalse($helperSet->has('dialog'));1003 $this->assertFalse($helperSet->has('progress'));1004 }1005 public function testOverwritingDefaultHelperSetOverwritesDefaultValues()1006 {1007 $application = new CustomApplication();1008 $application->setAutoExit(false);1009 $application->setCatchExceptions(false);1010 $application->setHelperSet(new HelperSet([new FormatterHelper()]));1011 $helperSet = $application->getHelperSet();1012 $this->assertTrue($helperSet->has('formatter'));1013 // no other default helper set should be returned1014 $this->assertFalse($helperSet->has('dialog'));1015 $this->assertFalse($helperSet->has('progress'));1016 }1017 public function testGetDefaultInputDefinitionReturnsDefaultValues()1018 {1019 $application = new Application();1020 $application->setAutoExit(false);1021 $application->setCatchExceptions(false);1022 $inputDefinition = $application->getDefinition();1023 $this->assertTrue($inputDefinition->hasArgument('command'));1024 $this->assertTrue($inputDefinition->hasOption('help'));1025 $this->assertTrue($inputDefinition->hasOption('quiet'));1026 $this->assertTrue($inputDefinition->hasOption('verbose'));1027 $this->assertTrue($inputDefinition->hasOption('version'));1028 $this->assertTrue($inputDefinition->hasOption('ansi'));1029 $this->assertTrue($inputDefinition->hasOption('no-ansi'));1030 $this->assertTrue($inputDefinition->hasOption('no-interaction'));1031 }1032 public function testOverwritingDefaultInputDefinitionOverwritesDefaultValues()1033 {1034 $application = new CustomApplication();1035 $application->setAutoExit(false);1036 $application->setCatchExceptions(false);1037 $inputDefinition = $application->getDefinition();1038 // check whether the default arguments and options are not returned any more1039 $this->assertFalse($inputDefinition->hasArgument('command'));1040 $this->assertFalse($inputDefinition->hasOption('help'));1041 $this->assertFalse($inputDefinition->hasOption('quiet'));1042 $this->assertFalse($inputDefinition->hasOption('verbose'));1043 $this->assertFalse($inputDefinition->hasOption('version'));1044 $this->assertFalse($inputDefinition->hasOption('ansi'));1045 $this->assertFalse($inputDefinition->hasOption('no-ansi'));1046 $this->assertFalse($inputDefinition->hasOption('no-interaction'));1047 $this->assertTrue($inputDefinition->hasOption('custom'));1048 }1049 public function testSettingCustomInputDefinitionOverwritesDefaultValues()1050 {1051 $application = new Application();1052 $application->setAutoExit(false);1053 $application->setCatchExceptions(false);1054 $application->setDefinition(new InputDefinition([new InputOption('--custom', '-c', InputOption::VALUE_NONE, 'Set the custom input definition.')]));1055 $inputDefinition = $application->getDefinition();1056 // check whether the default arguments and options are not returned any more1057 $this->assertFalse($inputDefinition->hasArgument('command'));1058 $this->assertFalse($inputDefinition->hasOption('help'));1059 $this->assertFalse($inputDefinition->hasOption('quiet'));1060 $this->assertFalse($inputDefinition->hasOption('verbose'));1061 $this->assertFalse($inputDefinition->hasOption('version'));1062 $this->assertFalse($inputDefinition->hasOption('ansi'));1063 $this->assertFalse($inputDefinition->hasOption('no-ansi'));1064 $this->assertFalse($inputDefinition->hasOption('no-interaction'));1065 $this->assertTrue($inputDefinition->hasOption('custom'));1066 }1067 public function testRunWithDispatcher()1068 {1069 $application = new Application();1070 $application->setAutoExit(false);1071 $application->setDispatcher($this->getDispatcher());1072 $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {1073 $output->write('foo.');1074 });1075 $tester = new ApplicationTester($application);1076 $tester->run(['command' => 'foo']);1077 $this->assertEquals('before.foo.after.'.PHP_EOL, $tester->getDisplay());1078 }1079 /**1080 * @expectedException \LogicException1081 * @expectedExceptionMessage error1082 */1083 public function testRunWithExceptionAndDispatcher()1084 {1085 $application = new Application();1086 $application->setDispatcher($this->getDispatcher());1087 $application->setAutoExit(false);1088 $application->setCatchExceptions(false);1089 $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {1090 throw new \RuntimeException('foo');1091 });1092 $tester = new ApplicationTester($application);1093 $tester->run(['command' => 'foo']);1094 }1095 public function testRunDispatchesAllEventsWithException()1096 {1097 $application = new Application();1098 $application->setDispatcher($this->getDispatcher());1099 $application->setAutoExit(false);1100 $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {1101 $output->write('foo.');1102 throw new \RuntimeException('foo');1103 });1104 $tester = new ApplicationTester($application);1105 $tester->run(['command' => 'foo']);1106 $this->assertContains('before.foo.error.after.', $tester->getDisplay());1107 }1108 public function testRunDispatchesAllEventsWithExceptionInListener()1109 {1110 $dispatcher = $this->getDispatcher();1111 $dispatcher->addListener('console.command', function () {1112 throw new \RuntimeException('foo');1113 });1114 $application = new Application();1115 $application->setDispatcher($dispatcher);1116 $application->setAutoExit(false);1117 $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {1118 $output->write('foo.');1119 });1120 $tester = new ApplicationTester($application);1121 $tester->run(['command' => 'foo']);1122 $this->assertContains('before.error.after.', $tester->getDisplay());1123 }1124 public function testRunWithError()1125 {1126 $application = new Application();1127 $application->setAutoExit(false);1128 $application->setCatchExceptions(false);1129 $application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {1130 $output->write('dym.');1131 throw new \Error('dymerr');1132 });1133 $tester = new ApplicationTester($application);1134 try {1135 $tester->run(['command' => 'dym']);1136 $this->fail('Error expected.');1137 } catch (\Error $e) {1138 $this->assertSame('dymerr', $e->getMessage());1139 }1140 }1141 public function testRunAllowsErrorListenersToSilenceTheException()1142 {1143 $dispatcher = $this->getDispatcher();1144 $dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) {1145 $event->getOutput()->write('silenced.');1146 $event->setExitCode(0);1147 });1148 $dispatcher->addListener('console.command', function () {1149 throw new \RuntimeException('foo');1150 });1151 $application = new Application();1152 $application->setDispatcher($dispatcher);1153 $application->setAutoExit(false);1154 $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {1155 $output->write('foo.');1156 });1157 $tester = new ApplicationTester($application);1158 $tester->run(['command' => 'foo']);1159 $this->assertContains('before.error.silenced.after.', $tester->getDisplay());1160 $this->assertEquals(ConsoleCommandEvent::RETURN_CODE_DISABLED, $tester->getStatusCode());1161 }1162 public function testConsoleErrorEventIsTriggeredOnCommandNotFound()1163 {1164 $dispatcher = new EventDispatcher();1165 $dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) {1166 $this->assertNull($event->getCommand());1167 $this->assertInstanceOf(CommandNotFoundException::class, $event->getError());1168 $event->getOutput()->write('silenced command not found');1169 });1170 $application = new Application();1171 $application->setDispatcher($dispatcher);1172 $application->setAutoExit(false);1173 $tester = new ApplicationTester($application);1174 $tester->run(['command' => 'unknown']);1175 $this->assertContains('silenced command not found', $tester->getDisplay());1176 $this->assertEquals(1, $tester->getStatusCode());1177 }1178 public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent()1179 {1180 $application = new Application();1181 $application->setAutoExit(false);1182 $application->setCatchExceptions(false);1183 $application->setDispatcher(new EventDispatcher());1184 $application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {1185 new \UnknownClass();1186 });1187 $tester = new ApplicationTester($application);1188 try {1189 $tester->run(['command' => 'dym']);1190 $this->fail('->run() should rethrow PHP errors if not handled via ConsoleErrorEvent.');1191 } catch (\Error $e) {1192 $this->assertSame($e->getMessage(), 'Class \'UnknownClass\' not found');1193 }1194 }1195 /**1196 * @expectedException \LogicException1197 * @expectedExceptionMessage error1198 */1199 public function testRunWithErrorAndDispatcher()1200 {1201 $application = new Application();1202 $application->setDispatcher($this->getDispatcher());1203 $application->setAutoExit(false);1204 $application->setCatchExceptions(false);1205 $application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {1206 $output->write('dym.');1207 throw new \Error('dymerr');1208 });1209 $tester = new ApplicationTester($application);1210 $tester->run(['command' => 'dym']);1211 $this->assertContains('before.dym.error.after.', $tester->getDisplay(), 'The PHP Error did not dispached events');1212 }1213 public function testRunDispatchesAllEventsWithError()1214 {1215 $application = new Application();1216 $application->setDispatcher($this->getDispatcher());1217 $application->setAutoExit(false);1218 $application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {1219 $output->write('dym.');1220 throw new \Error('dymerr');1221 });1222 $tester = new ApplicationTester($application);1223 $tester->run(['command' => 'dym']);1224 $this->assertContains('before.dym.error.after.', $tester->getDisplay(), 'The PHP Error did not dispached events');1225 }1226 public function testRunWithErrorFailingStatusCode()1227 {1228 $application = new Application();1229 $application->setDispatcher($this->getDispatcher());1230 $application->setAutoExit(false);1231 $application->register('dus')->setCode(function (InputInterface $input, OutputInterface $output) {1232 $output->write('dus.');1233 throw new \Error('duserr');1234 });1235 $tester = new ApplicationTester($application);1236 $tester->run(['command' => 'dus']);1237 $this->assertSame(1, $tester->getStatusCode(), 'Status code should be 1');1238 }1239 public function testRunWithDispatcherSkippingCommand()1240 {1241 $application = new Application();1242 $application->setDispatcher($this->getDispatcher(true));1243 $application->setAutoExit(false);1244 $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {1245 $output->write('foo.');1246 });1247 $tester = new ApplicationTester($application);1248 $exitCode = $tester->run(['command' => 'foo']);1249 $this->assertContains('before.after.', $tester->getDisplay());1250 $this->assertEquals(ConsoleCommandEvent::RETURN_CODE_DISABLED, $exitCode);1251 }1252 public function testRunWithDispatcherAccessingInputOptions()1253 {1254 $noInteractionValue = null;1255 $quietValue = null;1256 $dispatcher = $this->getDispatcher();1257 $dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) use (&$noInteractionValue, &$quietValue) {1258 $input = $event->getInput();1259 $noInteractionValue = $input->getOption('no-interaction');1260 $quietValue = $input->getOption('quiet');1261 });1262 $application = new Application();1263 $application->setDispatcher($dispatcher);1264 $application->setAutoExit(false);1265 $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {1266 $output->write('foo.');1267 });1268 $tester = new ApplicationTester($application);1269 $tester->run(['command' => 'foo', '--no-interaction' => true]);1270 $this->assertTrue($noInteractionValue);1271 $this->assertFalse($quietValue);1272 }1273 public function testRunWithDispatcherAddingInputOptions()1274 {1275 $extraValue = null;1276 $dispatcher = $this->getDispatcher();1277 $dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) use (&$extraValue) {1278 $definition = $event->getCommand()->getDefinition();1279 $input = $event->getInput();1280 $definition->addOption(new InputOption('extra', null, InputOption::VALUE_REQUIRED));1281 $input->bind($definition);1282 $extraValue = $input->getOption('extra');1283 });1284 $application = new Application();1285 $application->setDispatcher($dispatcher);1286 $application->setAutoExit(false);1287 $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {1288 $output->write('foo.');1289 });1290 $tester = new ApplicationTester($application);1291 $tester->run(['command' => 'foo', '--extra' => 'some test value']);1292 $this->assertEquals('some test value', $extraValue);1293 }1294 public function testSetRunCustomDefaultCommand()1295 {1296 $command = new \FooCommand();1297 $application = new Application();1298 $application->setAutoExit(false);1299 $application->add($command);1300 $application->setDefaultCommand($command->getName());1301 $tester = new ApplicationTester($application);1302 $tester->run([], ['interactive' => false]);1303 $this->assertEquals('called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command');1304 $application = new CustomDefaultCommandApplication();1305 $application->setAutoExit(false);1306 $tester = new ApplicationTester($application);1307 $tester->run([], ['interactive' => false]);1308 $this->assertEquals('called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command');1309 }1310 public function testSetRunCustomDefaultCommandWithOption()1311 {1312 $command = new \FooOptCommand();1313 $application = new Application();1314 $application->setAutoExit(false);1315 $application->add($command);1316 $application->setDefaultCommand($command->getName());1317 $tester = new ApplicationTester($application);1318 $tester->run(['--fooopt' => 'opt'], ['interactive' => false]);1319 $this->assertEquals('called'.PHP_EOL.'opt'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command');1320 }1321 public function testSetRunCustomSingleCommand()1322 {1323 $command = new \FooCommand();1324 $application = new Application();1325 $application->setAutoExit(false);1326 $application->add($command);1327 $application->setDefaultCommand($command->getName(), true);1328 $tester = new ApplicationTester($application);1329 $tester->run([]);1330 $this->assertContains('called', $tester->getDisplay());1331 $tester->run(['--help' => true]);1332 $this->assertContains('The foo:bar command', $tester->getDisplay());1333 }1334 /**1335 * @requires function posix_isatty1336 */1337 public function testCanCheckIfTerminalIsInteractive()1338 {1339 $application = new CustomDefaultCommandApplication();1340 $application->setAutoExit(false);1341 $tester = new ApplicationTester($application);1342 $tester->run(['command' => 'help']);1343 $this->assertFalse($tester->getInput()->hasParameterOption(['--no-interaction', '-n']));1344 $inputStream = $tester->getInput()->getStream();1345 $this->assertEquals($tester->getInput()->isInteractive(), @posix_isatty($inputStream));1346 }1347 public function testRunLazyCommandService()1348 {1349 $container = new ContainerBuilder();1350 $container->addCompilerPass(new AddConsoleCommandPass());1351 $container1352 ->register('lazy-command', LazyCommand::class)1353 ->addTag('console.command', ['command' => 'lazy:command'])1354 ->addTag('console.command', ['command' => 'lazy:alias'])1355 ->addTag('console.command', ['command' => 'lazy:alias2']);1356 $container->compile();1357 $application = new Application();1358 $application->setCommandLoader($container->get('console.command_loader'));1359 $application->setAutoExit(false);1360 $tester = new ApplicationTester($application);1361 $tester->run(['command' => 'lazy:command']);1362 $this->assertSame("lazy-command called\n", $tester->getDisplay(true));1363 $tester->run(['command' => 'lazy:alias']);1364 $this->assertSame("lazy-command called\n", $tester->getDisplay(true));1365 $tester->run(['command' => 'lazy:alias2']);1366 $this->assertSame("lazy-command called\n", $tester->getDisplay(true));1367 $command = $application->get('lazy:command');1368 $this->assertSame(['lazy:alias', 'lazy:alias2'], $command->getAliases());1369 }1370 /**1371 * @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException1372 */1373 public function testGetDisabledLazyCommand()1374 {1375 $application = new Application();1376 $application->setCommandLoader(new FactoryCommandLoader(['disabled' => function () { return new DisabledCommand(); }]));1377 $application->get('disabled');1378 }1379 public function testHasReturnsFalseForDisabledLazyCommand()1380 {1381 $application = new Application();1382 $application->setCommandLoader(new FactoryCommandLoader(['disabled' => function () { return new DisabledCommand(); }]));1383 $this->assertFalse($application->has('disabled'));1384 }1385 public function testAllExcludesDisabledLazyCommand()1386 {1387 $application = new Application();1388 $application->setCommandLoader(new FactoryCommandLoader(['disabled' => function () { return new DisabledCommand(); }]));1389 $this->assertArrayNotHasKey('disabled', $application->all());1390 }1391 protected function getDispatcher($skipCommand = false)1392 {1393 $dispatcher = new EventDispatcher();1394 $dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) use ($skipCommand) {1395 $event->getOutput()->write('before.');1396 if ($skipCommand) {1397 $event->disableCommand();1398 }1399 });1400 $dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use ($skipCommand) {1401 $event->getOutput()->writeln('after.');1402 if (!$skipCommand) {1403 $event->setExitCode(ConsoleCommandEvent::RETURN_CODE_DISABLED);1404 }1405 });1406 $dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) {1407 $event->getOutput()->write('error.');1408 $event->setError(new \LogicException('error.', $event->getExitCode(), $event->getError()));1409 });1410 return $dispatcher;1411 }1412 public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEnabled()1413 {1414 $application = new Application();1415 $application->setAutoExit(false);1416 $application->setDispatcher(new EventDispatcher());1417 $application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {1418 new \UnknownClass();1419 });1420 $tester = new ApplicationTester($application);1421 try {1422 $tester->run(['command' => 'dym']);1423 $this->fail('->run() should rethrow PHP errors if not handled via ConsoleErrorEvent.');1424 } catch (\Error $e) {1425 $this->assertSame($e->getMessage(), 'Class \'UnknownClass\' not found');1426 }1427 }1428 /**1429 * @expectedException \RuntimeException1430 * @expectedExceptionMessage foo1431 */1432 public function testThrowingErrorListener()1433 {1434 $dispatcher = $this->getDispatcher();1435 $dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) {1436 throw new \RuntimeException('foo');1437 });1438 $dispatcher->addListener('console.command', function () {1439 throw new \RuntimeException('bar');1440 });1441 $application = new Application();1442 $application->setDispatcher($dispatcher);1443 $application->setAutoExit(false);1444 $application->setCatchExceptions(false);1445 $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {1446 $output->write('foo.');1447 });1448 $tester = new ApplicationTester($application);1449 $tester->run(['command' => 'foo']);1450 }1451}1452class CustomApplication extends Application1453{...
manager.php
Source:manager.php
...179 }180 return $endpoint;181 }182 /**183 * Run server.184 *185 * Init WordPress reset api.186 *187 * @return \WP_REST_Server188 */189 public function run_server() {190 /**191 * If run_server() called means, that rest api is simulated from the backend.192 */193 $this->is_internal = true;194 if ( ! $this->server ) {195 // Remove all 'rest_api_init' actions.196 remove_all_actions( 'rest_api_init' );197 // Call custom reset api loader.198 do_action( 'elementor_rest_api_before_init' );199 $this->server = rest_get_server(); // Init API.200 }201 return $this->server;202 }203 /**204 * Kill server.205 *206 * Free server and controllers.207 */208 public function kill_server() {209 global $wp_rest_server;210 $this->controllers = [];211 $this->command_formats = [];212 $this->server = false;213 $this->is_internal = false;214 $this->cache = [];215 $wp_rest_server = false;216 }217 /**218 * Run processor.219 *220 * @param \Elementor\Data\Base\Processor $processor221 * @param array $data222 *223 * @return mixed224 */225 public function run_processor( $processor, $data ) {226 if ( call_user_func_array( [ $processor, 'get_conditions' ], $data ) ) {227 return call_user_func_array( [ $processor, 'apply' ], $data );228 }229 return null;230 }231 /**232 * Run processors.233 *234 * Filter them by class.235 *236 * @param \Elementor\Data\Base\Processor[] $processors237 * @param string $filter_by_class238 * @param array $data239 *240 * @return false|array241 */242 public function run_processors( $processors, $filter_by_class, $data ) {243 foreach ( $processors as $processor ) {244 if ( $processor instanceof $filter_by_class ) {245 if ( Processor\Before::class === $filter_by_class ) {246 $this->run_processor( $processor, $data );247 } elseif ( Processor\After::class === $filter_by_class ) {248 $result = $this->run_processor( $processor, $data );249 if ( $result ) {250 $data[1] = $result;251 }252 } else {253 // TODO: error254 break;255 }256 }257 }258 return isset( $data[1] ) ? $data[1] : false;259 }260 /**261 * Run request.262 *263 * Simulate rest API from within the backend.264 * Use args as query.265 *266 * @param string $endpoint267 * @param array $args268 * @param string $method269 *270 * @return \WP_REST_Response271 */272 private function run_request( $endpoint, $args, $method ) {273 $this->run_server();274 $endpoint = '/' . self::ROOT_NAMESPACE . '/v' . self::VERSION . '/' . $endpoint;275 // Run reset api.276 $request = new \WP_REST_Request( $method, $endpoint );277 if ( 'GET' === $method ) {278 $request->set_query_params( $args );279 } else {280 $request->set_body_params( $args );281 }282 return rest_do_request( $request );283 }284 /**285 * Run endpoint.286 *287 * Wrapper for `$this->run_request` return `$response->getData()` instead of `$response`.288 *289 * @param string $endpoint290 * @param array $args291 * @param string $method292 *293 * @return array294 */295 public function run_endpoint( $endpoint, $args = [], $method = 'GET' ) {296 $response = $this->run_request( $endpoint, $args, $method );297 return $response->get_data();298 }299 /**300 * Run ( simulated reset api ).301 *302 * Do:303 * Init reset server.304 * Run before processors.305 * Run command as reset api endpoint from internal.306 * Run after processors.307 *308 * @param string $command309 * @param array $args310 * @param string $method311 *312 * @return array|false processed result313 */314 public function run( $command, $args = [], $method = 'GET' ) {315 $key = crc32( $command . '-' . wp_json_encode( $args ) . '-' . $method );316 $cache = $this->get_cache( $key );317 if ( $cache ) {318 return $cache;319 }320 $this->run_server();...
args_test.go
Source:args_test.go
...3 "strings"4 "testing"5)6func TestNoArgs(t *testing.T) {7 c := &Command{Use: "c", Args: NoArgs, Run: emptyRun}8 output, err := executeCommand(c)9 if output != "" {10 t.Errorf("Unexpected string: %v", output)11 }12 if err != nil {13 t.Fatalf("Unexpected error: %v", err)14 }15}16func TestNoArgsWithArgs(t *testing.T) {17 c := &Command{Use: "c", Args: NoArgs, Run: emptyRun}18 _, err := executeCommand(c, "illegal")19 if err == nil {20 t.Fatal("Expected an error")21 }22 got := err.Error()23 expected := `unknown command "illegal" for "c"`24 if got != expected {25 t.Errorf("Expected: %q, got: %q", expected, got)26 }27}28func TestOnlyValidArgs(t *testing.T) {29 c := &Command{30 Use: "c",31 Args: OnlyValidArgs,32 ValidArgs: []string{"one", "two"},33 Run: emptyRun,34 }35 output, err := executeCommand(c, "one", "two")36 if output != "" {37 t.Errorf("Unexpected output: %v", output)38 }39 if err != nil {40 t.Fatalf("Unexpected error: %v", err)41 }42}43func TestOnlyValidArgsWithInvalidArgs(t *testing.T) {44 c := &Command{45 Use: "c",46 Args: OnlyValidArgs,47 ValidArgs: []string{"one", "two"},48 Run: emptyRun,49 }50 _, err := executeCommand(c, "three")51 if err == nil {52 t.Fatal("Expected an error")53 }54 got := err.Error()55 expected := `invalid argument "three" for "c"`56 if got != expected {57 t.Errorf("Expected: %q, got: %q", expected, got)58 }59}60func TestArbitraryArgs(t *testing.T) {61 c := &Command{Use: "c", Args: ArbitraryArgs, Run: emptyRun}62 output, err := executeCommand(c, "a", "b")63 if output != "" {64 t.Errorf("Unexpected output: %v", output)65 }66 if err != nil {67 t.Errorf("Unexpected error: %v", err)68 }69}70func TestMinimumNArgs(t *testing.T) {71 c := &Command{Use: "c", Args: MinimumNArgs(2), Run: emptyRun}72 output, err := executeCommand(c, "a", "b", "c")73 if output != "" {74 t.Errorf("Unexpected output: %v", output)75 }76 if err != nil {77 t.Errorf("Unexpected error: %v", err)78 }79}80func TestMinimumNArgsWithLessArgs(t *testing.T) {81 c := &Command{Use: "c", Args: MinimumNArgs(2), Run: emptyRun}82 _, err := executeCommand(c, "a")83 if err == nil {84 t.Fatal("Expected an error")85 }86 got := err.Error()87 expected := "requires at least 2 arg(s), only received 1"88 if got != expected {89 t.Fatalf("Expected %q, got %q", expected, got)90 }91}92func TestMaximumNArgs(t *testing.T) {93 c := &Command{Use: "c", Args: MaximumNArgs(3), Run: emptyRun}94 output, err := executeCommand(c, "a", "b")95 if output != "" {96 t.Errorf("Unexpected output: %v", output)97 }98 if err != nil {99 t.Errorf("Unexpected error: %v", err)100 }101}102func TestMaximumNArgsWithMoreArgs(t *testing.T) {103 c := &Command{Use: "c", Args: MaximumNArgs(2), Run: emptyRun}104 _, err := executeCommand(c, "a", "b", "c")105 if err == nil {106 t.Fatal("Expected an error")107 }108 got := err.Error()109 expected := "accepts at most 2 arg(s), received 3"110 if got != expected {111 t.Fatalf("Expected %q, got %q", expected, got)112 }113}114func TestExactArgs(t *testing.T) {115 c := &Command{Use: "c", Args: ExactArgs(3), Run: emptyRun}116 output, err := executeCommand(c, "a", "b", "c")117 if output != "" {118 t.Errorf("Unexpected output: %v", output)119 }120 if err != nil {121 t.Errorf("Unexpected error: %v", err)122 }123}124func TestExactArgsWithInvalidCount(t *testing.T) {125 c := &Command{Use: "c", Args: ExactArgs(2), Run: emptyRun}126 _, err := executeCommand(c, "a", "b", "c")127 if err == nil {128 t.Fatal("Expected an error")129 }130 got := err.Error()131 expected := "accepts 2 arg(s), received 3"132 if got != expected {133 t.Fatalf("Expected %q, got %q", expected, got)134 }135}136func TestExactValidArgs(t *testing.T) {137 c := &Command{Use: "c", Args: ExactValidArgs(3), ValidArgs: []string{"a", "b", "c"}, Run: emptyRun}138 output, err := executeCommand(c, "a", "b", "c")139 if output != "" {140 t.Errorf("Unexpected output: %v", output)141 }142 if err != nil {143 t.Errorf("Unexpected error: %v", err)144 }145}146func TestExactValidArgsWithInvalidCount(t *testing.T) {147 c := &Command{Use: "c", Args: ExactValidArgs(2), Run: emptyRun}148 _, err := executeCommand(c, "a", "b", "c")149 if err == nil {150 t.Fatal("Expected an error")151 }152 got := err.Error()153 expected := "accepts 2 arg(s), received 3"154 if got != expected {155 t.Fatalf("Expected %q, got %q", expected, got)156 }157}158func TestExactValidArgsWithInvalidArgs(t *testing.T) {159 c := &Command{160 Use: "c",161 Args: ExactValidArgs(1),162 ValidArgs: []string{"one", "two"},163 Run: emptyRun,164 }165 _, err := executeCommand(c, "three")166 if err == nil {167 t.Fatal("Expected an error")168 }169 got := err.Error()170 expected := `invalid argument "three" for "c"`171 if got != expected {172 t.Errorf("Expected: %q, got: %q", expected, got)173 }174}175func TestRangeArgs(t *testing.T) {176 c := &Command{Use: "c", Args: RangeArgs(2, 4), Run: emptyRun}177 output, err := executeCommand(c, "a", "b", "c")178 if output != "" {179 t.Errorf("Unexpected output: %v", output)180 }181 if err != nil {182 t.Errorf("Unexpected error: %v", err)183 }184}185func TestRangeArgsWithInvalidCount(t *testing.T) {186 c := &Command{Use: "c", Args: RangeArgs(2, 4), Run: emptyRun}187 _, err := executeCommand(c, "a")188 if err == nil {189 t.Fatal("Expected an error")190 }191 got := err.Error()192 expected := "accepts between 2 and 4 arg(s), received 1"193 if got != expected {194 t.Fatalf("Expected %q, got %q", expected, got)195 }196}197func TestRootTakesNoArgs(t *testing.T) {198 rootCmd := &Command{Use: "root", Run: emptyRun}199 childCmd := &Command{Use: "child", Run: emptyRun}200 rootCmd.AddCommand(childCmd)201 _, err := executeCommand(rootCmd, "illegal", "args")202 if err == nil {203 t.Fatal("Expected an error")204 }205 got := err.Error()206 expected := `unknown command "illegal" for "root"`207 if !strings.Contains(got, expected) {208 t.Errorf("expected %q, got %q", expected, got)209 }210}211func TestRootTakesArgs(t *testing.T) {212 rootCmd := &Command{Use: "root", Args: ArbitraryArgs, Run: emptyRun}213 childCmd := &Command{Use: "child", Run: emptyRun}214 rootCmd.AddCommand(childCmd)215 _, err := executeCommand(rootCmd, "legal", "args")216 if err != nil {217 t.Errorf("Unexpected error: %v", err)218 }219}220func TestChildTakesNoArgs(t *testing.T) {221 rootCmd := &Command{Use: "root", Run: emptyRun}222 childCmd := &Command{Use: "child", Args: NoArgs, Run: emptyRun}223 rootCmd.AddCommand(childCmd)224 _, err := executeCommand(rootCmd, "child", "illegal", "args")225 if err == nil {226 t.Fatal("Expected an error")227 }228 got := err.Error()229 expected := `unknown command "illegal" for "root child"`230 if !strings.Contains(got, expected) {231 t.Errorf("expected %q, got %q", expected, got)232 }233}234func TestChildTakesArgs(t *testing.T) {235 rootCmd := &Command{Use: "root", Run: emptyRun}236 childCmd := &Command{Use: "child", Args: ArbitraryArgs, Run: emptyRun}237 rootCmd.AddCommand(childCmd)238 _, err := executeCommand(rootCmd, "child", "legal", "args")239 if err != nil {240 t.Fatalf("Unexpected error: %v", err)241 }242}...
command_test.go
Source:command_test.go
...3 "testing"4)5func TestCommand(t *testing.T) {6 c := &Command{}7 t.Run("Run NewCommand()", func(t *testing.T) {8 c = NewCommand("test", "test description")9 })10 t.Run("Run setParentCommandPath()", func(t *testing.T) {11 c.setParentCommandPath("path")12 })13 t.Run("Run setApp()", func(t *testing.T) {14 c.setApp(&Cli{})15 })16 t.Run("Run parseFlags()", func(t *testing.T) {17 _, err := c.parseFlags([]string{"test", "flags"})18 t.Log(err)19 })20 t.Run("Run run()", func(t *testing.T) {21 cl := NewCli("test", "description", "0")22 cl.rootCommand.run([]string{"test"})23 cl.rootCommand.subCommandsMap["test"] = &Command{24 name: "subcom",25 shortdescription: "short description",26 hidden: false,27 app: cl,28 }29 cl.rootCommand.run([]string{"test"})30 cl.rootCommand.run([]string{"---"})31 cl.rootCommand.run([]string{"-help"})32 // cl.rootCommand.actionCallback = func() error {33 // println("Hello World!")34 // return nil35 // }36 // cl.rootCommand.run([]string{"test"})37 cl.rootCommand.app.defaultCommand = &Command{38 name: "subcom",39 shortdescription: "short description",40 hidden: false,41 app: cl,42 }43 cl.rootCommand.run([]string{"test"})44 })45 t.Run("Run Action()", func(t *testing.T) {46 c.Action(func() error { return nil })47 })48 t.Run("Run PrintHelp()", func(t *testing.T) {49 cl := NewCli("test", "description", "0")50 // co.shortdescription = ""51 cl.PrintHelp()52 cl.rootCommand.shortdescription = "test"53 cl.PrintHelp()54 cl.rootCommand.commandPath = "notTest"55 cl.PrintHelp()56 cl.rootCommand.longdescription = ""57 cl.PrintHelp()58 cl.rootCommand.longdescription = "test"59 cl.PrintHelp()60 mockCommand := &Command{61 name: "test",62 shortdescription: "short description",63 hidden: true,64 longestSubcommand: len("test"),65 }66 cl.rootCommand.subCommands = append(cl.rootCommand.subCommands, mockCommand)67 cl.PrintHelp()68 mockCommand = &Command{69 name: "subcom",70 shortdescription: "short description",71 hidden: false,72 app: cl,73 }74 cl.rootCommand.longestSubcommand = 1075 cl.rootCommand.subCommands = append(cl.rootCommand.subCommands, mockCommand)76 cl.PrintHelp()77 mockCommand = &Command{78 name: "subcom",79 shortdescription: "short description",80 hidden: false,81 app: cl,82 }83 cl.rootCommand.longestSubcommand = 1084 cl.defaultCommand = mockCommand85 cl.rootCommand.subCommands = append(cl.rootCommand.subCommands, mockCommand)86 cl.PrintHelp()87 cl.rootCommand.flagCount = 388 cl.PrintHelp()89 })90 t.Run("Run isDefaultCommand()", func(t *testing.T) {91 c.isDefaultCommand()92 })93 t.Run("Run isHidden()", func(t *testing.T) {94 c.isHidden()95 })96 t.Run("Run Hidden()", func(t *testing.T) {97 c.Hidden()98 })99 t.Run("Run NewSubCommand()", func(t *testing.T) {100 c.NewSubCommand("name", "description")101 })102 t.Run("Run AddCommand()", func(t *testing.T) {103 c.AddCommand(c)104 })105 t.Run("Run StringFlag()", func(t *testing.T) {106 var variable = "variable"107 c.StringFlag("name", "description", &variable)108 })109 t.Run("Run IntFlag()", func(t *testing.T) {110 var variable int111 c.IntFlag("test", "description", &variable)112 })113 t.Run("Run LongDescription()", func(t *testing.T) {114 c.LongDescription("name")115 })116}...
Run
Using AI Code Generation
1import (2func main() {3 cmd := exec.Command("ls", "-l")4 out, err := cmd.Output()5 if err != nil {6 fmt.Println(err)7 }8 fmt.Println(string(out))9}10import (11func main() {12 cmd := exec.Command("ls", "-l")13 err := cmd.Run()14 if err != nil {15 fmt.Println(err)16 }17}18import (19func main() {20 cmd := exec.Command("ls", "-l")21 out, err := cmd.CombinedOutput()22 if err != nil {23 fmt.Println(err)24 }25 fmt.Println(string(out))26}27import (28func main() {29 cmd := exec.Command("ls", "-l")30 out, err := cmd.Output()31 if err != nil {32 fmt.Println(err)33 }34 fmt.Println(string(out))35}
Run
Using AI Code Generation
1import (2func main() {3 cmd := exec.Command("echo", "hello world")4 out, err := cmd.Output()5 if err != nil {6 fmt.Println(err)7 }8 fmt.Println(string(out))9}10import (11func main() {12 cmd := exec.Command("ls", "-l")13 err := cmd.Run()14 if err != nil {15 fmt.Println(err)16 }17}18import (19func main() {20 cmd := exec.Command("ls", "-l")21 out, err := cmd.CombinedOutput()22 if err != nil {23 fmt.Println(err)24 }25 fmt.Println(string(out))26}
Run
Using AI Code Generation
1import (2func main() {3 cmd := exec.Command("ls", "-la")4 err := cmd.Run()5 if err != nil {6 fmt.Println(err)7 }8}9import (10func main() {11 cmd := exec.Command("ls", "-la")12 output, err := cmd.Output()13 if err != nil {14 fmt.Println(err)15 os.Exit(1)16 }17 fmt.Println(string(output))18}19import (20func main() {21 cmd := exec.Command("ls", "-la")22 err := cmd.Start()23 if err != nil {24 fmt.Println(err)25 os.Exit(1)26 }27 fmt.Println("Waiting for command to finish...")28 err = cmd.Wait()29 if err != nil {30 fmt.Println(err)31 os.Exit(1)32 }33 fmt.Println("Command finished successfully")34}35import (36func main() {37 cmd := exec.Command("ls", "-la")38 output, err := cmd.CombinedOutput()39 if err != nil {40 fmt.Println(err)41 os.Exit(1)42 }43 fmt.Println(string(output))44}45import (46func main() {47 path, err := exec.LookPath("ls")48 if err != nil {49 fmt.Println(err)50 os.Exit(1)51 }52 fmt.Println(path)53}54import (55func main() {56 ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)57 defer cancel()58 cmd := exec.CommandContext(ctx, "sleep", "5")59 err := cmd.Run()60 fmt.Println(err)61}
Run
Using AI Code Generation
1import (2func main() {3 cmd := exec.Command("ls", "-l")4 out, err := cmd.Output()5 if err != nil {6 fmt.Println(err)7 }8 fmt.Println(string(out))9}
Run
Using AI Code Generation
1import (2func main() {3 cmd := exec.Command("/bin/ls")4 err := cmd.Run()5 if err != nil {6 fmt.Println(err)7 }8}9import (10func main() {11 cmd := exec.Command("/bin/ls")12 out, err := cmd.Output()13 if err != nil {14 fmt.Println(err)15 }16 fmt.Println(string(out))17}18import (19func main() {20 cmd := exec.Command("/bin/ls")21 out, err := cmd.CombinedOutput()22 if err != nil {23 fmt.Println(err)24 }25 fmt.Println(string(out))26}27import (28func main() {29 cmd := exec.Command("/bin/ls")30 err := cmd.Start()31 if err != nil {32 fmt.Println(err)33 }34}35import (36func main() {37 cmd := exec.Command("/bin/ls")38 err := cmd.Wait()39 if err != nil {40 fmt.Println(err)41 }42}43import (44func main() {45 cmd := exec.Command("/bin/ls")46 out, err := cmd.StdoutPipe()47 if err != nil {48 fmt.Println(err)49 }50 err = cmd.Start()51 if err != nil {52 fmt.Println(err)53 }54 buf := make([]byte, 1024)55 for {56 n, err := out.Read(buf)57 if err != nil && err != io.EOF {58 fmt.Println(err)59 }60 if n == 0 {61 }62 fmt.Println(string(buf[:n]))63 }64}
Run
Using AI Code Generation
1import (2func main() {3 cmd := exec.Command("cmd", "/c", "echo", "hello")4 err := cmd.Run()5 if err != nil {6 log.Fatal(err)7 }8}9import (10func main() {11 cmd := exec.Command("cmd", "/c", "echo", "hello")12 output, err := cmd.Output()13 if err != nil {14 log.Fatal(err)15 }16 println(string(output))17}18import (19func main() {20 cmd := exec.Command("cmd", "/c", "echo", "hello")21 output, err := cmd.CombinedOutput()22 if err != nil {23 log.Fatal(err)24 }25 println(string(output))26}27import (28func main() {29 cmd := exec.Command("cmd", "/c", "echo", "hello")30 err := cmd.Start()31 if err != nil {32 log.Fatal(err)33 }34}35import (36func main() {37 cmd := exec.Command("cmd", "/c", "echo", "hello")38 stdin, err := cmd.StdinPipe()39 if err != nil {40 log.Fatal(err)41 }42 err = cmd.Start()43 if err != nil {44 log.Fatal(err)45 }46 stdin.Write([]byte("hello"))47}48import (49func main() {50 cmd := exec.Command("cmd", "/c", "echo", "hello")51 stdout, err := cmd.StdoutPipe()52 if err != nil {53 log.Fatal(err)54 }55 err = cmd.Start()56 if err != nil {57 log.Fatal(err)58 }59 buf := make([]byte, 1024)60 n, err := stdout.Read(buf)61 if err != nil {62 log.Fatal(err)63 }64 println(string(buf[:n]))65}
Run
Using AI Code Generation
1import (2func main() {3 cmd := exec.Command("ls")4 out, err := cmd.Output()5 fmt.Println(out, err)6}7import (8func main() {9 cmd := exec.Command("ls")10 out, err := cmd.CombinedOutput()11 fmt.Println(string(out), err)12}
Run
Using AI Code Generation
1import (2func main() {3 cmd := exec.Command("ls", "-la")4 output, err := cmd.Output()5 fmt.Println(string(output))6 if err != nil {7 log.Fatal(err)8 }9}10import (11func main() {12 cmd := exec.Command("ls", "-la")13 output, err := cmd.CombinedOutput()14 fmt.Println(string(output))15 if err != nil {16 log.Fatal(err)17 }18}
Run
Using AI Code Generation
1func main() {2 cmd := exec.Command("ls", "-la")3 output, err := cmd.Output()4 if err != nil {5 fmt.Println(err.Error())6 }7 fmt.Println(string(output))8}9func main() {10 cmd := exec.Command("ls", "-la")11 output, err := cmd.CombinedOutput()12 if err != nil {13 fmt.Println(err.Error())14 }15 fmt.Println(string(output))16}17func main() {18 cmd := exec.Command("ls", "-la")19 output, err := cmd.CombinedOutput()20 if err != nil {21 fmt.Println(err.Error())22 }23 fmt.Println(string(output))24}25func main() {26 cmd := exec.Command("ls", "-la")27 output, err := cmd.CombinedOutput()28 if err != nil {29 fmt.Println(err.Error())30 }31 fmt.Println(string(output))32}33func main() {34 cmd := exec.Command("ls", "-la")35 output, err := cmd.CombinedOutput()36 if err != nil {37 fmt.Println(err.Error())38 }39 fmt.Println(string(output
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!