Added Laravel project

This commit is contained in:
2017-09-17 00:35:10 +02:00
parent a3c19304d5
commit ecf605b8f5
6246 changed files with 682270 additions and 2 deletions

View File

@@ -0,0 +1,68 @@
<?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;
use PHPUnit\Framework\TestCase;
/**
* @covers SebastianBergmann\Diff\Chunk
*/
final class ChunkTest extends TestCase
{
/**
* @var Chunk
*/
private $chunk;
protected function setUp()
{
$this->chunk = new Chunk;
}
public function testCanBeCreatedWithoutArguments()
{
$this->assertInstanceOf(Chunk::class, $this->chunk);
}
public function testStartCanBeRetrieved()
{
$this->assertSame(0, $this->chunk->getStart());
}
public function testStartRangeCanBeRetrieved()
{
$this->assertSame(1, $this->chunk->getStartRange());
}
public function testEndCanBeRetrieved()
{
$this->assertSame(0, $this->chunk->getEnd());
}
public function testEndRangeCanBeRetrieved()
{
$this->assertSame(1, $this->chunk->getEndRange());
}
public function testLinesCanBeRetrieved()
{
$this->assertSame([], $this->chunk->getLines());
}
public function testLinesCanBeSet()
{
$this->assertSame([], $this->chunk->getLines());
$testValue = ['line0', 'line1'];
$this->chunk->setLines($testValue);
$this->assertSame($testValue, $this->chunk->getLines());
}
}

View File

