Last active
December 20, 2015 12:18
-
-
Save wouterj/6129648 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "require": { | |
| "symfony/console": "2.3.*" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Symfony\Component\Console\Command\Command; | |
| use Symfony\Component\Console\Input\InputOption; | |
| use Symfony\Component\Console\Input\InputInterface; | |
| use Symfony\Component\Console\Output\OutputInterface; | |
| class MyCommand extends Command | |
| { | |
| public function configure() | |
| { | |
| $this | |
| ->setName('acme:foo') | |
| ->setDescription('Foobar') | |
| ->addOption('bar', null, InputOption::VALUE_NONE); | |
| } | |
| public function execute(InputInterface $i, OutputInterface $o) | |
| { | |
| if ($i->getOption('bar')) { | |
| $o->writeln('BAR'); | |
| } else { | |
| $o->writeln('FOO'); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once __DIR__.'/vendor/autoload.php'; | |
| require_once __DIR__.'/MyCommand.php'; | |
| use Symfony\Component\Console\Application; | |
| use Symfony\Component\Console\Tester\CommandTester; | |
| class MyCommandTest extends \PHPUnit_Framework_TestCase | |
| { | |
| public function testExecute() | |
| { | |
| $application = new Application(); | |
| $application->add(new MyCommand()); | |
| $command = $application->find('acme:foo'); | |
| $commandTester = new CommandTester($command); | |
| $commandTester->execute( | |
| array( | |
| '--bar' => true, | |
| // 'command' => 'acme:foo', | |
| ) | |
| ); | |
| $this->assertRegExp('{BAR}', $commandTester->getDisplay()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment