/** {@inheritdoc} */
 public function execute(array $input)
 {
     $text = $this->textSanitizer->sanitize($input);
     $location = $this->locationSanitizer->sanitize($input);
     $addition = $input['addition'];
     $lines = $text->getLines();
     array_splice($lines, $location, 0, $addition);
     $text->setLines($lines);
     $text->setCurrentLineNumber($location);
 }
 /** {@inheritdoc} */
 public function execute(array $input)
 {
     $text = $this->textSanitizer->sanitize($input);
     $location = $this->locationSanitizer->sanitize($input);
     $lines = $text->getLines();
     array_splice($lines, $location, 1);
     $text->setLines($lines);
     $lineNumber = $location === $text->getLength() ? $location - 1 : $location;
     $text->setCurrentLineNumber($lineNumber);
 }
 /**
  * {@inheritdoc}
  *
  * @throws InvalidArgumentException If replacement isn't valid
  */
 public function execute(array $input)
 {
     $text = $this->textSanitizer->sanitize($input);
     $location = $this->locationSanitizer->sanitize($input);
     if (!is_callable($input['replacement'])) {
         throw new InvalidArgumentException('Invalid replacement');
     }
     $line = $text->getLine($location);
     $replacement = $input['replacement']($line);
     $text->setLine($replacement, $location);
     $text->setCurrentLineNumber($location);
 }
 function it_inserts_new_lines(TextSanitizer $textSanitizer, LocationSanitizer $locationSanitizer, Text $text)
 {
     $expectedFilename = sprintf(self::EXPECTED_FILENAME, $this->rootPath);
     $expectedLines = file($expectedFilename, FILE_IGNORE_NEW_LINES);
     $lineNumber = 6;
     $input = array('text' => $text, 'location' => $lineNumber - 1, 'addition' => "Pontius Pilate: '...Dickus?'");
     $textSanitizer->sanitize($input)->willReturn($text);
     $locationSanitizer->sanitize($input)->willReturn($lineNumber - 1);
     $text->setLines($expectedLines)->shouldBeCalled();
     $text->setCurrentLineNumber($lineNumber)->shouldBeCalled();
     $this->execute($input);
     $input = array('text' => $text, 'addition' => "Pontius Pilate: '...Dickus?'");
     $textSanitizer->sanitize($input)->willReturn($text);
     $locationSanitizer->sanitize($input)->willReturn($lineNumber - 1);
     $text->getCurrentLineNumber()->willReturn($lineNumber - 1);
     $text->setCurrentLineNumber($lineNumber)->shouldBeCalled();
     $this->execute($input);
 }
 function it_removes_lines(TextSanitizer $textSanitizer, LocationSanitizer $locationSanitizer, Text $text)
 {
     $expectedFilename = sprintf(self::EXPECTED_FILENAME, $this->rootPath);
     $expectedLines = file($expectedFilename, FILE_IGNORE_NEW_LINES);
     $lineNumber = 2;
     $input = array('text' => $text, 'location' => $lineNumber);
     $textSanitizer->sanitize($input)->willReturn($text);
     $locationSanitizer->sanitize($input)->willReturn($lineNumber);
     $text->setLines($expectedLines)->shouldBeCalled();
     $text->getLength()->willReturn(count($expectedLines));
     $text->setCurrentLineNumber($lineNumber)->shouldBeCalled();
     $this->execute($input);
     $input = array('text' => $text);
     $textSanitizer->sanitize($input)->willReturn($text);
     $locationSanitizer->sanitize($input)->willReturn($lineNumber);
     $text->getCurrentLineNumber()->willReturn($lineNumber);
     $text->setCurrentLineNumber($lineNumber)->shouldBeCalled();
     $this->execute($input);
 }
 function it_replaces_line(TextSanitizer $textSanitizer, LocationSanitizer $locationSanitizer, Text $text)
 {
     $expectedFilename = sprintf(self::EXPECTED_FILENAME, $this->rootPath);
     $expectedLines = file($expectedFilename, FILE_IGNORE_NEW_LINES);
     $expectedLine = $expectedLines[self::LINE_NUMBER];
     $replacement = function ($line) {
         return '[Even more sniggering]';
     };
     $input = array('text' => $text, 'location' => self::LINE_NUMBER, 'replacement' => $replacement);
     $textSanitizer->sanitize($input)->willReturn($text);
     $locationSanitizer->sanitize($input)->willReturn(self::LINE_NUMBER);
     $text->setLine($expectedLine, self::LINE_NUMBER)->shouldBeCalled();
     $text->setCurrentLineNumber(self::LINE_NUMBER)->shouldBeCalled();
     $this->execute($input);
     $input = array('text' => $text, 'replacement' => $replacement);
     $textSanitizer->sanitize($input)->willReturn($text);
     $locationSanitizer->sanitize($input)->willReturn(self::LINE_NUMBER);
     $text->getCurrentLineNumber()->willReturn(self::LINE_NUMBER);
     $text->setCurrentLineNumber(self::LINE_NUMBER)->shouldBeCalled();
     $this->execute($input);
 }