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

CopyMethodTest::testCopy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\VendorPlugin\Tests\Methods;
4
5
use Composer\Util\Filesystem;
6
use PHPUnit\Framework\TestCase;
7
use SilverStripe\VendorPlugin\Methods\CopyMethod;
8
use SilverStripe\VendorPlugin\Methods\SymlinkMethod;
9
use SilverStripe\VendorPlugin\Util;
10
11
class CopyMethodTest extends TestCase
12
{
13
    /**
14
     * @var Filesystem
15
     */
16
    protected $filesystem = null;
17
18
    /**
19
     * @var string app base path
20
     */
21
    protected $root = null;
22
23
    protected function setUp()
24
    {
25
        parent::setUp();
26
27
        // Get temp dir
28
        $this->root = Util::joinPaths(
29
            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

29
            /** @scrutinizer ignore-type */ sys_get_temp_dir(),
Loading history...
30
            'CopyMethodTest',
31
            substr(sha1(uniqid()), 0, 10)
32
        );
33
34
        // Setup filesystem
35
        $this->filesystem = new Filesystem();
36
        $this->filesystem->ensureDirectoryExists($this->root);
37
    }
38
39
    protected function tearDown()
40
    {
41
        $this->filesystem->remove($this->root);
42
        parent::tearDown();
43
    }
44
45
    public function testCopy()
46
    {
47
        $method = new CopyMethod();
48
        $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

48
        $target = Util::joinPaths(/** @scrutinizer ignore-type */ $this->root, 'resources', 'client');
Loading history...
49
        $method->exposeDirectory(
50
            realpath(__DIR__.'/../fixtures/source/client'),
51
            $target
52
        );
53
54
        // Ensure file exists
55
        $this->assertFileExists(Util::joinPaths($this->root, 'resources', 'client', 'subfolder', 'somefile.txt'));
56
57
        // Folder is a real folder and not a symlink
58
        $this->assertFalse($this->filesystem->isSymlinkedDirectory($target));
59
        $this->assertDirectoryExists($target);
60
61
62
        // Parent folder is a real folder
63
        $this->assertFalse($this->filesystem->isSymlinkedDirectory(dirname($target)));
64
        $this->assertDirectoryExists(dirname($target));
65
    }
66
67
    public function testRecoversFromSymlink()
68
    {
69
        $method = new SymlinkMethod();
70
        $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

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