CompilerTest::testRunPhar()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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