Skip to content

Commit

Permalink
Примерный bootstrap.php & phpunit.xml.dist
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Jun 6, 2021
1 parent 8f363de commit 69aca81
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
45 changes: 45 additions & 0 deletions bootstrap/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

$documentRootEnvName = 'DOCUMENT_ROOT';
$documentRoot = getenv($documentRootEnvName);

if ($documentRoot === false) {
$documentRoot = dirname(dirname(__DIR__));
if (!is_dir($documentRoot . '/bitrix/') || !is_file($documentRoot . '/bitrix/modules/main/include.php')) {
throw new RuntimeException(sprintf('Bitrix not found. Setup environment variable `%s`', $documentRootEnvName));
}
}

if (!is_dir($documentRoot)) {
throw new RuntimeException(
sprintf(
'Document root folder doesn`t exist: %s',
$documentRoot
)
);
}

$_SERVER['DOCUMENT_ROOT'] = $documentRoot;

define('LANGUAGE_ID', 'pa');
define('NO_KEEP_STATISTIC', true);
define('NOT_CHECK_PERMISSIONS', true);
define('LOG_FILENAME', 'php://stderr');
define('BX_NO_ACCELERATOR_RESET', true);
define('STOP_STATISTICS', true);
define('NO_AGENT_STATISTIC', 'Y');
define('DisableEventsCheck', true);
define('NO_AGENT_CHECK', true);

require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php');

// Альтернативный способ вывода ошибок типа "DB query error.":
$GLOBALS['DB']->debug = true;

global $DB;
$app = \Bitrix\Main\Application::getInstance();
$con = $app->getConnection();
$DB->db_Conn = $con->getResource();

// "authorizing" as admin
$_SESSION['SESS_AUTH']['USER_ID'] = 1;
19 changes: 19 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap/bootstrap.php" colors="true" executionOrder="random" resolveDependencies="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Tests">
<!-- Директории с тестами -->
</testsuite>
</testsuites>
<php>
<server name='HTTP_HOST' value='localhost' />
<server name='SERVER_NAME' value='localhost' />
<!-- Так можно напрямую задать DOCUMENT_ROOT -->
<!--<env name='DOCUMENT_ROOT' value='/path/to/root' /> -->
</php>
</phpunit>

0 comments on commit 69aca81

Please sign in to comment.