writeln() public method

public writeln ( string $message = '', integer | null $indent = null )
$message string
$indent integer | null
 /**
  * @param Resource $resource
  * @param array             $data
  */
 public function generate(Resource $resource, array $data = array())
 {
     $filepath = $resource->getSrcFilename();
     $methodName = $data['name'];
     $arguments = $data['arguments'];
     $content = $this->getContent($resource, $methodName, $arguments);
     $code = $this->appendMethodToCode($this->filesystem->getFileContents($filepath), $content);
     $this->filesystem->putFileContents($filepath, $code);
     $this->io->writeln(sprintf("<info>Method <value>%s::%s()</value> has been created.</info>\n", $resource->getSrcClassname(), $methodName), 2);
 }
 /**
  * @param Resource $resource
  * @param array $data
  */
 public function generate(Resource $resource, array $data)
 {
     $filepath = $resource->getSrcFilename();
     if (!($content = $this->templates->render('private-constructor', array()))) {
         $content = $this->templates->renderString($this->getTemplate(), array());
     }
     $code = $this->filesystem->getFileContents($filepath);
     $code = $this->codeWriter->insertMethodFirstInClass($code, $content);
     $this->filesystem->putFileContents($filepath, $code);
     $this->io->writeln("<info>Private constructor has been created.</info>\n", 2);
 }
 /**
  * @param Resource $resource
  * @param array             $data
  */
 public function generate(Resource $resource, array $data = array())
 {
     $filepath = $resource->getSrcFilename();
     $name = $data['name'];
     $arguments = $data['arguments'];
     $argString = $this->buildArgumentString($arguments);
     $values = array('%name%' => $name, '%arguments%' => $argString);
     if (!($content = $this->templates->render('interface-method-signature', $values))) {
         $content = $this->templates->renderString($this->getTemplate(), $values);
     }
     $this->insertMethodSignature($filepath, $content);
     $this->io->writeln(sprintf("<info>Method signature <value>%s::%s()</value> has been created.</info>\n", $resource->getSrcClassname(), $name), 2);
 }
Example #4
0
 /**
  * @param Resource $resource
  * @param array             $data
  */
 public function generate(Resource $resource, array $data = array())
 {
     $filepath = $resource->getSrcFilename();
     $name = $data['name'];
     $arguments = $data['arguments'];
     $argString = count($arguments) ? '$argument' . implode(', $argument', range(1, count($arguments))) : '';
     $values = array('%name%' => $name, '%arguments%' => $argString);
     if (!($content = $this->templates->render('method', $values))) {
         $content = $this->templates->renderString($this->getTemplate(), $values);
     }
     $code = $this->filesystem->getFileContents($filepath);
     $this->filesystem->putFileContents($filepath, $this->getUpdatedCode($name, $content, $code));
     $this->io->writeln(sprintf("<info>Method <value>%s::%s()</value> has been created.</info>\n", $resource->getSrcClassname(), $name), 2);
 }
 /**
  * @param Resource $resource
  * @param array             $data
  */
 public function generate(Resource $resource, array $data)
 {
     $method = $data['method'];
     $expected = $data['expected'];
     $code = $this->filesystem->getFileContents($resource->getSrcFilename());
     $values = array('%constant%' => var_export($expected, true));
     if (!($content = $this->templates->render('method', $values))) {
         $content = $this->templates->renderString($this->getTemplate(), $values);
     }
     $pattern = '/' . '(function\\s+' . preg_quote($method, '/') . '\\s*\\([^\\)]*\\))\\s+{[^}]*?}/';
     $replacement = '$1' . $content;
     $modifiedCode = preg_replace($pattern, $replacement, $code);
     $this->filesystem->putFileContents($resource->getSrcFilename(), $modifiedCode);
     $this->io->writeln(sprintf("<info>Method <value>%s::%s()</value> has been modified.</info>\n", $resource->getSrcClassname(), $method), 2);
 }
 /**
  * @param Resource $resource
  * @param array $data
  *
  * @return mixed
  */
 public function generate(Resource $resource, array $data = array())
 {
     $filepath = $resource->getSrcFilename();
     $name = $data['name'];
     $arguments = $data['arguments'];
     $argString = $this->argumentBuilder->buildFrom($arguments);
     $values = array('%name%' => $name, '%arguments%' => $argString);
     if (!($content = $this->templates->render('method', $values))) {
         $content = $this->templates->renderString($this->getTemplate(), $values);
     }
     $code = $this->filesystem->getFileContents($filepath);
     $code = preg_replace('/}[ \\n]*$/', rtrim($content) . "\n}\n", trim($code));
     $this->filesystem->putFileContents($filepath, $code);
     $this->io->writeln(sprintf("\n<info>Method <value>%s::%s()</value> has been created.</info>", $resource->getSrcClassname(), $name), 2);
 }
 function let(ConsoleIO $io, ResourceManager $resourceManager, GeneratorManager $generatorManager, SuiteEvent $suiteEvent, ExampleEvent $exampleEvent, NameChecker $nameChecker)
 {
     $io->writeln(Argument::any())->willReturn();
     $io->askConfirmation(Argument::any())->willReturn();
     $this->beConstructedWith($io, $resourceManager, $generatorManager, $nameChecker);
     $io->isCodeGenerationEnabled()->willReturn(true);
 }
