PhpXmlRpc_ServerAwareTestCase   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 76
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A _run() 0 26 3
A set_up_before_class() 0 7 1
A tear_down_after_class() 0 7 2
A set_up() 0 7 1
1
<?php
2
3
include_once __DIR__ . '/LoggerAwareTestCase.php';
4
5
use PHPUnit\Extensions\SeleniumCommon\RemoteCoverage;
6
use PHPUnit\Framework\TestResult;
7
8
abstract class PhpXmlRpc_ServerAwareTestCase extends PhpXmlRpc_LoggerAwareTestCase
9
{
10
    /** @var string */
11
    protected $baseUrl;
12
    /** @var string */
13
    protected $testId;
14
    /** @var boolean */
15
    protected $collectCodeCoverageInformation;
16
    /** @var string */
17
    protected $coverageScriptUrl;
18
19
    protected static $randId;
20
21
    /**
22
     * Reimplemented to allow us to collect code coverage info from the target server.
23
     * Code taken from PHPUnit_Extensions_Selenium2TestCase
24
     *
25
     * @param TestResult $result
26
     * @return TestResult
27
     * @throws Exception
28
     *
29
     * @todo instead of overriding run via _run, try to achieve this by implementing Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation
30
     */
31
    public function _run($result = NULL)
32
    {
33
        $this->testId = get_class($this) . '__' . $this->getName();
34
35
        if ($result === NULL) {
36
            $result = $this->createResult();
37
        }
38
39
        $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
40
41
        parent::_run($result);
42
43
        if ($this->collectCodeCoverageInformation) {
44
            $coverage = new RemoteCoverage(
45
                $this->coverageScriptUrl,
46
                $this->testId
47
            );
48
            $result->getCodeCoverage()->append(
49
                $coverage->get(), $this
50
            );
51
        }
52
53
        // do not call this before to give the time to the Listeners to run
54
        //$this->getStrategy()->endOfTest($this->session);
55
56
        return $result;
57
    }
58
59
    public static function set_up_before_class()
60
    {
61
        parent::set_up_before_class();
62
63
        // Set up a database connection or other fixture which needs to be available.
64
        self::$randId = uniqid();
65
        file_put_contents(sys_get_temp_dir() . '/phpunit_rand_id.txt', self::$randId);
66
    }
67
68
    public static function tear_down_after_class()
69
    {
70
        if (is_file(sys_get_temp_dir() . '/phpunit_rand_id.txt')) {
71
            unlink(sys_get_temp_dir() . '/phpunit_rand_id.txt');
72
        }
73
74
        parent::tear_down_after_class();
75
    }
76
77
    public function set_up()
78
    {
79
        parent::set_up();
80
81
        // assumes HTTPURI to be in the form /tests/index.php?etc...
82
        $this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
83
        $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
84
    }
85
}
86