Completed
Push — master ( 9a7b87...ad20a3 )
by Alessandro
03:07
created

PHPUnitBinFile::__construct()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

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