Skip to content

Commit 8c8dbdb

Browse files
Implement SebastianBergmann\Diff\Line::isAdded(), SebastianBergmann\Diff\Line::isRemoved(), and SebastianBergmann\Diff\Line::isUnchanged()
1 parent 10b0765 commit 8c8dbdb

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
99
* `SebastianBergmann\Diff\Chunk::start()`, `SebastianBergmann\Diff\Chunk::startRange()`, `SebastianBergmann\Diff\Chunk::end()`, `SebastianBergmann\Diff\Chunk::endRange()`, and `SebastianBergmann\Diff\Chunk::lines()`
1010
* `SebastianBergmann\Diff\Diff::from()`, `SebastianBergmann\Diff\Diff::to()`, and `SebastianBergmann\Diff\Diff::chunks()`
1111
* `SebastianBergmann\Diff\Line::content()` and `SebastianBergmann\Diff\Diff::type()`
12+
* `SebastianBergmann\Diff\Line::isAdded()`,`SebastianBergmann\Diff\Line::isRemoved()`, and `SebastianBergmann\Diff\Line::isUnchanged()`
1213

1314
### Deprecated
1415

src/Line.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ public function type(): int
3333
return $this->type;
3434
}
3535

36+
public function isAdded(): bool
37+
{
38+
return $this->type === self::ADDED;
39+
}
40+
41+
public function isRemoved(): bool
42+
{
43+
return $this->type === self::REMOVED;
44+
}
45+
46+
public function isUnchanged(): bool
47+
{
48+
return $this->type === self::UNCHANGED;
49+
}
50+
3651
/**
3752
* @deprecated
3853
*/

tests/LineTest.php

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,61 @@
1010
namespace SebastianBergmann\Diff;
1111

1212
use PHPUnit\Framework\Attributes\CoversClass;
13+
use PHPUnit\Framework\Attributes\Small;
1314
use PHPUnit\Framework\TestCase;
1415

1516
#[CoversClass(Line::class)]
17+
#[Small]
1618
final class LineTest extends TestCase
1719
{
18-
private Line $line;
20+
public function testCanBeOfTypeAdded(): void
21+
{
22+
$this->assertSame(Line::ADDED, $this->added()->type());
23+
$this->assertSame(Line::ADDED, $this->added()->getType());
24+
25+
$this->assertTrue($this->added()->isAdded());
26+
$this->assertFalse($this->added()->isRemoved());
27+
$this->assertFalse($this->added()->isUnchanged());
28+
}
29+
30+
public function testCanBeOfTypeRemoved(): void
31+
{
32+
$this->assertSame(Line::REMOVED, $this->removed()->type());
33+
$this->assertSame(Line::REMOVED, $this->removed()->getType());
34+
35+
$this->assertTrue($this->removed()->isRemoved());
36+
$this->assertFalse($this->removed()->isAdded());
37+
$this->assertFalse($this->removed()->isUnchanged());
38+
}
39+
40+
public function testCanBeOfTypeUnchanged(): void
41+
{
42+
$this->assertSame(Line::UNCHANGED, $this->unchanged()->type());
43+
$this->assertSame(Line::UNCHANGED, $this->unchanged()->getType());
44+
45+
$this->assertTrue($this->unchanged()->isUnchanged());
46+
$this->assertFalse($this->unchanged()->isAdded());
47+
$this->assertFalse($this->unchanged()->isRemoved());
48+
}
1949

20-
protected function setUp(): void
50+
public function testHasContent(): void
2151
{
22-
$this->line = new Line;
52+
$this->assertSame('content', $this->added()->content());
53+
$this->assertSame('content', $this->added()->getContent());
2354
}
2455

25-
public function testCanBeCreatedWithoutArguments(): void
56+
private function added(): Line
2657
{
27-
$this->assertInstanceOf(Line::class, $this->line);
58+
return new Line(Line::ADDED, 'content');
2859
}
2960

30-
public function testTypeCanBeRetrieved(): void
61+
private function removed(): Line
3162
{
32-
$this->assertSame(Line::UNCHANGED, $this->line->type());
33-
$this->assertSame(Line::UNCHANGED, $this->line->getType());
63+
return new Line(Line::REMOVED, 'content');
3464
}
3565

36-
public function testContentCanBeRetrieved(): void
66+
private function unchanged(): Line
3767
{
38-
$this->assertSame('', $this->line->content());
39-
$this->assertSame('', $this->line->getContent());
68+
return new Line(Line::UNCHANGED, 'content');
4069
}
4170
}

0 commit comments

Comments
 (0)