Nette\Tester and Tracy working hand by hand?

Notice: This thread is very old.
Honza Kuchař
Member | 1662
+
0
-

Hi Traciers!

What is the best forkflow (e.g. what works for you the best) for debugging tests? Look into these two scenarious to get the sense of what I've written.

  1. When running tests on CI i want to know IF tests failed and which tests failed.

    solution: run tester tests. Done. Works by default.

  2. When I'm on dev machine I want to know WHY something failed. So let's look into Tracy's log folder. Nothing there. Why? Can I enable logging exceptions (of course) to tracy's log folder when running test?
Milo
Nette Core | 1283
+
+1
-

There are many possibilities. It depends on how you run the tests and which errors you want to log.

Both the Tester and Tracy installs own error and exception handlers. I'll assume that you want to completly preserve the Tester behaviour, and you want to log all errors and exceptions additionally.

# test's bootstrap.php

require __DIR__ . '/vendor/autoload.php';

# Standard setup
date_default_timezone_set('Europe/Prague');
Tester\Environment::setup();

# On dev-machine
if (development) {
	$_prevEx = set_exception_handler(function(\Exception $e) use (& $_prevEx) {
		Tracy\Debugger::log($e, Tracy\ILogger::EXCEPTION);
		if ($_prevEx !== NULL) {
			$_prevEx($e);
		}
	});

	$_prevEr = set_error_handler(function($severity, $message, $file, $line) use (& $_prevEr) {
		$e = new \ErrorException($message, 0, $severity, $file, $line);
		Tracy\Debugger::log($e, Tracy\ILogger::EXCEPTION);
		if ($_prevEr === NULL) {
			return FALSE;
		} else {
			call_user_func_array($_prevEr, func_get_args());
		}
	});
}

Maybe is better to enclose it into some own scope.

Or if you want to log the failed assertions only, there is a simpler way:

Tester\Assert::$onFailure = function(Tester\AssertException $e) {
	Tracy\Debugger::log($e, Tracy\ILogger::EXCEPTION);
	throw $e;
};
Filip Procházka
Moderator | 4668
+
0
-

It would be cool to have event on the Environment, so Tracy could be hooked “after” the default Tester error & exception handlers.

Milo
Nette Core | 1283
+
0
-

Agree. I'm thinking about that some time.

Aurielle
Member | 1281
+
0
-

+1, I had to copy handleException() and error and exception handlers to make logging possible…

Honza Kuchař
Member | 1662
+
0
-

Thanks for helpful answer! Is anyone going to send PR?