Vendor lock
This commit is contained in:
31
vendor/sebastian/diff/tests/Utils/FileUtils.php
vendored
Normal file
31
vendor/sebastian/diff/tests/Utils/FileUtils.php
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Diff\Utils;
|
||||
|
||||
final class FileUtils
|
||||
{
|
||||
public static function getFileContent(string $file): string
|
||||
{
|
||||
$content = @\file_get_contents($file);
|
||||
|
||||
if (false === $content) {
|
||||
$error = \error_get_last();
|
||||
|
||||
throw new \RuntimeException(\sprintf(
|
||||
'Failed to read content of file "%s".%s',
|
||||
$file,
|
||||
$error ? ' ' . $error['message'] : ''
|
||||
));
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
277
vendor/sebastian/diff/tests/Utils/UnifiedDiffAssertTrait.php
vendored
Normal file
277
vendor/sebastian/diff/tests/Utils/UnifiedDiffAssertTrait.php
vendored
Normal file
@ -0,0 +1,277 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Diff\Utils;
|
||||
|
||||
trait UnifiedDiffAssertTrait
|
||||
{
|
||||
/**
|
||||
* @param string $diff
|
||||
*
|
||||
* @throws \UnexpectedValueException
|
||||
*/
|
||||
public function assertValidUnifiedDiffFormat(string $diff): void
|
||||
{
|
||||
if ('' === $diff) {
|
||||
$this->addToAssertionCount(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// test diff ends with a line break
|
||||
$last = \substr($diff, -1);
|
||||
|
||||
if ("\n" !== $last && "\r" !== $last) {
|
||||
throw new \UnexpectedValueException(\sprintf('Expected diff to end with a line break, got "%s".', $last));
|
||||
}
|
||||
|
||||
$lines = \preg_split('/(.*\R)/', $diff, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$lineCount = \count($lines);
|
||||
$lineNumber = $diffLineFromNumber = $diffLineToNumber = 1;
|
||||
$fromStart = $fromTillOffset = $toStart = $toTillOffset = -1;
|
||||
$expectHunkHeader = true;
|
||||
|
||||
// check for header
|
||||
if ($lineCount > 1) {
|
||||
$this->unifiedDiffAssertLinePrefix($lines[0], 'Line 1.');
|
||||
$this->unifiedDiffAssertLinePrefix($lines[1], 'Line 2.');
|
||||
|
||||
if ('---' === \substr($lines[0], 0, 3)) {
|
||||
if ('+++' !== \substr($lines[1], 0, 3)) {
|
||||
throw new \UnexpectedValueException(\sprintf("Line 1 indicates a header, so line 2 must start with \"+++\".\nLine 1: \"%s\"\nLine 2: \"%s\".", $lines[0], $lines[1]));
|
||||
}
|
||||
|
||||
$this->unifiedDiffAssertHeaderLine($lines[0], '--- ', 'Line 1.');
|
||||
$this->unifiedDiffAssertHeaderLine($lines[1], '+++ ', 'Line 2.');
|
||||
|
||||
$lineNumber = 3;
|
||||
}
|
||||
}
|
||||
|
||||
$endOfLineTypes = [];
|
||||
$diffClosed = false;
|
||||
|
||||
// assert format of lines, get all hunks, test the line numbers
|
||||
for (; $lineNumber <= $lineCount; ++$lineNumber) {
|
||||
if ($diffClosed) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected line as 2 "No newline" markers have found, ". Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
$line = $lines[$lineNumber - 1]; // line numbers start by 1, array index at 0
|
||||
$type = $this->unifiedDiffAssertLinePrefix($line, \sprintf('Line %d.', $lineNumber));
|
||||
|
||||
if ($expectHunkHeader && '@' !== $type && '\\' !== $type) {
|
||||
throw new \UnexpectedValueException(\sprintf('Expected hunk start (\'@\'), got "%s". Line %d.', $type, $lineNumber));
|
||||
}
|
||||
|
||||
if ('@' === $type) {
|
||||
if (!$expectHunkHeader) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected hunk start (\'@\'). Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
$previousHunkFromEnd = $fromStart + $fromTillOffset;
|
||||
$previousHunkTillEnd = $toStart + $toTillOffset;
|
||||
|
||||
[$fromStart, $fromTillOffset, $toStart, $toTillOffset] = $this->unifiedDiffAssertHunkHeader($line, \sprintf('Line %d.', $lineNumber));
|
||||
|
||||
// detect overlapping hunks
|
||||
if ($fromStart < $previousHunkFromEnd) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected new hunk; "from" (\'-\') start overlaps previous hunk. Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
if ($toStart < $previousHunkTillEnd) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected new hunk; "to" (\'+\') start overlaps previous hunk. Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
/* valid states; hunks touches against each other:
|
||||
$fromStart === $previousHunkFromEnd
|
||||
$toStart === $previousHunkTillEnd
|
||||
*/
|
||||
|
||||
$diffLineFromNumber = $fromStart;
|
||||
$diffLineToNumber = $toStart;
|
||||
$expectHunkHeader = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('-' === $type) {
|
||||
if (isset($endOfLineTypes['-'])) {
|
||||
throw new \UnexpectedValueException(\sprintf('Not expected from (\'-\'), already closed by "\\ No newline at end of file". Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
++$diffLineFromNumber;
|
||||
} elseif ('+' === $type) {
|
||||
if (isset($endOfLineTypes['+'])) {
|
||||
throw new \UnexpectedValueException(\sprintf('Not expected to (\'+\'), already closed by "\\ No newline at end of file". Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
++$diffLineToNumber;
|
||||
} elseif (' ' === $type) {
|
||||
if (isset($endOfLineTypes['-'])) {
|
||||
throw new \UnexpectedValueException(\sprintf('Not expected same (\' \'), \'-\' already closed by "\\ No newline at end of file". Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
if (isset($endOfLineTypes['+'])) {
|
||||
throw new \UnexpectedValueException(\sprintf('Not expected same (\' \'), \'+\' already closed by "\\ No newline at end of file". Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
++$diffLineFromNumber;
|
||||
++$diffLineToNumber;
|
||||
} elseif ('\\' === $type) {
|
||||
if (!isset($lines[$lineNumber - 2])) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected "\\ No newline at end of file", it must be preceded by \'+\' or \'-\' line. Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
$previousType = $this->unifiedDiffAssertLinePrefix($lines[$lineNumber - 2], \sprintf('Preceding line of "\\ No newline at end of file" of unexpected format. Line %d.', $lineNumber));
|
||||
|
||||
if (isset($endOfLineTypes[$previousType])) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected "\\ No newline at end of file", "%s" was already closed. Line %d.', $type, $lineNumber));
|
||||
}
|
||||
|
||||
$endOfLineTypes[$previousType] = true;
|
||||
$diffClosed = \count($endOfLineTypes) > 1;
|
||||
} else {
|
||||
// internal state error
|
||||
throw new \RuntimeException(\sprintf('Unexpected line type "%s" Line %d.', $type, $lineNumber));
|
||||
}
|
||||
|
||||
$expectHunkHeader =
|
||||
$diffLineFromNumber === ($fromStart + $fromTillOffset)
|
||||
&& $diffLineToNumber === ($toStart + $toTillOffset)
|
||||
;
|
||||
}
|
||||
|
||||
if (
|
||||
$diffLineFromNumber !== ($fromStart + $fromTillOffset)
|
||||
&& $diffLineToNumber !== ($toStart + $toTillOffset)
|
||||
) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected EOF, number of lines in hunk "from" (\'-\')) and "to" (\'+\') mismatched. Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
if ($diffLineFromNumber !== ($fromStart + $fromTillOffset)) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected EOF, number of lines in hunk "from" (\'-\')) mismatched. Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
if ($diffLineToNumber !== ($toStart + $toTillOffset)) {
|
||||
throw new \UnexpectedValueException(\sprintf('Unexpected EOF, number of lines in hunk "to" (\'+\')) mismatched. Line %d.', $lineNumber));
|
||||
}
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $line
|
||||
* @param string $message
|
||||
*
|
||||
* @return string '+', '-', '@', ' ' or '\'
|
||||
*/
|
||||
private function unifiedDiffAssertLinePrefix(string $line, string $message): string
|
||||
{
|
||||
$this->unifiedDiffAssertStrLength($line, 2, $message); // 2: line type indicator ('+', '-', ' ' or '\') and a line break
|
||||
$firstChar = $line[0];
|
||||
|
||||
if ('+' === $firstChar || '-' === $firstChar || '@' === $firstChar || ' ' === $firstChar) {
|
||||
return $firstChar;
|
||||
}
|
||||
|
||||
if ("\\ No newline at end of file\n" === $line) {
|
||||
return '\\';
|
||||
}
|
||||
|
||||
throw new \UnexpectedValueException(\sprintf('Expected line to start with \'@\', \'-\' or \'+\', got "%s". %s', $line, $message));
|
||||
}
|
||||
|
||||
private function unifiedDiffAssertStrLength(string $line, int $min, string $message): void
|
||||
{
|
||||
$length = \strlen($line);
|
||||
|
||||
if ($length < $min) {
|
||||
throw new \UnexpectedValueException(\sprintf('Expected string length of minimal %d, got %d. %s', $min, $length, $message));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert valid unified diff header line
|
||||
*
|
||||
* Samples:
|
||||
* - "+++ from1.txt\t2017-08-24 19:51:29.383985722 +0200"
|
||||
* - "+++ from1.txt"
|
||||
*
|
||||
* @param string $line
|
||||
* @param string $start
|
||||
* @param string $message
|
||||
*/
|
||||
private function unifiedDiffAssertHeaderLine(string $line, string $start, string $message): void
|
||||
{
|
||||
if (0 !== \strpos($line, $start)) {
|
||||
throw new \UnexpectedValueException(\sprintf('Expected header line to start with "%s", got "%s". %s', $start . ' ', $line, $message));
|
||||
}
|
||||
|
||||
// sample "+++ from1.txt\t2017-08-24 19:51:29.383985722 +0200\n"
|
||||
$match = \preg_match(
|
||||
"/^([^\t]*)(?:[\t]([\\S].*[\\S]))?\n$/",
|
||||
\substr($line, 4), // 4 === string length of "+++ " / "--- "
|
||||
$matches
|
||||
);
|
||||
|
||||
if (1 !== $match) {
|
||||
throw new \UnexpectedValueException(\sprintf('Header line does not match expected pattern, got "%s". %s', $line, $message));
|
||||
}
|
||||
|
||||
// $file = $matches[1];
|
||||
|
||||
if (\count($matches) > 2) {
|
||||
$this->unifiedDiffAssertHeaderDate($matches[2], $message);
|
||||
}
|
||||
}
|
||||
|
||||
private function unifiedDiffAssertHeaderDate(string $date, string $message): void
|
||||
{
|
||||
// sample "2017-08-24 19:51:29.383985722 +0200"
|
||||
$match = \preg_match(
|
||||
'/^([\d]{4})-([01]?[\d])-([0123]?[\d])(:? [\d]{1,2}:[\d]{1,2}(?::[\d]{1,2}(:?\.[\d]+)?)?(?: ([\+\-][\d]{4}))?)?$/',
|
||||
$date,
|
||||
$matches
|
||||
);
|
||||
|
||||
if (1 !== $match || ($matchesCount = \count($matches)) < 4) {
|
||||
throw new \UnexpectedValueException(\sprintf('Date of header line does not match expected pattern, got "%s". %s', $date, $message));
|
||||
}
|
||||
|
||||
// [$full, $year, $month, $day, $time] = $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $line
|
||||
* @param string $message
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function unifiedDiffAssertHunkHeader(string $line, string $message): array
|
||||
{
|
||||
if (1 !== \preg_match('#^@@ -([\d]+)((?:,[\d]+)?) \+([\d]+)((?:,[\d]+)?) @@\n$#', $line, $matches)) {
|
||||
throw new \UnexpectedValueException(
|
||||
\sprintf(
|
||||
'Hunk header line does not match expected pattern, got "%s". %s',
|
||||
$line,
|
||||
$message
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
(int) $matches[1],
|
||||
empty($matches[2]) ? 1 : (int) \substr($matches[2], 1),
|
||||
(int) $matches[3],
|
||||
empty($matches[4]) ? 1 : (int) \substr($matches[4], 1),
|
||||
];
|
||||
}
|
||||
}
|
129
vendor/sebastian/diff/tests/Utils/UnifiedDiffAssertTraitIntegrationTest.php
vendored
Normal file
129
vendor/sebastian/diff/tests/Utils/UnifiedDiffAssertTraitIntegrationTest.php
vendored
Normal file
@ -0,0 +1,129 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Diff\Utils;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* @requires OS Linux
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class UnifiedDiffAssertTraitIntegrationTest extends TestCase
|
||||
{
|
||||
use UnifiedDiffAssertTrait;
|
||||
|
||||
private $filePatch;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->filePatch = __DIR__ . '/../fixtures/out/patch.txt';
|
||||
|
||||
$this->cleanUpTempFiles();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->cleanUpTempFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileFrom
|
||||
* @param string $fileTo
|
||||
*
|
||||
* @dataProvider provideFilePairsCases
|
||||
*/
|
||||
public function testValidPatches(string $fileFrom, string $fileTo): void
|
||||
{
|
||||
$command = \sprintf(
|
||||
'diff -u %s %s > %s',
|
||||
\escapeshellarg(\realpath($fileFrom)),
|
||||
\escapeshellarg(\realpath($fileTo)),
|
||||
\escapeshellarg($this->filePatch)
|
||||
);
|
||||
|
||||
$p = new Process($command);
|
||||
$p->run();
|
||||
|
||||
$exitCode = $p->getExitCode();
|
||||
|
||||
if (0 === $exitCode) {
|
||||
// odd case when two files have the same content. Test after executing as it is more efficient than to read the files and check the contents every time.
|
||||
$this->addToAssertionCount(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertSame(
|
||||
1, // means `diff` found a diff between the files we gave it
|
||||
$exitCode,
|
||||
\sprintf(
|
||||
"Command exec. was not successful:\n\"%s\"\nOutput:\n\"%s\"\nStdErr:\n\"%s\"\nExit code %d.\n",
|
||||
$command,
|
||||
$p->getOutput(),
|
||||
$p->getErrorOutput(),
|
||||
$p->getExitCode()
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(FileUtils::getFileContent($this->filePatch));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, string>>
|
||||
*/
|
||||
public function provideFilePairsCases(): array
|
||||
{
|
||||
$cases = [];
|
||||
|
||||
// created cases based on dedicated fixtures
|
||||
$dir = \realpath(__DIR__ . '/../fixtures/UnifiedDiffAssertTraitIntegrationTest');
|
||||
$dirLength = \strlen($dir);
|
||||
|
||||
for ($i = 1;; ++$i) {
|
||||
$fromFile = \sprintf('%s/%d_a.txt', $dir, $i);
|
||||
$toFile = \sprintf('%s/%d_b.txt', $dir, $i);
|
||||
|
||||
if (!\file_exists($fromFile)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->assertFileExists($toFile);
|
||||
$cases[\sprintf("Diff file:\n\"%s\"\nvs.\n\"%s\"\n", \substr(\realpath($fromFile), $dirLength), \substr(\realpath($toFile), $dirLength))] = [$fromFile, $toFile];
|
||||
}
|
||||
|
||||
// create cases based on PHP files within the vendor directory for integration testing
|
||||
$dir = \realpath(__DIR__ . '/../../vendor');
|
||||
$dirLength = \strlen($dir);
|
||||
|
||||
$fileIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS));
|
||||
$fromFile = __FILE__;
|
||||
|
||||
/** @var \SplFileInfo $file */
|
||||
foreach ($fileIterator as $file) {
|
||||
if ('php' !== $file->getExtension()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$toFile = $file->getPathname();
|
||||
$cases[\sprintf("Diff file:\n\"%s\"\nvs.\n\"%s\"\n", \substr(\realpath($fromFile), $dirLength), \substr(\realpath($toFile), $dirLength))] = [$fromFile, $toFile];
|
||||
$fromFile = $toFile;
|
||||
}
|
||||
|
||||
return $cases;
|
||||
}
|
||||
|
||||
private function cleanUpTempFiles(): void
|
||||
{
|
||||
@\unlink($this->filePatch);
|
||||
}
|
||||
}
|
434
vendor/sebastian/diff/tests/Utils/UnifiedDiffAssertTraitTest.php
vendored
Normal file
434
vendor/sebastian/diff/tests/Utils/UnifiedDiffAssertTraitTest.php
vendored
Normal file
@ -0,0 +1,434 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Diff\Utils;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers SebastianBergmann\Diff\Utils\UnifiedDiffAssertTrait
|
||||
*/
|
||||
final class UnifiedDiffAssertTraitTest extends TestCase
|
||||
{
|
||||
use UnifiedDiffAssertTrait;
|
||||
|
||||
/**
|
||||
* @param string $diff
|
||||
*
|
||||
* @dataProvider provideValidCases
|
||||
*/
|
||||
public function testValidCases(string $diff): void
|
||||
{
|
||||
$this->assertValidUnifiedDiffFormat($diff);
|
||||
}
|
||||
|
||||
public function provideValidCases(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
-Z
|
||||
+U
|
||||
',
|
||||
],
|
||||
[
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
-Z
|
||||
+U
|
||||
@@ -15 +15 @@
|
||||
-X
|
||||
+V
|
||||
',
|
||||
],
|
||||
'empty diff. is valid' => [
|
||||
'',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testNoLinebreakEnd(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Expected diff to end with a line break, got "C".', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat("A\nB\nC");
|
||||
}
|
||||
|
||||
public function testInvalidStartWithoutHeader(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote("Expected line to start with '@', '-' or '+', got \"A\n\". Line 1.", '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat("A\n");
|
||||
}
|
||||
|
||||
public function testInvalidStartHeader1(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote("Line 1 indicates a header, so line 2 must start with \"+++\".\nLine 1: \"--- A\n\"\nLine 2: \"+ 1\n\".", '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat("--- A\n+ 1\n");
|
||||
}
|
||||
|
||||
public function testInvalidStartHeader2(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote("Header line does not match expected pattern, got \"+++ file X\n\". Line 2.", '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat("--- A\n+++ file\tX\n");
|
||||
}
|
||||
|
||||
public function testInvalidStartHeader3(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Date of header line does not match expected pattern, got "[invalid date]". Line 1.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
"--- Original\t[invalid date]
|
||||
+++ New
|
||||
@@ -1,2 +1,2 @@
|
||||
-A
|
||||
+B
|
||||
" . '
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidStartHeader4(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote("Expected header line to start with \"+++ \", got \"+++INVALID\n\". Line 2.", '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++INVALID
|
||||
@@ -1,2 +1,2 @@
|
||||
-A
|
||||
+B
|
||||
' . '
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidLine1(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote("Expected line to start with '@', '-' or '+', got \"1\n\". Line 5.", '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
-Z
|
||||
1
|
||||
+U
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidLine2(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Expected string length of minimal 2, got 1. Line 4.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
|
||||
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testHunkInvalidFormat(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote("Hunk header line does not match expected pattern, got \"@@ INVALID -1,1 +1,1 @@\n\". Line 3.", '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ INVALID -1,1 +1,1 @@
|
||||
-Z
|
||||
+U
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testHunkOverlapFrom(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected new hunk; "from" (\'-\') start overlaps previous hunk. Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,1 +8,1 @@
|
||||
-Z
|
||||
+U
|
||||
@@ -7,1 +9,1 @@
|
||||
-Z
|
||||
+U
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testHunkOverlapTo(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected new hunk; "to" (\'+\') start overlaps previous hunk. Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,1 +8,1 @@
|
||||
-Z
|
||||
+U
|
||||
@@ -17,1 +7,1 @@
|
||||
-Z
|
||||
+U
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testExpectHunk1(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Expected hunk start (\'@\'), got "+". Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
-Z
|
||||
+U
|
||||
+O
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testExpectHunk2(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected hunk start (\'@\'). Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,12 +8,12 @@
|
||||
' . '
|
||||
' . '
|
||||
@@ -38,12 +48,12 @@
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMisplacedLineAfterComments1(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected line as 2 "No newline" markers have found, ". Line 8.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
-Z
|
||||
\ No newline at end of file
|
||||
+U
|
||||
\ No newline at end of file
|
||||
+A
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMisplacedLineAfterComments2(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected line as 2 "No newline" markers have found, ". Line 7.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
+U
|
||||
\ No newline at end of file
|
||||
\ No newline at end of file
|
||||
\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMisplacedLineAfterComments3(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected line as 2 "No newline" markers have found, ". Line 7.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8 +8 @@
|
||||
+U
|
||||
\ No newline at end of file
|
||||
\ No newline at end of file
|
||||
+A
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMisplacedComment(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected "\ No newline at end of file", it must be preceded by \'+\' or \'-\' line. Line 1.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testUnexpectedDuplicateNoNewLineEOF(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected "\\ No newline at end of file", "\\" was already closed. Line 8.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,12 +8,12 @@
|
||||
' . '
|
||||
' . '
|
||||
\ No newline at end of file
|
||||
' . '
|
||||
\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFromAfterClose(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Not expected from (\'-\'), already closed by "\ No newline at end of file". Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,12 +8,12 @@
|
||||
-A
|
||||
\ No newline at end of file
|
||||
-A
|
||||
\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSameAfterFromClose(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Not expected same (\' \'), \'-\' already closed by "\ No newline at end of file". Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,12 +8,12 @@
|
||||
-A
|
||||
\ No newline at end of file
|
||||
A
|
||||
\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testToAfterClose(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Not expected to (\'+\'), already closed by "\ No newline at end of file". Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,12 +8,12 @@
|
||||
+A
|
||||
\ No newline at end of file
|
||||
+A
|
||||
\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSameAfterToClose(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Not expected same (\' \'), \'+\' already closed by "\ No newline at end of file". Line 6.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,12 +8,12 @@
|
||||
+A
|
||||
\ No newline at end of file
|
||||
A
|
||||
\ No newline at end of file
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testUnexpectedEOFFromMissingLines(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected EOF, number of lines in hunk "from" (\'-\')) mismatched. Line 7.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,19 +7,2 @@
|
||||
-A
|
||||
+B
|
||||
' . '
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testUnexpectedEOFToMissingLines(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected EOF, number of lines in hunk "to" (\'+\')) mismatched. Line 7.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -8,2 +7,3 @@
|
||||
-A
|
||||
+B
|
||||
' . '
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testUnexpectedEOFBothFromAndToMissingLines(): void
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessageRegExp(\sprintf('#^%s$#', \preg_quote('Unexpected EOF, number of lines in hunk "from" (\'-\')) and "to" (\'+\') mismatched. Line 7.', '#')));
|
||||
|
||||
$this->assertValidUnifiedDiffFormat(
|
||||
'--- Original
|
||||
+++ New
|
||||
@@ -1,12 +1,14 @@
|
||||
-A
|
||||
+B
|
||||
' . '
|
||||
'
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user