예제 #1
0
 /**
  * File changes are made in memory only, until this methods actually applies
  * them on the filesystem.
  *
  * @param File $file
  *
  * @throws \Symfony\Component\Filesystem\Exception\IOException If the file cannot be written to.
  *
  * @api
  */
 public function save(File $file, $filename = null)
 {
     if ($filename !== null) {
         $file->setFilename($filename);
     }
     $this->filesystem->write($file);
 }
 function it_inserts_properties(File $file, Property $property, InsertPropertyHandler $insertPropertyHandler)
 {
     $properties = [$property->getWrappedObject()];
     $insertProperties = new InsertProperties($file->getWrappedObject(), $properties);
     $insertProperty = Argument::Type(InsertProperty::class);
     $insertPropertyHandler->handle($insertProperty)->shouldBeCalled();
     $this->handle($insertProperties);
 }
 function it_does_not_insert_the_same_use_statement_twice(Editor $editor, File $file, FullyQualifiedName $fullyQualifiedName, InsertUseStatementHandler $insertUseStatementHandler)
 {
     $fullyQualifiedNames = [$fullyQualifiedName->getWrappedObject()];
     $insertUseStatements = new InsertUseStatements($file->getWrappedObject(), $fullyQualifiedNames);
     $fullyQualifiedName->getFullyQualifiedName()->willReturn('Vendor\\Project\\MyDependency');
     $editor->hasBelow($file, '/^use Vendor\\\\Project\\\\MyDependency;$/', 0)->willReturn(true);
     $insertUseStatement = Argument::Type(InsertUseStatement::class);
     $insertUseStatementHandler->handle($insertUseStatement)->shouldNotBeCalled();
     $this->handle($insertUseStatements);
 }
 function it_inserts_use_statement_at_the_end_of_use_statement_block(Editor $editor, File $file, FullyQualifiedName $fullyQualifiedName)
 {
     $insertUseStatement = new InsertUseStatement($file->getWrappedObject(), $fullyQualifiedName->getWrappedObject());
     $fullyQualifiedName->getNamespace()->willReturn(self::NAME_SPACE);
     $fullyQualifiedName->getFullyQualifiedName()->willReturn(self::FULLY_QUALIFIED_NAME);
     $editor->hasBelow($file, self::NAME_SPACE_PATTERN, 0)->willReturn(false);
     $editor->hasBelow($file, self::USE_STATEMENT_PATTERN, 0)->willReturn(false);
     $editor->jumpBelow($file, InsertUseStatementHandler::CLASS_ENDING, 0)->shouldBeCalled();
     $editor->hasAbove($file, InsertUseStatementHandler::USE_STATEMENT)->willReturn(true);
     $editor->jumpAbove($file, InsertUseStatementHandler::USE_STATEMENT)->shouldBeCalled();
     $editor->insertBelow($file, self::USE_STATEMENT)->shouldBeCalled();
     $this->handle($insertUseStatement);
 }
예제 #5
0
 function it_inserts_method_in_class_with_stuff(Editor $editor, File $file, Method $method, PrettyPrinter $prettyPrinter)
 {
     $insertMethod = new InsertMethod($file->getWrappedObject(), $method->getWrappedObject());
     $method->getName()->willReturn(self::METHOD_NAME);
     $editor->hasBelow($file, self::METHOD_PATTERN, 0)->willReturn(false);
     $editor->jumpBelow($file, InsertMethodHandler::CLASS_ENDING, 0)->shouldBeCalled();
     $file->decrementCurrentLineNumber(1)->shouldBeCalled();
     $file->getLine()->willReturn('    }');
     $editor->insertBelow($file, '')->shouldBeCalled();
     $prettyPrinter->generateCode($method)->willReturn(self::GENERATED_CODE);
     $editor->insertBelow($file, self::GENERATED_CODE)->shouldBeCalled();
     $this->handle($insertMethod);
 }
 function it_inserts_constructor_in_class_with_methods_and_other_stuff(Editor $editor, File $file, Method $method, PrettyPrinter $prettyPrinter)
 {
     $insertConstructor = new InsertConstructor($file->getWrappedObject(), $method->getWrappedObject());
     $editor->hasBelow($file, InsertConstructorHandler::CONSTRUCTOR, 0)->willReturn(false);
     $editor->hasBelow($file, InsertConstructorHandler::METHOD, 0)->willReturn(true);
     $editor->jumpBelow($file, InsertConstructorHandler::METHOD, 0)->shouldBeCalled();
     $editor->insertAbove($file, '')->shouldBeCalled();
     $prettyPrinter->generateCode($method)->willReturn(self::GENERATED_CODE);
     $editor->insertAbove($file, self::GENERATED_CODE)->shouldBeCalled();
     $file->decrementCurrentLineNumber(1)->shouldBeCalled();
     $file->getLine()->willReturn('    const CONSTANT = 42;');
     $editor->insertBelow($file, '')->shouldBeCalled();
     $this->handle($insertConstructor);
 }
