Completed
Push — master ( b6fc24...3c2867 )
by Michal
07:33
created

PMATestCase::setUpBeforeClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/* vim: set expandtab sw=4 ts=4 sts=4: */
3
/**
4
 * Base class for phpMyAdmin tests
5
 *
6
 * @package PhpMyAdmin-test
7
 */
8
9
class PMATestCase extends PHPUnit_Framework_TestCase
10
{
11
    protected $restoreInstance = null;
12
    protected $attrInstance = null;
13
14
    /**
15
     * This method is called before the first test of this test class is run.
16
     */
17
    public static function setUpBeforeClass()
18
    {
19
        require 'libraries/config.default.php';
20
        $GLOBALS['cfg'] = $cfg;
0 ignored issues
show
Bug introduced by
The variable $cfg does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
21
    }
22
23
    /**
24
     * Creates mock of Response object for header testing
25
     *
26
     * @param mixed $param parameter for header method
27
     *
28
     * @return void
29
     */
30
    public function mockResponse($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

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

Loading history...
31
    {
32
        $this->restoreInstance = PMA\libraries\Response::getInstance();
33
34
        $mockResponse = $this->getMockBuilder('PMA\libraries\Response')
35
            ->disableOriginalConstructor()
36
            ->setMethods(array('header', 'headersSent', 'disable', 'isAjax'))
37
            ->getMock();
38
39
        $mockResponse->expects($this->any())
40
            ->method('headersSent')
41
            ->with()
42
            ->will($this->returnValue(false));
43
44
        $param = func_get_args();
45
46
        if (is_array($param[0])) {
47
            $header_method = $mockResponse->expects($this->exactly(count($param)))
48
                ->method('header');
49
50
            call_user_func_array(array($header_method, 'withConsecutive'), $param);
51
        } else {
52
            $mockResponse->expects($this->once())
53
                ->method('header')
54
                ->with($param[0]);
55
        }
56
57
        $this->attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance');
58
        $this->attrInstance->setAccessible(true);
59
        $this->attrInstance->setValue($mockResponse);
60
    }
61
62
    /**
63
     *Tear down function for mockResponse method
64
     *
65
     *@return void
66
     */
67
    protected function tearDown()
68
    {
69
        if (! is_null($this->attrInstance) && ! is_null($this->restoreInstance)) {
70
            $this->attrInstance->setValue($this->restoreInstance);
71
            $this->restoreInstance = null;
72
            $this->attrInstance = null;
73
        }
74
    }
75
}
76