Completed
Push — master ( ec27b7...6deef1 )
by Damian
11s
created

SymlinkMethodTest::testSymlink()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\VendorPlugin\Tests\Methods;
4
5
use Composer\Util\Filesystem;
6
use Composer\Util\Platform;
7
use PHPUnit\Framework\TestCase;
8
use SilverStripe\VendorPlugin\Methods\CopyMethod;
9
use SilverStripe\VendorPlugin\Methods\SymlinkMethod;
10
use SilverStripe\VendorPlugin\Util;
11
12
class SymlinkMethodTest extends TestCase
13
{
14
    /**
15
     * @var Filesystem
16
     */
17
    protected $filesystem = null;
18
19
    /**
20
     * @var string app base path
21
     */
22
    protected $root = null;
23
24
    protected function setUp()
25
    {
26
        parent::setUp();
27
28
        // Get temp dir
29
        $this->root = Util::joinPaths(
30
            sys_get_temp_dir(),
0 ignored issues
show
Bug introduced by
sys_get_temp_dir() of type string is incompatible with the type array expected by parameter $parts of SilverStripe\VendorPlugin\Util::joinPaths(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
            /** @scrutinizer ignore-type */ sys_get_temp_dir(),
Loading history...
31
            'SymlinkMethodTest',
32
            substr(sha1(uniqid()), 0, 10)
33
        );
34
35
        // Setup filesystem
36
        $this->filesystem = new Filesystem();
37
        $this->filesystem->ensureDirectoryExists($this->root);
38
    }
39
40
    protected function tearDown()
41
    {
42
        $this->filesystem->remove($this->root);
43
        parent::tearDown();
44
    }
45
46
    public function testSymlink()
47
    {
48
        $method = new SymlinkMethod();
49
        $target = Util::joinPaths($this->root, 'resources', 'client');
0 ignored issues
show
Bug introduced by
$this->root of type string is incompatible with the type array expected by parameter $parts of SilverStripe\VendorPlugin\Util::joinPaths(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
        $target = Util::joinPaths(/** @scrutinizer ignore-type */ $this->root, 'resources', 'client');
Loading history...
50
        $method->exposeDirectory(
51
            realpath(__DIR__.'/../fixtures/source/client'),
52
            $target
53
        );
54
55
        // Ensure file exists
56
        $this->assertFileExists(Util::joinPaths($this->root, 'resources', 'client', 'subfolder', 'somefile.txt'));
57
58
        // Folder is NOT a real folder
59
        if (Platform::isWindows()) {
60
            $this->assertTrue($this->filesystem->isJunction($target));
61
        } else {
62
            $this->assertTrue($this->filesystem->isSymlinkedDirectory($target));
63
        }
64
65
        // Parent folder is a real folder
66
        $this->assertDirectoryExists(dirname($target));
67
    }
68
69
    public function testRecoversFromCopy()
70
    {
71
        $method = new CopyMethod();
72
        $target = Util::joinPaths($this->root, 'resources', 'client');
0 ignored issues
show
Bug introduced by
$this->root of type string is incompatible with the type array expected by parameter $parts of SilverStripe\VendorPlugin\Util::joinPaths(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
        $target = Util::joinPaths(/** @scrutinizer ignore-type */ $this->root, 'resources', 'client');
Loading history...
73
        $method->exposeDirectory(
74
            realpath(__DIR__.'/../fixtures/source/client'),
75
            $target
76
        );
77
78
        // Repeat prior test
79
        $this->testSymlink();
80
    }
81
}
82