Passed
Push — master ( 573db6...fc8ac8 )
by Gaetano
10:15
created

PhpXmlRpc_ServerAwareTestCase   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 37
c 2
b 0
f 0
dl 0
loc 96
rs 10
wmc 10

5 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
A getClient() 0 18 3
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
    protected function getClient($customPath)
0 ignored issues
show
Unused Code introduced by
The parameter $customPath is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

86
    protected function getClient(/** @scrutinizer ignore-unused */ $customPath)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
87
    {
88
        $server = explode(':', $this->args['HTTPSERVER']);
89
        if (count($server) > 1) {
90
            $client = new xmlrpc_client($this->args['HTTPURI'], $server[0], $server[1]);
0 ignored issues
show
Bug introduced by
$server[1] of type string is incompatible with the type integer expected by parameter $port of xmlrpc_client::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

90
            $client = new xmlrpc_client($this->args['HTTPURI'], $server[0], /** @scrutinizer ignore-type */ $server[1]);
Loading history...
91
        } else {
92
            $client = new xmlrpc_client($this->args['HTTPURI'], $this->args['HTTPSERVER']);
93
        }
94
95
        $client->setDebug($this->args['DEBUG']);
96
97
        $client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId);
98
99
        if ($this->collectCodeCoverageInformation) {
100
            $client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
101
        }
102
103
        return $client;
104
    }
105
}
106