From 9fbff395b05721e35fdccdb851eff9b51adedd49 Mon Sep 17 00:00:00 2001 From: Pavel Dohnal Date: Thu, 15 Aug 2019 14:05:42 +0200 Subject: [PATCH] Save exception when running acceptance tests [MAILPOET-2267] --- .circleci/config.yml | 2 ++ lib/API/JSON/API.php | 4 ++++ mailpoet_initializer.php | 7 ++++--- tests/_output/.gitignore | 2 +- tests/docker/docker-compose.yml | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5447bba168..4f351c1da7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -159,6 +159,7 @@ jobs: - run: name: Run acceptance tests command: | + mkdir -m 777 -p tests/_output/exceptions cd tests/docker docker-compose run -e SKIP_DEPS=1 codeception -g acceptance_group_<< parameters.index >> --steps --debug -vvv --html --xml - store_artifacts: @@ -180,6 +181,7 @@ jobs: - run: name: Run acceptance tests command: | + mkdir -m 777 -p tests/_output/exceptions cd tests/docker docker-compose run -e SKIP_DEPS=1 -e MULTISITE=1 codeception -g acceptance_group_<< parameters.index >> --steps --debug -vvv --html --xml - store_artifacts: diff --git a/lib/API/JSON/API.php b/lib/API/JSON/API.php index 2cf82a8cb9..542e81c93a 100644 --- a/lib/API/JSON/API.php +++ b/lib/API/JSON/API.php @@ -10,6 +10,7 @@ use MailPoet\Util\Helpers; use MailPoet\Util\Security; use MailPoet\WP\Functions as WPFunctions; use Tracy\Debugger; +use Tracy\ILogger; if (!defined('ABSPATH')) exit; @@ -180,6 +181,9 @@ class API { $response = $endpoint->{$this->_request_method}($this->_request_data); return $response; } catch (\Exception $e) { + if (class_exists(Debugger::class) && Debugger::$logDirectory) { + Debugger::log($e, ILogger::EXCEPTION); + } $error_message = $e->getMessage(); $error_response = $this->createErrorResponse(Error::BAD_REQUEST, $error_message, Response::STATUS_BAD_REQUEST); return $error_response; diff --git a/mailpoet_initializer.php b/mailpoet_initializer.php index c42fd633fd..64daab88f7 100644 --- a/mailpoet_initializer.php +++ b/mailpoet_initializer.php @@ -12,8 +12,9 @@ $tracy_path = __DIR__ . '/tools/tracy.phar'; if (WP_DEBUG && PHP_VERSION_ID >= 70100 && file_exists($tracy_path)) { require_once $tracy_path; - if (getenv('MAILPOET_DISABLE_TRACY_BAR')) { - Debugger::$showBar = false; + if (getenv('MAILPOET_TEST_TRACY_MODE')) { + Debugger::enable(Debugger::PRODUCTION, __DIR__ . '/tests/_output/exceptions'); + Debugger::$logSeverity = E_ALL; } else { function render_tracy() { ob_start(); @@ -32,8 +33,8 @@ if (WP_DEBUG && PHP_VERSION_ID >= 70100 && file_exists($tracy_path)) { } add_action('admin_enqueue_scripts', 'render_tracy', PHP_INT_MAX, 0); session_start(); + Debugger::enable(Debugger::DEVELOPMENT); } - Debugger::enable(Debugger::DEVELOPMENT); } define('MAILPOET_VERSION', $mailpoet_plugin['version']); diff --git a/tests/_output/.gitignore b/tests/_output/.gitignore index c96a04f008..d6b7ef32c8 100644 --- a/tests/_output/.gitignore +++ b/tests/_output/.gitignore @@ -1,2 +1,2 @@ * -!.gitignore \ No newline at end of file +!.gitignore diff --git a/tests/docker/docker-compose.yml b/tests/docker/docker-compose.yml index aabf4761c4..7a47012453 100644 --- a/tests/docker/docker-compose.yml +++ b/tests/docker/docker-compose.yml @@ -42,7 +42,7 @@ services: WORDPRESS_DB_USER: wordpress WORDPRESS_DB_NAME: wordpress WORDPRESS_TABLE_PREFIX: mp_ - MAILPOET_DISABLE_TRACY_BAR: 1 + MAILPOET_TEST_TRACY_MODE: 1 healthcheck: test: ["CMD", "curl", "-f", "http://localhost"]