phpmyadmin/test/classes/PmaTestCase.php
William Desportes e816e45c18 phpstan level 0 (#14405)
* Fix phpdoc @return

- Fixed @return typehint

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Fix incorrect case on function calls

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Type hint + typo fix

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Fixes

- @return fix
- @var fix
- Class names
- Throws fix
- test/classes/Plugins/Export/ExportSqlTest.php any() invoked with 1 parameter, 0 required
-  libraries/classes/Controllers/Table/TableStructureController.php Array has 2 duplicate keys with value 'columns_list'
- Call parent constructor  libraries/classes/Error.php

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Update config

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Access to an undefined property

- Access to an undefined property PhpMyAdmin\Plugins\Schema\Pdf\PdfRelationSchema::$diagram_row
- Access to an undefined property PhpMyAdmin\Plugins\Schema\Pdf\Pdf::$cMargin
- Undefined properties

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Update config

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Fix bootstrap-phpstan

Signed-off-by: William Desportes <williamdes@wdes.fr>

* Fix typos and phpstan config

Fixes: #14399
Signed-off-by: William Desportes <williamdes@wdes.fr>
2018-06-25 20:34:46 -03:00

113 lines
3.1 KiB
PHP

<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Base class for phpMyAdmin tests
*
* @package PhpMyAdmin-test
*/
declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\Response;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
/**
* Base class for phpMyAdmin tests
*
* @package PhpMyAdmin-test
*/
class PmaTestCase extends TestCase
{
/**
* @var Response
*/
protected $restoreInstance = null;
/**
* @var Response
*/
protected $attrInstance = null;
/**
* This method is called before the first test of this test class is run.
*
* @return void
*/
public static function setUpBeforeClass()
{
require 'libraries/config.default.php';
$GLOBALS['cfg'] = $cfg;
}
/**
* Creates mock of Response object for header testing
*
* @param mixed ... $param parameter for header method
*
* @return \PHPUnit\Framework\MockObject\MockBuilder
*/
public function mockResponse(...$param)
{
$this->restoreInstance = Response::getInstance();
$mockResponse = $this->getMockBuilder('PhpMyAdmin\Response')
->disableOriginalConstructor()
->setMethods([
'header', 'headersSent', 'disable', 'isAjax',
'setRequestStatus', 'addJSON', 'addHTML',
'getFooter', 'getHeader','httpResponseCode',
])
->getMock();
$mockResponse->expects($this->any())
->method('headersSent')
->with()
->will($this->returnValue(false));
if (count($param) > 0) {
if (is_array($param[0])) {
if (is_array($param[0][0]) && count($param) == 1) {
$param = $param[0];
if (is_int(end($param))) {
$http_response_code_param = end($param);
$param = array_slice($param, 0, -1);
$header_method = $mockResponse->expects($this->once())
->method('httpResponseCode')->with($http_response_code_param);
}
}
$header_method = $mockResponse->expects($this->exactly(count($param)))
->method('header');
call_user_func_array([$header_method, 'withConsecutive'], $param);
} else {
$mockResponse->expects($this->once())
->method('header')
->with($param[0]);
}
}
$this->attrInstance = new ReflectionProperty('PhpMyAdmin\Response', '_instance');
$this->attrInstance->setAccessible(true);
$this->attrInstance->setValue($mockResponse);
return $mockResponse;
}
/**
*Tear down function for mockResponse method
*
*@return void
*/
protected function tearDown()
{
if (! is_null($this->attrInstance) && ! is_null($this->restoreInstance)) {
$this->attrInstance->setValue($this->restoreInstance);
$this->restoreInstance = null;
$this->attrInstance = null;
}
}
}