예제 #7
0
 function it_writes_files(SymfonyFilesystem $symfonyFilesystem)
 {
     $this->fileCopier->copy($this->sourceFilename, $this->copyFilename, true);
     $content = file_get_contents($this->copyFilename);
     $lines = file($this->copyFilename);
     $file = File::fromArray($lines);
     $file->setFilename($this->copyFilename);
     $symfonyFilesystem->dumpFile($this->copyFilename, $content, null)->shouldBeCalled();
     $this->write($file);
 }
예제 #8
0
    public function getExamples()
    {
        $levelMessage = 'The "%s" character should be used for a title level %d';
        $invalidMessage = 'Only =, -, ~, . and " should be used as title underlines';
        $incFile = File::fromString(<<<RST
Title level 3
~~~~~~~~~~~~~
RST
);
        $incFile->setFilename('file.rst.inc');
        return [[Text::fromString(<<<RST
Title Level 1
=============

Title level 2
~~~~~~~~~~~~~
RST
), [$this->getViolationProphet(sprintf($levelMessage, '-', 2), 2)], 'It finds wrongly used underline level'], [Text::fromString(<<<RST
Title Level 1
+++++++++++++
RST
), [$this->getViolationProphet($invalidMessage, 2)], 'It finds unused underline levels that are valid in reStructured Text'], [Text::fromString(<<<RST
Title level 1
=============

Title level 2
-------------

Title level 3
~~~~~~~~~~~~~

Title level 4
.............

Title level 2
-------------
RST
), [], 'It accepts jumping multiple levels back'], [$incFile, [], 'Inc files are allowed to start at deeper levels']];
    }
예제 #9
0
 function let(File $file, Filesystem $filesystem, SearchEngine $searchEngine, CommandInvoker $commandInvoker)
 {
     $file->getFilename()->willReturn(self::FILENAME);
     $this->beConstructedWith($filesystem, $searchEngine, $commandInvoker);
 }
예제 #10
0
파일: Console.php 프로젝트: wouterj/docbot
 private function printFilename(File $file)
 {
     $filename = str_replace(getcwd(), '', $file->getFilename());
     $this->output->writeln(array('<fg=blue>', $filename, str_repeat('=', strlen($filename)) . '</>'));
 }
예제 #11
0
 function it_inserts_property_in_class_with_methods(Editor $editor, File $file, PrettyPrinter $prettyPrinter, Property $property)
 {
     $insertProperty = new InsertProperty($file->getWrappedObject(), $property->getWrappedObject());
     $property->getName()->willReturn('property');
     $editor->hasBelow($file, '/^    private \\$property;$/', 0)->willReturn(false);
     $editor->hasBelow($file, InsertPropertyHandler::PROPERTY, 0)->willReturn(false);
     $editor->hasBelow($file, InsertPropertyHandler::CONSTANT, 0)->willReturn(false);
     $editor->jumpBelow($file, InsertPropertyHandler::CLASS_OPENING, 0)->shouldBeCalled();
     $prettyPrinter->generateCode($property)->willReturn('    private $property;');
     $editor->insertBelow($file, '    private $property;')->shouldBeCalled();
     $file->incrementCurrentLineNumber(1)->shouldBeCalled();
     $file->getLine()->willReturn('    public function __construct($property)');
     $editor->insertAbove($file, '')->shouldBeCalled();
     $this->handle($insertProperty);
 }
예제 #12
0
 /**
  * Atomically writes the given File's content on the actual file.
  *
  * @param File $file
  *
  * @throws IOException If the file cannot be written to.
  */
 public function write(File $file)
 {
     $filename = $file->getFilename();
     if (null === $filename) {
         throw new NoFilenameGivenException();
     }
     $content = $this->contentFactory->make($file);
     try {
         $this->symfonyFilesystem->dumpFile($filename, $content, null);
     } catch (SymfonyIOException $e) {
         $message = sprintf('Failed to write "%s".', $filename);
         throw new IOException($filename, $message, $e);
     }
 }