Completed
Pull Request — master (#45)
by
unknown
06:12
created

PHPUnitBinFile::getPhpUnitBin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Paraunit\Configuration;
4
5
/**
6
 * Class PHPUnitBinFile
7
 * @package Paraunit\Configuration
8
 */
9
class PHPUnitBinFile
10
{
11
    // I'm using Paraunit as a vendor package
12
    const PHPUNIT_RELPATH_FOR_VENDOR = '/../../../../../phpunit/phpunit/phpunit';
13
    // I'm using Paraunit standalone (developing)
14
    const PHPUNIT_RELPATH_FOR_STANDALONE = '/../../../vendor/phpunit/phpunit/phpunit';
15
16
    /** @var string Realpath to PHPUnit bin location */
17
    private $phpUnitBin;
18
19
    /**
20
     * PHPUnitBinFile constructor.
21
     */
22 10
    public function __construct()
23
    {
24 10
        if (defined('PARAUNIT_PHAR_FILE')) {
25
            // Paraunit is running as standalone PHAR archive
26
            // PHPUnit is embedded in the archive, self execute it in special mode
27
            $this->phpUnitBin = PARAUNIT_PHAR_FILE . ' phpunit';
28
            return;
29
        }
30
31 10
        if (file_exists(__DIR__.self::PHPUNIT_RELPATH_FOR_VENDOR)) {
32
            $this->phpUnitBin = __DIR__.self::PHPUNIT_RELPATH_FOR_VENDOR;
33 10
        } elseif (file_exists(__DIR__.self::PHPUNIT_RELPATH_FOR_STANDALONE)) {
34 10
            $this->phpUnitBin = __DIR__.self::PHPUNIT_RELPATH_FOR_STANDALONE;
35 10
        } else {
36
            throw new \Exception('PHPUnit bin not found');
37
        }
38
39 10
        $this->phpUnitBin = realpath($this->phpUnitBin);
40 10
    }
41
42
    /**
43
     * @return string
44
     */
45 10
    public function getPhpUnitBin()
46
    {
47 10
        return $this->phpUnitBin;
48
    }
49
}
50