CompilerTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 4 1
A ensureDirectoryExists() 0 15 4
A testBuildPhar() 0 14 3
A testRunPhar() 0 4 1
1
<?php
2
namespace AlreadyExtract;
3
4
use Symfony\Component\Filesystem\Filesystem;
5
use Symfony\Component\Process\Process;
6
7
class CompilerTest extends \PHPUnit_Framework_TestCase
8
{
9
    private static $pharPath;
10
11
    public static function setUpBeforeClass()
12
    {
13
        self::$pharPath = sys_get_temp_dir().'/already-exist-phar-test/already-extract.phar';
14
    }
15
16
    public function ensureDirectoryExists($directory)
17
    {
18
        if (!is_dir($directory)) {
19
            if (file_exists($directory)) {
20
                throw new \RuntimeException(
21
                    $directory.' exists and is not a directory.'
22
                );
23
            }
24
            if (!@mkdir($directory, 0777, true)) {
25
                throw new \RuntimeException(
26
                    $directory.' does not exist and could not be created.'
27
                );
28
            }
29
        }
30
    }
31
32
    public function testBuildPhar()
33
    {
34
        $fs = new Filesystem;
35
        $fs->remove(dirname(self::$pharPath));
36
        $this->ensureDirectoryExists(dirname(self::$pharPath));
37
        chdir(dirname(self::$pharPath));
38
39
        $proc = new Process('php '.escapeshellarg(__DIR__ . '/../../bin/compile'), dirname(self::$pharPath));
40
        $exitcode = $proc->run();
41
        if ($exitcode !== 0 || trim($proc->getOutput())) {
42
            $this->fail($proc->getOutput());
43
        }
44
        $this->assertTrue(file_exists(self::$pharPath));
45
    }
46
47
    public function testRunPhar()
48
    {
49
        $this->assertTrue(true);
50
    }
51
}
52