Completed
Push — master ( 87b7a4...6ce28d )
by Gaetano
11:11 queued 06:38
created

PhpXmlRpc_LocalFileTestCase   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 39
c 2
b 0
f 0
dl 0
loc 73
rs 10
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 26 3
A request() 0 34 5
1
<?php
2
3
include_once __DIR__ . '/parse_args.php';
4
5
abstract class PhpXmlRpc_LocalFileTestCase extends PHPUnit_Framework_TestCase
6
{
7
    public $args = array();
8
9
    protected $baseUrl;
10
11
    protected $testId;
12
    /** @var boolean $collectCodeCoverageInformation */
13
    protected $collectCodeCoverageInformation;
14
    protected $coverageScriptUrl;
15
16
    public function run(PHPUnit_Framework_TestResult $result = NULL)
17
    {
18
        $this->testId = get_class($this) . '__' . $this->getName();
19
20
        if ($result === NULL) {
21
            $result = $this->createResult();
22
        }
23
24
        $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
25
26
        parent::run($result);
27
28
        if ($this->collectCodeCoverageInformation) {
29
            $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
30
                $this->coverageScriptUrl,
31
                $this->testId
32
            );
33
            $result->getCodeCoverage()->append(
34
                $coverage->get(), $this
35
            );
36
        }
37
38
        // do not call this before to give the time to the Listeners to run
39
        //$this->getStrategy()->endOfTest($this->session);
40
41
        return $result;
42
    }
43
44
    protected function request($file, $method = 'GET', $payload = '', $emptyPageOk = false)
45
    {
46
        $url = $this->baseUrl . $file;
47
48
        $ch = curl_init($url);
49
        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

49
        curl_setopt_array(/** @scrutinizer ignore-type */ $ch, array(
Loading history...
50
            CURLOPT_RETURNTRANSFER => true,
51
            CURLOPT_FAILONERROR => true
52
        ));
53
        if ($method == 'POST')
54
        {
55
            curl_setopt_array($ch, array(
56
                CURLOPT_POST => true,
57
                CURLOPT_POSTFIELDS => $payload
58
            ));
59
        }
60
        if ($this->collectCodeCoverageInformation)
61
        {
62
            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

62
            curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true');
Loading history...
63
        }
64
        if ($this->args['DEBUG'] > 0) {
65
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
66
        }
67
        $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

67
        $page = curl_exec(/** @scrutinizer ignore-type */ $ch);
Loading history...
68
        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

68
        curl_close(/** @scrutinizer ignore-type */ $ch);
Loading history...
69
70
        $this->assertNotFalse($page);
0 ignored issues
show
Bug introduced by
It seems like $page can also be of type string; however, parameter $condition of PHPUnit_Framework_Assert::assertNotFalse() does only seem to accept boolean, 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

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