@@ -0,0 +1,55 @@
<?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;
use PHPUnit\Framework\TestCase;
/**
* @covers SebastianBergmann\Diff\Diff
*
* @uses SebastianBergmann\Diff\Chunk
*/
final class DiffTest extends TestCase
{
public function testGettersAfterConstructionWithDefault()
{
$from = 'line1a';
$to = 'line2a';
$diff = new Diff($from, $to);
$this->assertSame($from, $diff->getFrom());
$this->assertSame($to, $diff->getTo());
$this->assertSame([], $diff->getChunks(), 'Expect chunks to be default value "array()".');
}
public function testGettersAfterConstructionWithChunks()
{
$from = 'line1b';
$to = 'line2b';
$chunks = [new Chunk(), new Chunk(2, 3)];
$diff = new Diff($from, $to, $chunks);
$this->assertSame($from, $diff->getFrom());
$this->assertSame($to, $diff->getTo());
$this->assertSame($chunks, $diff->getChunks(), 'Expect chunks to be passed value.');
}
public function testSetChunksAfterConstruction()
{
$diff = new Diff('line1c', 'line2c');
$this->assertSame([], $diff->getChunks(), 'Expect chunks to be default value "array()".');
$chunks = [new Chunk(), new Chunk(2, 3)];
$diff->setChunks($chunks);
$this->assertSame($chunks, $diff->getChunks(), 'Expect chunks to be passed value.');
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,83 @@
<?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;
use PHPUnit\Framework\TestCase;
/**
* @requires OS Linux
*/
final class DifferTestTest extends TestCase
{
private $fileFrom;
private $filePatch;
protected function setUp()
{
$dir = \realpath(__DIR__ . '/../') . '/';
$this->fileFrom = $dir . 'from.txt';
$this->filePatch = $dir . 'patch.txt';
}
/**
* @dataProvider provideDiffWithLineNumbers
*/
public function testTheTestProvideDiffWithLineNumbers($expected, $from, $to)
{
$this->runThisTest($expected, $from, $to);
}
public function provideDiffWithLineNumbers()
{
require_once __DIR__ . '/DifferTest.php';
$test = new DifferTest();
$tests = $test->provideDiffWithLineNumbers();
$tests = \array_filter(
$tests,
function ($key) {
return !\is_string($key) || false === \strpos($key, 'non_patch_compat');
},
ARRAY_FILTER_USE_KEY
);
return $tests;
}
private function runThisTest(string $expected, string $from, string $to)
{
$expected = \str_replace('--- Original', '--- from.txt', $expected);
$expected = \str_replace('+++ New', '+++ from.txt', $expected);
@\unlink($this->fileFrom);
@\unlink($this->filePatch);
$this->assertNotFalse(\file_put_contents($this->fileFrom, $from));
$this->assertNotFalse(\file_put_contents($this->filePatch, $expected));
$command = \sprintf(
'patch -u --verbose %s < %s', // --posix
\escapeshellarg($this->fileFrom),
\escapeshellarg($this->filePatch)
);
\exec($command, $output, $d);
$this->assertSame(0, $d, \sprintf('%s | %s', $command, \implode("\n", $output)));
$patched = \file_get_contents($this->fileFrom);
$this->assertSame($patched, $to);
@\unlink($this->fileFrom . '.orig');
@\unlink($this->fileFrom);
@\unlink($this->filePatch);
}
}

View File

@@ -0,0 +1,44 @@
<?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;
use PHPUnit\Framework\TestCase;
/**
* @covers SebastianBergmann\Diff\Line
*/
final class LineTest extends TestCase
{
/**
* @var Line
*/
private $line;
protected function setUp()
{
$this->line = new Line;
}
public function testCanBeCreatedWithoutArguments()
{
$this->assertInstanceOf(Line::class, $this->line);
}
public function testTypeCanBeRetrieved()
{
$this->assertSame(Line::UNCHANGED, $this->line->getType());
}
public function testContentCanBeRetrieved()
{
$this->assertSame('', $this->line->getContent());
}
}

View File

@@ -0,0 +1,201 @@
<?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;
use PHPUnit\Framework\TestCase;
/**
* @coversNothing
*/
abstract class LongestCommonSubsequenceTest extends TestCase
{
/**
* @var LongestCommonSubsequenceCalculator
*/
private $implementation;
/**
* @var string
*/
private $memoryLimit;
/**
* @var int[]
*/
private $stress_sizes = [1, 2, 3, 100, 500, 1000, 2000];
protected function setUp()
{
$this->memoryLimit = \ini_get('memory_limit');
\ini_set('memory_limit', '256M');
$this->implementation = $this->createImplementation();
}
/**
* @return LongestCommonSubsequenceCalculator
*/
abstract protected function createImplementation();
protected function tearDown()
{
\ini_set('memory_limit', $this->memoryLimit);
}
public function testBothEmpty()
{
$from = [];
$to = [];
$common = $this->implementation->calculate($from, $to);
$this->assertSame([], $common);
}
public function testIsStrictComparison()
{
$from = [
false, 0, 0.0, '', null, [],
true, 1, 1.0, 'foo', ['foo', 'bar'], ['foo' => 'bar']
];
$to = $from;
$common = $this->implementation->calculate($from, $to);
$this->assertSame($from, $common);
$to = [
false, false, false, false, false, false,
true, true, true, true, true, true
];
$expected = [
false,
true,
];
$common = $this->implementation->calculate($from, $to);
$this->assertSame($expected, $common);
}
public function testEqualSequences()
{
foreach ($this->stress_sizes as $size) {
$range = \range(1, $size);
$from = $range;
$to = $range;
$common = $this->implementation->calculate($from, $to);
$this->assertSame($range, $common);
}
}
public function testDistinctSequences()
{
$from = ['A'];
$to = ['B'];
$common = $this->implementation->calculate($from, $to);
$this->assertSame([], $common);
$from = ['A', 'B', 'C'];
$to = ['D', 'E', 'F'];
$common = $this->implementation->calculate($from, $to);
$this->assertSame([], $common);
foreach ($this->stress_sizes as $size) {
$from = \range(1, $size);
$to = \range($size + 1, $size * 2);
$common = $this->implementation->calculate($from, $to);
$this->assertSame([], $common);
}
}
public function testCommonSubsequence()
{
$from = ['A', 'C', 'E', 'F', 'G'];
$to = ['A', 'B', 'D', 'E', 'H'];
$expected = ['A', 'E'];
$common = $this->implementation->calculate($from, $to);
$this->assertSame($expected, $common);
$from = ['A', 'C', 'E', 'F', 'G'];
$to = ['B', 'C', 'D', 'E', 'F', 'H'];
$expected = ['C', 'E', 'F'];
$common = $this->implementation->calculate($from, $to);
$this->assertSame($expected, $common);
foreach ($this->stress_sizes as $size) {
$from = $size < 2 ? [1] : \range(1, $size + 1, 2);
$to = $size < 3 ? [1] : \range(1, $size + 1, 3);
$expected = $size < 6 ? [1] : \range(1, $size + 1, 6);
$common = $this->implementation->calculate($from, $to);
$this->assertSame($expected, $common);
}
}
public function testSingleElementSubsequenceAtStart()
{
foreach ($this->stress_sizes as $size) {
$from = \range(1, $size);
$to = \array_slice($from, 0, 1);
$common = $this->implementation->calculate($from, $to);
$this->assertSame($to, $common);
}
}
public function testSingleElementSubsequenceAtMiddle()
{
foreach ($this->stress_sizes as $size) {
$from = \range(1, $size);
$to = \array_slice($from, (int) ($size / 2), 1);
$common = $this->implementation->calculate($from, $to);
$this->assertSame($to, $common);
}
}
public function testSingleElementSubsequenceAtEnd()
{
foreach ($this->stress_sizes as $size) {
$from = \range(1, $size);
$to = \array_slice($from, $size - 1, 1);
$common = $this->implementation->calculate($from, $to);
$this->assertSame($to, $common);
}
}
public function testReversedSequences()
{
$from = ['A', 'B'];
$to = ['B', 'A'];
$expected = ['A'];
$common = $this->implementation->calculate($from, $to);
$this->assertSame($expected, $common);
foreach ($this->stress_sizes as $size) {
$from = \range(1, $size);
$to = \array_reverse($from);
$common = $this->implementation->calculate($from, $to);
$this->assertSame([1], $common);
}
}
public function testStrictTypeCalculate()
{
$diff = $this->implementation->calculate(['5'], ['05']);
$this->assertInternalType('array', $diff);
$this->assertCount(0, $diff);
}
}

View File

@@ -0,0 +1,22 @@
<?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;
/**
* @covers SebastianBergmann\Diff\MemoryEfficientLongestCommonSubsequenceCalculator
*/
final class MemoryEfficientImplementationTest extends LongestCommonSubsequenceTest
{
protected function createImplementation()
{
return new MemoryEfficientLongestCommonSubsequenceCalculator;
}
}

View File

@@ -0,0 +1,151 @@
<?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;
use PHPUnit\Framework\TestCase;
/**
* @covers SebastianBergmann\Diff\Parser
*
* @uses SebastianBergmann\Diff\Chunk
* @uses SebastianBergmann\Diff\Diff
* @uses SebastianBergmann\Diff\Line
*/
final class ParserTest extends TestCase
{
/**
* @var Parser
*/
private $parser;
protected function setUp()
{
$this->parser = new Parser;
}
public function testParse()
{
$content = \file_get_contents(__DIR__ . '/fixtures/patch.txt');
$diffs = $this->parser->parse($content);
$this->assertInternalType('array', $diffs);
$this->assertContainsOnlyInstancesOf(Diff::class, $diffs);
$this->assertCount(1, $diffs);
$chunks = $diffs[0]->getChunks();
$this->assertInternalType('array', $chunks);
$this->assertContainsOnlyInstancesOf(Chunk::class, $chunks);
$this->assertCount(1, $chunks);
$this->assertSame(20, $chunks[0]->getStart());
$this->assertCount(4, $chunks[0]->getLines());
}
public function testParseWithMultipleChunks()
{
$content = \file_get_contents(__DIR__ . '/fixtures/patch2.txt');
$diffs = $this->parser->parse($content);
$this->assertCount(1, $diffs);
$chunks = $diffs[0]->getChunks();
$this->assertCount(3, $chunks);
$this->assertSame(20, $chunks[0]->getStart());
$this->assertSame(320, $chunks[1]->getStart());
$this->assertSame(600, $chunks[2]->getStart());
$this->assertCount(5, $chunks[0]->getLines());
$this->assertCount(5, $chunks[1]->getLines());
$this->assertCount(4, $chunks[2]->getLines());
}
public function testParseWithRemovedLines()
{
$content = <<<A
diff --git a/Test.txt b/Test.txt
index abcdefg..abcdefh 100644
--- a/Test.txt
+++ b/Test.txt
@@ -49,9 +49,8 @@
A
-B
A;
$diffs = $this->parser->parse($content);
$this->assertInternalType('array', $diffs);
$this->assertContainsOnlyInstancesOf(Diff::class, $diffs);
$this->assertCount(1, $diffs);
$chunks = $diffs[0]->getChunks();
$this->assertInternalType('array', $chunks);
$this->assertContainsOnlyInstancesOf(Chunk::class, $chunks);
$this->assertCount(1, $chunks);
$chunk = $chunks[0];
$this->assertSame(49, $chunk->getStart());
$this->assertSame(49, $chunk->getEnd());
$this->assertSame(9, $chunk->getStartRange());
$this->assertSame(8, $chunk->getEndRange());
$lines = $chunk->getLines();
$this->assertInternalType('array', $lines);
$this->assertContainsOnlyInstancesOf(Line::class, $lines);
$this->assertCount(2, $lines);
/** @var Line $line */
$line = $lines[0];
$this->assertSame('A', $line->getContent());
$this->assertSame(Line::UNCHANGED, $line->getType());
$line = $lines[1];
$this->assertSame('B', $line->getContent());
$this->assertSame(Line::REMOVED, $line->getType());
}
public function testParseDiffForMulitpleFiles()
{
$content = <<<A
diff --git a/Test.txt b/Test.txt
index abcdefg..abcdefh 100644
--- a/Test.txt
+++ b/Test.txt
@@ -1,3 +1,2 @@
A
-B
diff --git a/Test123.txt b/Test123.txt
index abcdefg..abcdefh 100644
--- a/Test2.txt
+++ b/Test2.txt
@@ -1,2 +1,3 @@
A
+B
A;
$diffs = $this->parser->parse($content);
$this->assertCount(2, $diffs);
/** @var Diff $diff */
$diff = $diffs[0];
$this->assertSame('a/Test.txt', $diff->getFrom());
$this->assertSame('b/Test.txt', $diff->getTo());
$this->assertCount(1, $diff->getChunks());
$diff = $diffs[1];
$this->assertSame('a/Test2.txt', $diff->getFrom());
$this->assertSame('b/Test2.txt', $diff->getTo());
$this->assertCount(1, $diff->getChunks());
}
}

View File

@@ -0,0 +1,22 @@
<?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;
/**
* @covers SebastianBergmann\Diff\TimeEfficientLongestCommonSubsequenceCalculator
*/
final class TimeEfficientImplementationTest extends LongestCommonSubsequenceTest
{
protected function createImplementation()
{
return new TimeEfficientLongestCommonSubsequenceCalculator;
}
}

View File

@@ -0,0 +1,9 @@
diff --git a/Foo.php b/Foo.php
index abcdefg..abcdefh 100644
--- a/Foo.php
+++ b/Foo.php
@@ -20,4 +20,5 @@ class Foo
const ONE = 1;
const TWO = 2;
+ const THREE = 3;
const FOUR = 4;

View File

@@ -0,0 +1,21 @@
diff --git a/Foo.php b/Foo.php
index abcdefg..abcdefh 100644
--- a/Foo.php
+++ b/Foo.php
@@ -20,4 +20,5 @@ class Foo
const ONE = 1;
const TWO = 2;
+ const THREE = 3;
const FOUR = 4;
@@ -320,4 +320,5 @@ class Foo
const A = 'A';
const B = 'B';
+ const C = 'C';
const D = 'D';
@@ -600,4 +600,5 @@ class Foo
public function doSomething() {
+ return 'foo';
}