File: ChunkTest.php

package info (click to toggle)
phpunit-diff 7.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 29,932 kB
  • sloc: php: 4,348; xml: 47; makefile: 15
file content (85 lines) | stat: -rw-r--r-- 1,982 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?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\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(Chunk::class)]
#[UsesClass(Line::class)]
#[Small]
final class ChunkTest extends TestCase
{
    public function testHasLines(): void
    {
        $this->assertEquals([$this->line()], $this->chunk()->lines());
    }

    public function testHasStart(): void
    {
        $this->assertSame(1, $this->chunk()->start());
    }

    public function testHasStartRange(): void
    {
        $this->assertSame(2, $this->chunk()->startRange());
    }

    public function testHasEnd(): void
    {
        $this->assertSame(3, $this->chunk()->end());
    }

    public function testHasEndRange(): void
    {
        $this->assertSame(4, $this->chunk()->endRange());
    }

    public function testLinesCanBeSet(): void
    {
        $chunk = $this->chunk();
        $lines = [new Line(Line::ADDED, 'added'), new Line(Line::REMOVED, 'removed')];

        $chunk->setLines($lines);

        $this->assertSame($lines, $chunk->lines());
    }

    public function testCanBeIterated(): void
    {
        $line  = new Line;
        $chunk = new Chunk(lines: [$line]);

        foreach ($chunk as $index => $_line) {
            $this->assertSame(0, $index);
            $this->assertSame($line, $_line);
        }
    }

    private function chunk(): Chunk
    {
        return new Chunk(
            1,
            2,
            3,
            4,
            [
                $this->line(),
            ],
        );
    }

    private function line(): Line
    {
        return new Line(Line::ADDED, 'content');
    }
}