Completed
Pull Request — master (#62)
by Alessandro
09:23
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
    // I'm using Paraunit in a PHAR
16
    const PHPUNIT_RELPATH_FOR_PHAR = 'vendor/phpunit/phpunit/phpunit';
17
18
    /** @var string Realpath to PHPUnit bin location */
19
    private $phpUnitBin;
20
21
    /**
22
     * PHPUnitBinFile constructor.
23
     */
24 11
    public function __construct()
25
    {
26 11
        if (file_exists(__DIR__.self::PHPUNIT_RELPATH_FOR_VENDOR)) {
27
            $this->phpUnitBin = __DIR__.self::PHPUNIT_RELPATH_FOR_VENDOR;
28 11
        } elseif (file_exists(__DIR__.self::PHPUNIT_RELPATH_FOR_STANDALONE)) {
29 11
            $this->phpUnitBin = __DIR__.self::PHPUNIT_RELPATH_FOR_STANDALONE;
30 11
        } elseif (file_exists(self::PHPUNIT_RELPATH_FOR_PHAR)) {
31
            $this->phpUnitBin = self::PHPUNIT_RELPATH_FOR_PHAR;
32
        } else {
33
            throw new \Exception('PHPUnit bin not found');
34
        }
35
36 11
        $this->phpUnitBin = realpath($this->phpUnitBin);
37 11
    }
38
39
    /**
40
     * @return string
41
     */
42 11
    public function getPhpUnitBin()
43
    {
44 11
        return $this->phpUnitBin;
45
    }
46
}
47