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

PhpXmlRpc_WebTestCase::_run()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 4
nop 1
dl 0
loc 26
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
include_once __DIR__ . '/ServerAwareTestCase.php';
4
5
abstract class PhpXmlRpc_WebTestCase extends PhpXmlRpc_ServerAwareTestCase
6
{
7
    /**
8
     * Make an HTTP request, check that the result is a 200 OK page with no php fatal error or warning messages.
9
     *
10
     * @param string $path
11
     * @param string $method
12
     * @param string $payload
13
     * @param false $emptyPageOk
14
     * @return bool|string
15
     */
16
    protected function request($path, $method = 'GET', $payload = '', $emptyPageOk = false)
17
    {
18
        $url = $this->baseUrl . $path;
19
20
        $ch = curl_init($url);
21
        curl_setopt_array($ch, array(
22
            CURLOPT_RETURNTRANSFER => true,
23
            CURLOPT_FAILONERROR => true
24
        ));
25
        if ($method == 'POST')
26
        {
27
            curl_setopt_array($ch, array(
28
                CURLOPT_POST => true,
29
                CURLOPT_POSTFIELDS => $payload
30
            ));
31
        }
32
        if ($this->collectCodeCoverageInformation)
33
        {
34
            curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID='.$this->testId);
35
        }
36
        if ($this->args['DEBUG'] > 0) {
37
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
38
        }
39
        $page = curl_exec($ch);
40
        curl_close($ch);
41
42
        $this->assertNotFalse($page);
43
        if (!$emptyPageOk) {
0 ignored issues
show
introduced by
The condition $emptyPageOk is always false.
Loading history...
44
            $this->assertNotEquals('', $page);
45
        }
46
        $this->assertStringNotContainsStringIgnoringCase('Fatal error', $page);
0 ignored issues
show
Bug introduced by
It seems like $page can also be of type true; however, parameter $haystack of PHPUnit\Framework\Assert...insStringIgnoringCase() does only seem to accept string, 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

46
        $this->assertStringNotContainsStringIgnoringCase('Fatal error', /** @scrutinizer ignore-type */ $page);
Loading history...
47
        $this->assertStringNotContainsStringIgnoringCase('Notice:', $page);
48
49
        return $page;
50
    }
51
52
    /**
53
     * Build an xml-rpc client, tweaked if needed to collect code-coverage information of the server
54
     *
55
     * @param string $path
56
     * @return \PhpXmlRpc\Client
57
     */
58
    protected function newClient($path)
59
    {
60
        $client = new \PhpXmlRpc\Client($this->baseUrl . $path);
61
        if ($this->collectCodeCoverageInformation) {
62
            $client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
63
        }
64
        // let's just assume that the client works fine for these tests, and avoid polluting output, even in debug mode
65
        //$client->setAcceptedCompression(false);
66
        //$client->setDebug($this->args['DEBUG']);
67
        return $client;
68
    }
69
}
70