Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordiosmosis <diosmosis@users.noreply.github.com>2018-08-13 00:48:27 +0300
committerGitHub <noreply@github.com>2018-08-13 00:48:27 +0300
commit73bc38f81454b78b1f844ea3ffbd9681117064de (patch)
tree2450c0ae4e7c7e6da331af3738ea9fe0c7969566 /tests
parenteb035eb9ebbf794c852ca0707423cb8ab3543aa8 (diff)
Add backtrace to exceptions treated as fatal errors w/ test, … (#13276)
* Add backtrace to exceptions treated as fatal errors w/ test, and move partial backtrace reconstruction to FrontController so different safemodes can receive it. * Add missing file. * fixing tests * fix test finally * fix submodule
Diffstat (limited to 'tests')
-rw-r--r--tests/PHPUnit/Integration/ErrorHandlerTest.php39
-rw-r--r--tests/PHPUnit/Integration/FrontControllerTest.php55
-rw-r--r--tests/resources/trigger-fatal-exception.php31
3 files changed, 86 insertions, 39 deletions
diff --git a/tests/PHPUnit/Integration/ErrorHandlerTest.php b/tests/PHPUnit/Integration/ErrorHandlerTest.php
deleted file mode 100644
index eaf290c574..0000000000
--- a/tests/PHPUnit/Integration/ErrorHandlerTest.php
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-/**
- * Piwik - free/libre analytics platform
- *
- * @link http://piwik.org
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- */
-
-namespace Piwik\Tests\Integration;
-
-
-use Piwik\Http;
-use Piwik\Tests\Framework\Fixture;
-use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
-
-class ErrorHandlerTest extends IntegrationTestCase
-{
- public function test_fatalErrorStackTracesReturned()
- {
- $url = Fixture::getRootUrl() . '/tests/resources/trigger-fatal.php?format=json';
- $response = Http::sendHttpRequest($url, 2);
-
- $response = json_decode($response, $isAssoc = true);
- $response['message'] = $this->cleanMessage($response['message']);
-
- $this->assertEquals('error', $response['result']);
-
- $expectedFormat = <<<FORMAT
-Allowed memory size of %s bytes exhausted (tried to allocate %s bytes) on {includePath}/tests/resources/trigger-fatal.php(22)#0 {includePath}/tests/resources/trigger-fatal.php(35): MyClass-&gt;triggerError()#1 {includePath}/tests/resources/trigger-fatal.php(51): MyDerivedClass::staticMethod()#2 {includePath}/tests/resources/trigger-fatal.php(57): myFunction()
-FORMAT;
-
- $this->assertStringMatchesFormat($expectedFormat, $response['message']);
- }
-
- private function cleanMessage($message)
- {
- return str_replace(PIWIK_INCLUDE_PATH, '{includePath}', $message);
- }
-} \ No newline at end of file
diff --git a/tests/PHPUnit/Integration/FrontControllerTest.php b/tests/PHPUnit/Integration/FrontControllerTest.php
new file mode 100644
index 0000000000..c5aecf7987
--- /dev/null
+++ b/tests/PHPUnit/Integration/FrontControllerTest.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Tests\Integration;
+
+use Piwik\Http;
+use Piwik\Tests\Framework\Fixture;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+
+class FrontControllerTest extends IntegrationTestCase
+{
+ public function test_fatalErrorStackTracesReturned()
+ {
+ $url = Fixture::getRootUrl() . '/tests/resources/trigger-fatal.php?format=json';
+ $response = Http::sendHttpRequest($url, self::isTravisCI() ? 2 : 20);
+
+ $response = json_decode($response, $isAssoc = true);
+ $response['message'] = $this->cleanMessage($response['message']);
+
+ $this->assertEquals('error', $response['result']);
+
+ $expectedFormat = <<<FORMAT
+Allowed memory size of %s bytes exhausted (tried to allocate %s bytes) on {includePath}/tests/resources/trigger-fatal.php(22)#0 {includePath}/tests/resources/trigger-fatal.php(35): MyClass-&gt;triggerError()#1 {includePath}/tests/resources/trigger-fatal.php(51): MyDerivedClass::staticMethod()#2 {includePath}/tests/resources/trigger-fatal.php(57): myFunction()
+FORMAT;
+
+ $this->assertStringMatchesFormat($expectedFormat, $response['message']);
+ }
+
+ public function test_thrownExceptionInFrontControllerPrintsBacktrace()
+ {
+ $url = Fixture::getRootUrl() . '/tests/resources/trigger-fatal-exception.php?format=json';
+ $response = Http::sendHttpRequest($url, self::isTravisCI() ? 2 : 20);
+
+ $response = json_decode($response, $isAssoc = true);
+ $response['message'] = $this->cleanMessage($response['message']);
+
+ $this->assertEquals('error', $response['result']);
+
+ $expectedFormat = <<<FORMAT
+test message on {includePath}/tests/resources/trigger-fatal-exception.php(23)#0 [internal function]: {closure}('CoreHome', 'index', Array)#1 {includePath}/core/EventDispatcher.php(141): call_user_func_array(Object(Closure), Array)#2 {includePath}/core/Piwik.php(780): Piwik\EventDispatcher-&gt;postEvent('Request.dispatc...', Array, false, NULL)#3 {includePath}/core/FrontController.php(538): Piwik\Piwik::postEvent('Request.dispatc...', Array)#4 {includePath}/core/FrontController.php(146): Piwik\FrontController-&gt;doDispatch('CoreHome', 'index', NULL)#5 {includePath}/tests/resources/trigger-fatal-exception.php(31): Piwik\FrontController-&gt;dispatch('CoreHome', 'index')#6 {main}
+FORMAT;
+
+ $this->assertStringMatchesFormat($expectedFormat, $response['message']);
+ }
+
+ private function cleanMessage($message)
+ {
+ return str_replace(PIWIK_INCLUDE_PATH, '{includePath}', $message);
+ }
+} \ No newline at end of file
diff --git a/tests/resources/trigger-fatal-exception.php b/tests/resources/trigger-fatal-exception.php
new file mode 100644
index 0000000000..a725553414
--- /dev/null
+++ b/tests/resources/trigger-fatal-exception.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+define('PIWIK_PRINT_ERROR_BACKTRACE', true);
+define('PIWIK_ENABLE_DISPATCH', false);
+
+require_once __DIR__ . '/../../tests/PHPUnit/proxy/index.php';
+
+$environment = new \Piwik\Application\Environment(null);
+$environment->init();
+
+\Piwik\Access::getInstance()->setSuperUserAccess(true);
+
+$executed = false;
+\Piwik\Piwik::addAction('Request.dispatch', function () use (&$executed) {
+ if (!$executed) {
+ $executed = true;
+ throw new Twig_Error_Runtime('test message');
+ }
+});
+
+\Piwik\FrontController::$enableDispatch = true;
+
+\Piwik\FrontController::getInstance()->init();
+
+echo \Piwik\FrontController::getInstance()->dispatch('CoreHome', 'index');