ChainedMethodTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 62
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 14 1
A tearDown() 0 4 1
A testFailover() 0 28 1
1
<?php
2
3
namespace SilverStripe\VendorPlugin\Tests\Methods;
4
5
use Composer\Util\Filesystem;
6
use PHPUnit\Framework\TestCase;
7
use RuntimeException;
8
use SilverStripe\VendorPlugin\Methods\ChainedMethod;
9
use SilverStripe\VendorPlugin\Methods\CopyMethod;
10
use SilverStripe\VendorPlugin\Util;
11
12
class ChainedMethodTest 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(),
31
            'ChainedMethodTest',
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 testFailover()
47
    {
48
        $failingMethod = $this->createMock(CopyMethod::class);
49
        $failingMethod
50
            ->method('exposeDirectory')
51
            ->willThrowException(new RuntimeException());
52
53
        // Create eventually successful method
54
        $method = new ChainedMethod($failingMethod, new CopyMethod());
55
56
        // Expose
57
        $target = Util::joinPaths($this->root, 'resources', 'client');
58
        $method->exposeDirectory(
59
            realpath(__DIR__.'/../fixtures/source/client'),
60
            $target
61
        );
62
63
        // Ensure file exists
64
        $this->assertFileExists(Util::joinPaths($this->root, 'resources', 'client', 'subfolder', 'somefile.txt'));
65
66
        // Folder is a real folder and not a symlink
67
        $this->assertFalse($this->filesystem->isSymlinkedDirectory($target));
68
        $this->assertDirectoryExists($target);
69
70
71
        // Parent folder is a real folder
72
        $this->assertFalse($this->filesystem->isSymlinkedDirectory(dirname($target)));
73
        $this->assertDirectoryExists(dirname($target));
74
    }
75
}
76