Exemple #1
1
 public function testFormattedOutput()
 {
     $today = new \DateTimeImmutable();
     // Show 1 has an upcoming episode.
     for ($i = 1; $i <= 3; $i++) {
         $serie = $this->getMockBuilder('Moinax\\TvDb\\Serie')->disableOriginalConstructor()->getMock();
         $serie->id = 1;
         $serie->name = "Serie {$i}";
         $series[] = $serie;
     }
     $show_1 = [$this->getEpisode('S1E1', $today->modify("-7 days")), $this->getEpisode('S1E2', $today->modify('+7 days'))];
     // Show 2 only has episodes in the past.
     $show_2 = [$this->getEpisode('S2E1', $today->modify("-21 days")), $this->getEpisode('S2E2', $today->modify('-14 days'))];
     // Show 3 has an episode coming out today.
     $show_3 = [$this->getEpisode('S3E1', $today->modify("-7 days")), $this->getEpisode('S3E2', $today)];
     $episodes = [['episodes' => $show_1], ['episodes' => $show_2], ['episodes' => $show_3]];
     $shows = ['show1' => 'imdb1', 'show2' => 'imdb2', 'show3' => 'imdb3'];
     $application = new Application();
     $application->add($this->getCommand($series, $episodes, $shows));
     $command = $application->find('status');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName()], ['decorated' => TRUE]);
     //    $this->assertEquals('', $commandTester->getDisplay());
     //    $this->assertTrue(stripos($commandTester->getDisplay(), 'red') !== FALSE);
     $a = $commandTester->getDisplay();
     $b = $commandTester->getOutput();
 }
 public function setUp()
 {
     parent::setUp();
     $this->application = new Application();
     $this->application->add(new \DaemonCommandStub($this->commandName));
     $this->command = $this->application->find($this->commandName);
     $this->tester = new CommandTester($this->command);
     $this->command->setOutputCallback(function () {
         return $this->tester->getOutput();
     });
 }
 /**
  * @param string $expected
  * @param string $format
  * @param bool   $isDecorated
  *
  * @dataProvider provideDiffReporting
  */
 public function testDiffReportingDecorated($expected, $format, $isDecorated)
 {
     $command = new FixCommand();
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('path' => array(__DIR__ . '/Fixtures/FixCommand/TextDiffTestInput.php'), '--diff' => true, '--dry-run' => true, '--format' => $format, '--rules' => 'concat_without_spaces', '--using-cache' => 'no'), array('decorated' => $isDecorated, 'verbosity' => OutputInterface::VERBOSITY_NORMAL));
     if ($isDecorated !== $commandTester->getOutput()->isDecorated()) {
         $this->markTestSkipped(sprintf('Output should %sbe decorated.', $isDecorated ? '' : 'not '));
     }
     if ($isDecorated !== $commandTester->getOutput()->getFormatter()->isDecorated()) {
         $this->markTestSkipped(sprintf('Formatter should %sbe decorated.', $isDecorated ? '' : 'not '));
     }
     $this->assertStringMatchesFormat($expected, $commandTester->getDisplay(false));
 }
 /**
  * Returns the output for the tester.
  *
  * @param CommandTester $tester The tester.
  *
  * @return string The output.
  */
 protected function getOutput(CommandTester $tester)
 {
     /** @var $output StreamOutput */
     $output = $tester->getOutput();
     $stream = $output->getStream();
     $string = '';
     rewind($stream);
     while (false === feof($stream)) {
         $string .= fgets($stream);
     }
     $string = preg_replace(array('/\\x1b(\\[|\\(|\\))[;?0-9]*[0-9A-Za-z]/', '/[\\x03|\\x1a]/'), array('', '', ''), $string);
     return str_replace(PHP_EOL, "\n", $string);
 }
 public function testQuietStatus()
 {
     $cmd = $this->app->find('metadata:status');
     $tester = new CommandTester($cmd);
     $ret = $tester->execute(array('command' => $cmd->getName(), '--path' => __DIR__ . '/metadata/fake_sugar', '--metadata-file' => $this->getYamlFilename(MetadataTestCase::METADATA_NEW), '--quiet' => null));
     $this->assertEquals(2, $ret);
     // Test empty write*
     $func_names = array('writeAdd', 'writeDel', 'writeUpdate');
     $output = $tester->getOutput();
     $reflex = new \ReflectionClass($cmd);
     foreach ($func_names as $func_name) {
         $method = $reflex->getMethod($func_name);
         $method->setAccessible(true);
         $this->assertNull($method->invoke($cmd, $output, array()));
     }
 }
Exemple #6
0
 /**
  * @test
  */
 public function shouldWriteCommitAndPushInfoWithVerbosityVerbose()
 {
     $gitDriver = $this->getMockBuilder('AOE\\Tagging\\Vcs\\Driver\\GitDriver')->disableOriginalConstructor()->setMethods(array('getLatestTag', 'tag', 'hasChangesSinceTag', 'commit'))->getMock();
     $gitDriver->expects($this->once())->method('hasChangesSinceTag')->will($this->returnValue(true));
     $gitDriver->expects($this->once())->method('getLatestTag')->will($this->returnValue('2.7.3'));
     $gitDriver->expects($this->once())->method('commit')->with(array('myfile.ext'), '/home/foo/bar', 'my message for commit');
     $gitCommand = $this->getMockBuilder('AOE\\Tagging\\Command\\GitCommand')->setMethods(array('getDriver'))->getMock();
     $gitCommand->expects($this->once())->method('getDriver')->will($this->returnValue($gitDriver));
     /** @var GitCommand $gitCommand */
     $application = new Application();
     $application->add($gitCommand);
     $command = $application->find('git');
     $commandTester = new CommandTester($command);
     $test = $commandTester->getOutput();
     $commandTester->execute(array('command' => $command->getName(), 'url' => 'git@git.test.test/foo/bar', 'path' => '/home/foo/bar', '--commit-and-push' => array('myfile.ext'), '--message' => 'my message for commit'), ['verbosity' => 2]);
 }
Exemple #7
0
 /**
  * @covers ::configure
  * @covers ::execute
  */
 public function testExecute()
 {
     $mock = $this->getMockBuilder('MaartenStaa\\PHPTA\\CLI\\Command')->setMethods(array('getConfiguration', 'bootstrap', 'resolveTargets', 'createProject'))->getMock();
     $config = new Configuration();
     $mock->expects($this->once())->method('getConfiguration')->will($this->returnValue($config));
     $mock->expects($this->once())->method('bootstrap')->with($config);
     $mock->expects($this->once())->method('resolveTargets')->with($config)->will($this->returnValue(array('foo')));
     $project = $this->getMockBuilder('MaartenStaa\\PHPTA\\Processors\\Project')->setMethods(array('process'))->setConstructorArgs(array(array(), array(), false))->getMock();
     $mock->expects($this->once())->method('createProject')->with($config)->will($this->returnValue($project));
     $project->expects($this->once())->method('process')->with($this->equalTo(array('foo')), $this->isInstanceOf('Symfony\\Component\\Console\\Output\\StreamOutput'));
     $application = new Application('PHPTA', 'v1.2.34');
     $application->add($mock);
     $command = $application->find('phpta');
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName()));
     $this->assertEquals('PHPTA version v1.2.34 by Maarten Staa.' . PHP_EOL . PHP_EOL, $this->getDisplay($commandTester->getOutput()));
 }