Passed
Push — master ( 02b7f4...c1cbf5 )
by Gaetano
07:18
created

PhpXmlRpc_ServerAwareTestCase::set_up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
include_once __DIR__ . '/LogAwareTestCase.php';
4
5
use PHPUnit\Extensions\SeleniumCommon\RemoteCoverage;
6
use PHPUnit\Framework\TestResult;
7
8
abstract class PhpXmlRpc_ServerAwareTestCase extends PhpXmlRpc_LogAwareTestCase
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
    /**
20
     * Reimplemented to allow us to collect code coverage info from the target server.
21
     * Code taken from PHPUnit_Extensions_Selenium2TestCase
22
     *
23
     * @param TestResult $result
24
     * @return TestResult
25
     * @throws Exception
26
     *
27
     * @todo instead of overriding run via _run, try to achieve this by implementing Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation
28
     */
29
    public function _run($result = NULL)
30
    {
31
        $this->testId = get_class($this) . '__' . $this->getName();
32
33
        if ($result === NULL) {
34
            $result = $this->createResult();
35
        }
36
37
        $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
38
39
        parent::_run($result);
40
41
        if ($this->collectCodeCoverageInformation) {
42
            $coverage = new RemoteCoverage(
43
                $this->coverageScriptUrl,
44
                $this->testId
45
            );
46
            $result->getCodeCoverage()->append(
47
                $coverage->get(), $this
48
            );
49
        }
50
51
        // do not call this before to give the time to the Listeners to run
52
        //$this->getStrategy()->endOfTest($this->session);
53
54
        return $result;
55
    }
56
57
    public function set_up()
58
    {
59
        parent::set_up();
60
61
        // assumes HTTPURI to be in the form /tests/index.php?etc...
62
        $this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
63
        $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
64
    }
65
}
66