Changes in Nette Tester 1.6.0

9 years ago by Miloslav Hůla  

Nette Tester 1.6.0 is out. Let me summarize the changes.

The new optional parameter $description has been added to almost all Assert methods. It works as an error message prefix when an assertion fails. It is handy in situations where the error message is not self-describing enough. For example, in a loop with an assertion:

foreach ($model->getUsers() as $user) {
	Assert::true($user->isActive(), "User $user->name");
}
# Before 1.6.0 you got
Failed: FALSE should be TRUE

# Now you get
Failed: User sandokan: FALSE should be TRUE

The next change takes place in the Assert class too. A new assertion Assert::noError($callable) is suited to test snippets of code when there is no other assertion. It checks that $callable function does not generate any PHP notice/warning/error or exception. For example:

use Tester\Assert;

require __DIR__ . '/bootstrap.php';

Assert::noError(function () {
	# Checks that there is no error or exception
	$o = new Object;
	$o->doSomething();
});

Before 1.6.0 you could not wrap code into noError() and you had to make a workaround to prevent Error: This test forgets to execute an assertion message.

Next changes target the TestCase.

The @throws assertion is applied to testMethods() only, not to setUp() nor tearDown(). For example, if you had a testMethod() annoted by @throws \Exception, the method didn't throw an exception but tearDown() did, the test (probably wrongly) succeeded. Now, any exception thrown by setUp() or tearDown() is considered as test fail.

Another improvement is that the TestCase::tearDown() is called even when the error is generated in a test method.

One small thing remains. Closures and anonymous classes dumping has been improved. You can find file and line info in dumps.

If you are interested in details, you can compare 1.5.0 and 1.6.0 version.