public function testEscapedStrings() { $params = new CommandParams('"foo bar" "baz fu" \'bar baz\''); $this->assertEquals(['foo bar', 'baz fu', "'bar", "baz'"], $params->getArguments()); $this->assertSame('foo bar', $params->getFirstArgument()); $this->assertSame('baz fu', $params->getSecondArgument()); $this->assertSame("'bar", $params->getThirdArgument()); $this->assertSame('foo bar', $params->getArgument(0)); $this->assertSame('baz fu', $params->getArgument(1)); $this->assertSame("'bar", $params->getArgument(2)); $this->assertSame("baz'", $params->getArgument(3)); }
/** * @param string $contents * @param CommandParams $params * * @return string * * @throws ExecutionFailedException */ private function findLines($contents, CommandParams $params) { $lines = explode("\n", $contents); $range = $params->getThirdArgument(); if (is_numeric($range)) { return $this->wrapLines(array_slice($lines, $range - 1, 1)); } $matches = []; if (!preg_match('|(\\d+)-(\\d+)|', $range, $matches)) { throw new ExecutionFailedException("Line definition '{$range}' is not valid. Must be in format N or N-N."); } $from = min([$matches[1], $matches[2]]); $to = max([$matches[1], $matches[2]]); return $this->wrapLines(array_slice($lines, $from - 1, $to - $from + 1)); }