Example #8
0
 public function displayFatal(CurrentExampleTracker $currentExample, $error)
 {
     if (null !== $error && ($currentExample->getCurrentExample() || $error['type'] == E_ERROR) || is_null($currentExample->getCurrentExample()) && defined('HHVM_VERSION')) {
         ini_set('display_errors', "stderr");
         $failedOpen = $this->io->isDecorated() ? '<failed>' : '';
         $failedClosed = $this->io->isDecorated() ? '</failed>' : '';
         $failedCross = $this->io->isDecorated() ? '✘' : '';
         $this->io->writeln("{$failedOpen}{$failedCross} Fatal error happened while executing the following {$failedClosed}");
         $this->io->writeln("{$failedOpen}    {$currentExample->getCurrentExample()} {$failedClosed}");
         $this->io->writeln("{$failedOpen}    {$error['message']} in {$error['file']} on line {$error['line']} {$failedClosed}");
     }
 }
Example #9
0
 function it_outputs_a_suite_summary(SuiteEvent $event, ConsoleIO $io, StatisticsCollector $stats)
 {
     $stats->getEventsCount()->willReturn(1);
     $stats->getFailedEvents()->willReturn(array());
     $stats->getBrokenEvents()->willReturn(array());
     $stats->getPendingEvents()->willReturn(array());
     $stats->getSkippedEvents()->willReturn(array());
     $stats->getTotalSpecs()->willReturn(15);
     $event->getTime()->willReturn(12.345);
     $stats->getCountsHash()->willReturn(array('passed' => 1, 'pending' => 0, 'skipped' => 0, 'failed' => 2, 'broken' => 0));
     $this->afterSuite($event);
     $io->writeln('15 specs')->shouldHaveBeenCalled();
     $io->writeln("\n12345ms")->shouldHaveBeenCalled();
     $io->write('1 example ')->shouldHaveBeenCalled();
     $expected = '(<passed>1 passed</passed>, <failed>2 failed</failed>)';
     $io->write($expected)->shouldHaveBeenCalled();
 }
Example #10
0
 function it_outputs_undefined_progress_on_afterexample_event(SpecificationEvent $specEvent, ExampleEvent $exampleEvent, ExampleNode $example, SpecificationNode $spec, ConsoleIO $io, StatisticsCollector $stats)
 {
     $specEvent->getSpecification()->willReturn($spec);
     $exampleEvent->getExample()->willReturn($example);
     $example->getTitle()->willReturn('foobar');
     $exampleEvent->getResult()->willReturn(999);
     $spec->getTitle()->willReturn('spec1');
     $this->beforeSpecification($specEvent);
     $this->afterExample($exampleEvent);
     $expected = "not ok 1 - spec1: foobar\n  ---\n  message: 'The example result type was unknown to formatter'\n  severity: fail\n  ...";
     $io->writeln($expected)->shouldHaveBeenCalled();
 }
Example #11
0
 /**
  * @param Resource $resource
  * @param string            $filepath
  */
 private function generateFileAndRenderTemplate(Resource $resource, $filepath)
 {
     $content = $this->renderTemplate($resource, $filepath);
     $this->filesystem->putFileContents($filepath, $content);
     $this->io->writeln($this->getGeneratedMessage($resource, $filepath));
 }