Skip to content

Commit 0adf6e5

Browse files
authored
Port changes from upstream (#13)
1 parent ad7130c commit 0adf6e5

7 files changed

+35
-15
lines changed

src/Chunk.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class Chunk
3333
private $endRange;
3434

3535
/**
36-
* @var array
36+
* @var Line[]
3737
*/
3838
private $lines;
3939

@@ -66,13 +66,25 @@ public function getEndRange()
6666
return $this->endRange;
6767
}
6868

69+
/**
70+
* @return Line[]
71+
*/
6972
public function getLines()
7073
{
7174
return $this->lines;
7275
}
7376

77+
/**
78+
* @param Line[] $lines
79+
*/
7480
public function setLines(array $lines)
7581
{
82+
foreach ($lines as $line) {
83+
if (!$line instanceof Line) {
84+
throw new InvalidArgumentException;
85+
}
86+
}
87+
7688
$this->lines = $lines;
7789
}
7890
}

tests/ChunkTest.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
/**
1616
* @covers PhpCsFixer\Diff\Chunk
17+
*
18+
* @uses PhpCsFixer\Diff\Line
1719
*/
1820
final class ChunkTest extends TestCase
1921
{
@@ -27,6 +29,11 @@ protected function setUp()
2729
$this->chunk = new Chunk;
2830
}
2931

32+
public function testHasInitiallyNoLines()
33+
{
34+
$this->assertSame([], $this->chunk->getLines());
35+
}
36+
3037
public function testCanBeCreatedWithoutArguments()
3138
{
3239
$this->assertInstanceOf(Chunk::class, $this->chunk);
@@ -59,10 +66,10 @@ public function testLinesCanBeRetrieved()
5966

6067
public function testLinesCanBeSet()
6168
{
62-
$this->assertSame([], $this->chunk->getLines());
69+
$lines = [new Line(Line::ADDED, 'added'), new Line(Line::REMOVED, 'removed')];
70+
71+
$this->chunk->setLines($lines);
6372

64-
$testValue = ['line0', 'line1'];
65-
$this->chunk->setLines($testValue);
66-
$this->assertSame($testValue, $this->chunk->getLines());
73+
$this->assertSame($lines, $this->chunk->getLines());
6774
}
6875
}

tests/LongestCommonSubsequenceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ abstract class LongestCommonSubsequenceTest extends TestCase
3535
protected function setUp()
3636
{
3737
$this->memoryLimit = \ini_get('memory_limit');
38-
\ini_set('memory_limit', '256M');
38+
\ini_set('memory_limit', '-1');
3939

4040
$this->implementation = $this->createImplementation();
4141
}

tests/Output/Integration/StrictUnifiedDiffOutputBuilderIntegrationTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*
2222
* @uses PhpCsFixer\Diff\Differ
2323
* @uses PhpCsFixer\Diff\TimeEfficientLongestCommonSubsequenceCalculator
24+
* @uses PhpCsFixer\Diff\MemoryEfficientLongestCommonSubsequenceCalculator
2425
*
2526
* @requires OS Linux
2627
*/

tests/Output/StrictUnifiedDiffOutputBuilderTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* @covers PhpCsFixer\Diff\Output\StrictUnifiedDiffOutputBuilder
2020
*
2121
* @uses PhpCsFixer\Diff\Differ
22+
* @uses PhpCsFixer\Diff\TimeEfficientLongestCommonSubsequenceCalculator
23+
* @uses PhpCsFixer\Diff\ConfigurationException
2224
*/
2325
final class StrictUnifiedDiffOutputBuilderTest extends TestCase
2426
{

tests/ParserTest.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ public function testParse()
3838

3939
$diffs = $this->parser->parse($content);
4040

41-
$this->assertInternalType('array', $diffs);
4241
$this->assertContainsOnlyInstancesOf(Diff::class, $diffs);
4342
$this->assertCount(1, $diffs);
4443

4544
$chunks = $diffs[0]->getChunks();
46-
$this->assertInternalType('array', $chunks);
4745
$this->assertContainsOnlyInstancesOf(Chunk::class, $chunks);
4846

4947
$this->assertCount(1, $chunks);
@@ -75,23 +73,21 @@ public function testParseWithMultipleChunks()
7573

7674
public function testParseWithRemovedLines()
7775
{
78-
$content = <<<A
76+
$content = <<<END
7977
diff --git a/Test.txt b/Test.txt
8078
index abcdefg..abcdefh 100644
8179
--- a/Test.txt
8280
+++ b/Test.txt
8381
@@ -49,9 +49,8 @@
8482
A
8583
-B
86-
A;
84+
END;
8785
$diffs = $this->parser->parse($content);
88-
$this->assertInternalType('array', $diffs);
8986
$this->assertContainsOnlyInstancesOf(Diff::class, $diffs);
9087
$this->assertCount(1, $diffs);
9188

9289
$chunks = $diffs[0]->getChunks();
9390

94-
$this->assertInternalType('array', $chunks);
9591
$this->assertContainsOnlyInstancesOf(Chunk::class, $chunks);
9692
$this->assertCount(1, $chunks);
9793

@@ -102,7 +98,6 @@ public function testParseWithRemovedLines()
10298
$this->assertSame(8, $chunk->getEndRange());
10399

104100
$lines = $chunk->getLines();
105-
$this->assertInternalType('array', $lines);
106101
$this->assertContainsOnlyInstancesOf(Line::class, $lines);
107102
$this->assertCount(2, $lines);
108103

@@ -118,7 +113,7 @@ public function testParseWithRemovedLines()
118113

119114
public function testParseDiffForMulitpleFiles()
120115
{
121-
$content = <<<A
116+
$content = <<<END
122117
diff --git a/Test.txt b/Test.txt
123118
index abcdefg..abcdefh 100644
124119
--- a/Test.txt
@@ -134,7 +129,7 @@ public function testParseDiffForMulitpleFiles()
134129
@@ -1,2 +1,3 @@
135130
A
136131
+B
137-
A;
132+
END;
138133
$diffs = $this->parser->parse($content);
139134
$this->assertCount(2, $diffs);
140135

tests/Utils/UnifiedDiffAssertTrait.php

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function assertValidUnifiedDiffFormat($diff)
2727

2828
// test diff ends with a line break
2929
$last = \substr($diff, -1);
30+
3031
if ("\n" !== $last && "\r" !== $last) {
3132
throw new \UnexpectedValueException(\sprintf('Expected diff to end with a line break, got "%s".', $last));
3233
}
@@ -130,6 +131,7 @@ public function assertValidUnifiedDiffFormat($diff)
130131
}
131132

132133
$previousType = $this->unifiedDiffAssertLinePrefix($lines[$lineNumber - 2], \sprintf('Preceding line of "\\ No newline at end of file" of unexpected format. Line %d.', $lineNumber));
134+
133135
if (isset($endOfLineTypes[$previousType])) {
134136
throw new \UnexpectedValueException(\sprintf('Unexpected "\\ No newline at end of file", "%s" was already closed. Line %d.', $type, $lineNumber));
135137
}
@@ -190,6 +192,7 @@ private function unifiedDiffAssertLinePrefix($line, $message)
190192
private function unifiedDiffAssertStrLength($line, $min, $message)
191193
{
192194
$length = \strlen($line);
195+
193196
if ($length < $min) {
194197
throw new \UnexpectedValueException(\sprintf('Expected string length of minimal %d, got %d. %s', $min, $length, $message));
195198
}

0 commit comments

Comments
 (0)