Passed
Push — master ( 43c003...f5456e )
by Gaetano
07:42
created

PhpXmlRpc_LocalFileTestCase::run()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 26
rs 9.8666
1
<?php
2
3
include_once __DIR__ . '/parse_args.php';
4
5
include_once __DIR__ . '/PolyfillTestCase.php';
6
7
use PHPUnit\Framework\TestResult;
8
9
abstract class PhpXmlRpc_LocalFileTestCase extends PhpXmlRpc_PolyfillTestCase
10
{
11
    public $args = array();
12
13
    protected $baseUrl;
14
15
    protected $testId;
16
    /** @var boolean $collectCodeCoverageInformation */
17
    protected $collectCodeCoverageInformation;
18
    protected $coverageScriptUrl;
19
20
    public function _run(TestResult $result = NULL)
21
    {
22
        $this->testId = get_class($this) . '__' . $this->getName();
23
24
        if ($result === NULL) {
25
            $result = $this->createResult();
26
        }
27
28
        $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
29
30
        parent::_run($result);
31
32
        if ($this->collectCodeCoverageInformation) {
33
            $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
0 ignored issues
show
Bug introduced by
The type PHPUnit_Extensions_SeleniumCommon_RemoteCoverage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
                $this->coverageScriptUrl,
35
                $this->testId
36
            );
37
            $result->getCodeCoverage()->append(
38
                $coverage->get(), $this
39
            );
40
        }
41
42
        // do not call this before to give the time to the Listeners to run
43
        //$this->getStrategy()->endOfTest($this->session);
44
45
        return $result;
46
    }
47
48
    protected function request($file, $method = 'GET', $payload = '', $emptyPageOk = false)
49
    {
50
        $url = $this->baseUrl . $file;
51
52
        $ch = curl_init($url);
53
        curl_setopt_array($ch, array(
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_setopt_array() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

53
        curl_setopt_array(/** @scrutinizer ignore-type */ $ch, array(
Loading history...
54
            CURLOPT_RETURNTRANSFER => true,
55
            CURLOPT_FAILONERROR => true
56
        ));
57
        if ($method == 'POST')
58
        {
59
            curl_setopt_array($ch, array(
60
                CURLOPT_POST => true,
61
                CURLOPT_POSTFIELDS => $payload
62
            ));
63
        }
64
        if ($this->collectCodeCoverageInformation)
65
        {
66
            curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true');
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_setopt() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

66
            curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true');
Loading history...
67
        }
68
        if ($this->args['DEBUG'] > 0) {
69
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
70
        }
71
        $page = curl_exec($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

71
        $page = curl_exec(/** @scrutinizer ignore-type */ $ch);
Loading history...
72
        curl_close($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

72
        curl_close(/** @scrutinizer ignore-type */ $ch);
Loading history...
73
74
        $this->assertNotFalse($page);
75
        if (!$emptyPageOk) {
76
            $this->assertNotEquals('', $page);
77
        }
78
        $this->assertNotContains('Fatal error', $page);
79
        $this->assertNotContains('Notice:', $page);
80
81
        return $page;
82
    }
83
84
}
85