first commit
This commit is contained in:
141
tests/functional/bootstrap.php
Normal file
141
tests/functional/bootstrap.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
if (getenv('TEST_SHOP')) {
|
||||
throw new Exception('TEST_SHOP was removed. Use `--testsuite engine` or `shop` instead.');
|
||||
}
|
||||
|
||||
define('TEST_SUITE', getTestSuite());
|
||||
echo 'TEST_SUITE='.TEST_SUITE."\n";
|
||||
|
||||
/* Tells if database query log should be displayed */
|
||||
define('QUERY_LOG', (int) getenv('QUERY_LOG'));
|
||||
echo 'QUERY_LOG='.QUERY_LOG."\n";
|
||||
|
||||
global $cfg, $dbcfg;
|
||||
global $txt_str;
|
||||
$txt_str = [];
|
||||
|
||||
if (!isset($_SESSION)) {
|
||||
$_SESSION = [];
|
||||
}
|
||||
|
||||
// Prepare request superglobals
|
||||
$_SERVER = $_SERVER + [
|
||||
'SERVER_NAME' => 'kupshop.localhost',
|
||||
'QUERY_STRING' => '',
|
||||
'SCRIPT_NAME' => 'index.php',
|
||||
'REMOTE_ADDR' => '127.0.0.1',
|
||||
];
|
||||
|
||||
$shop_dir = getenv('SHOP') ?: __DIR__.'/../../../shop';
|
||||
chdir($shop_dir);
|
||||
|
||||
// Disable stack traces of exception
|
||||
ini_set('xdebug.show_exception_trace', 0);
|
||||
|
||||
$cfg['Cache']['prefix'] = 'tests';
|
||||
|
||||
switch (TEST_SUITE) {
|
||||
case 'shop':
|
||||
require_once './vendor/autoload.php';
|
||||
|
||||
if (file_exists('./config/config.php')) {
|
||||
require_once './config/config.php';
|
||||
} else {
|
||||
require_once './include/config.php';
|
||||
}
|
||||
|
||||
$testConfig = './tests/functional/test.config.php';
|
||||
is_readable($testConfig) && require_once $testConfig;
|
||||
require_once './include/functions.php';
|
||||
break;
|
||||
case 'engine_units_float':
|
||||
require_once __DIR__.'/test.units_float.config.php';
|
||||
require_once '../engine/web/functions.php';
|
||||
|
||||
$cfg['Addr']['print'] = 'www.kupshop.local/';
|
||||
$cfg['Addr']['full'] = 'https://'.$cfg['Addr']['print'];
|
||||
$cfg['Path']['smarty_tpl']['templates'] = 'nic'; // Non-existent folder to skip shop templates
|
||||
break;
|
||||
case 'engine':
|
||||
require_once __DIR__.'/test.config.php';
|
||||
require_once './engine/web/functions.php';
|
||||
|
||||
$cfg['Addr']['print'] = 'www.kupshop.local/';
|
||||
$cfg['Addr']['full'] = 'https://'.$cfg['Addr']['print'];
|
||||
$cfg['Path']['smarty_tpl']['templates'] = 'nic'; // Non-existent folder to skip shop templates
|
||||
break;
|
||||
}
|
||||
|
||||
if (QUERY_LOG) {
|
||||
sqlGetConnection()
|
||||
->getConfiguration()
|
||||
->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
|
||||
}
|
||||
|
||||
require_once $cfg['Path']['shared_version'].'web/lang/lang.cs.php';
|
||||
|
||||
function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext = null)
|
||||
{
|
||||
// TODO(hauschwitz): opravit deprecation warningy místo vypínání
|
||||
if ($errno === E_DEPRECATED || $errno === E_USER_DEPRECATED) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (stripos($errfile, '.tpl.php') !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (stripos($errfile, 'smarty_internal_templatebase') !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$errorHandler = new PHPUnit\Util\ErrorHandler(false, true, true, true);
|
||||
|
||||
return $errorHandler($errno, $errstr, $errfile, $errline);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function getTestSuite()
|
||||
{
|
||||
$args = $GLOBALS['argv'];
|
||||
$testSuiteParamIndex = array_search('--testsuite', $args);
|
||||
|
||||
if ($testSuiteParamIndex) {
|
||||
return $args[$testSuiteParamIndex + 1];
|
||||
}
|
||||
|
||||
return 'engine';
|
||||
}
|
||||
|
||||
$GLOBALS['previous'] = set_error_handler('mutingErrorHandler');
|
||||
|
||||
spl_autoload_register(function ($className) {
|
||||
$fileName = __DIR__.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $className).'.php';
|
||||
|
||||
if (!file_exists($fileName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
require $fileName;
|
||||
});
|
||||
|
||||
if (TEST_SUITE == 'shop') {
|
||||
// Autoloader for shop tests
|
||||
spl_autoload_register(function ($className) {
|
||||
$fileName = 'tests/functional'.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $className).'.php';
|
||||
|
||||
if (!file_exists($fileName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
require $fileName;
|
||||
});
|
||||
}
|
||||
|
||||
// Prepare database
|
||||
global $db;
|
||||
$db = new \KupShop\DevelopmentBundle\Util\Tests\DatabaseUtils();
|
||||
$db->prepare();
|
||||
Reference in New Issue
Block a user