Disable Tracy debug bar in tests

[MAILPOET-2239]
This commit is contained in:
Jan Jakeš
2019-07-31 15:33:27 +02:00
committed by Rostislav Wolný
parent 09c35d0745
commit a3411d0a15
3 changed files with 23 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ namespace MailPoet\Cron;
use MailPoet\Cron\Triggers\WordPress; use MailPoet\Cron\Triggers\WordPress;
use MailPoet\Settings\SettingsController; use MailPoet\Settings\SettingsController;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
use Tracy\Debugger;
if (!defined('ABSPATH')) exit; if (!defined('ABSPATH')) exit;
@@ -30,6 +31,12 @@ class DaemonHttpRunner {
} }
function ping() { function ping() {
// if Tracy enabled & called by 'MailPoet Cron' user agent, disable Tracy Bar
// (happens in CronHelperTest because it's not a real integration test - calls other WP instance)
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
if (class_exists(Debugger::class) && $user_agent === 'MailPoet Cron') {
Debugger::$showBar = false;
}
$this->addCacheHeaders(); $this->addCacheHeaders();
$this->terminateRequest(self::PING_SUCCESS_RESPONSE); $this->terminateRequest(self::PING_SUCCESS_RESPONSE);
} }

View File

@@ -12,17 +12,21 @@ $tracy_path = __DIR__ . '/tools/tracy.phar';
if (WP_DEBUG && PHP_VERSION_ID >= 70100 && file_exists($tracy_path)) { if (WP_DEBUG && PHP_VERSION_ID >= 70100 && file_exists($tracy_path)) {
require_once $tracy_path; require_once $tracy_path;
function render_tracy() { if (getenv('MAILPOET_DISABLE_TRACY_BAR')) {
ob_start(); Debugger::$showBar = false;
Debugger::renderLoader(); } else {
$tracy_script_html = ob_get_clean(); function render_tracy() {
ob_start();
Debugger::renderLoader();
$tracy_script_html = ob_get_clean();
// strip 'async' to ensure all AJAX request are caught // strip 'async' to ensure all AJAX request are caught
// (even when fired immediately after page starts loading) // (even when fired immediately after page starts loading)
echo str_replace('async', '', $tracy_script_html); return str_replace('async', '', $tracy_script_html);
}; }
add_action('admin_enqueue_scripts', 'render_tracy', PHP_INT_MAX, 0); add_action('admin_enqueue_scripts', 'render_tracy', PHP_INT_MAX, 0);
session_start(); session_start();
}
Debugger::enable(Debugger::DEVELOPMENT); Debugger::enable(Debugger::DEVELOPMENT);
} }

View File

@@ -42,6 +42,8 @@ services:
WORDPRESS_DB_USER: wordpress WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_NAME: wordpress WORDPRESS_DB_NAME: wordpress
WORDPRESS_TABLE_PREFIX: mp_ WORDPRESS_TABLE_PREFIX: mp_
MAILPOET_DISABLE_TRACY_BAR: 1
healthcheck: healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"] test: ["CMD", "curl", "-f", "http://localhost"]
interval: 1m30s interval: 1m30s