Completed
Push — master ( ac98ee...01982b )
by ANTHONIUS
02:45
created

FilesystemTest::testPatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the dotfiles project.
7
 *
8
 *     (c) Anthonius Munthi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Dotfiles\Core\Tests\Util;
15
16
use Dotfiles\Core\Util\Filesystem;
17
use PHPUnit\Framework\TestCase;
18
19
class FilesystemTest extends TestCase
20
{
21
    public function testPatch(): void
22
    {
23
        $fs = new Filesystem();
24
        $current = <<<'EOC'
25
26
export FOO="BAR"
27
28
EOC;
29
        $target = getenv('HOME').'/somefile';
30
        file_put_contents($target, $current, LOCK_EX);
31
        $patch = <<<'EOC'
32
33
export HELLO="WORLD"
34
35
EOC;
36
        // fresh patch test
37
        $fs->patch($target, $patch);
38
        $this->assertFileEquals(__DIR__.'/fixtures/patch-fresh', $target);
39
40
        // test patch when file already patch
41
        $fs->patch($target, 'EXISTING');
42
        $this->assertFileEquals(__DIR__.'/fixtures/patch-exist', $target);
43
    }
44
}
45