Changes in Nette Tester 1.7.0

9 years ago by Miloslav Hůla  

Nette Tester 1.7.0 is out. I'll summarize the changes.

HtmlGenerator, which generates HTML code coverage reports, now counts lines from not evaluated files as not covered. The only impact is, that you can see lower percentual coverage in the report. Imagine the situation, that you have two source files (same length for simplification), but only one of them is loaded by tests. You got 100% coverage before, now you get only 50%.

If you are using TestCase test methods with @dataProvider, data provider method can return Traversable now. As a consequence of this, you can use a generator (yield). It is handy for lazy data loading, for example from remote API. Short example:

class RemoteAPITest extends Tester\TestCase
{
	/** @dataProvider getRemoteData */
	public function testMe($arg)
	{
		Assert::same(..., $arg);
	}

	public function getRemoteData()
	{
		foreach ($this->remoteService->cases() as $case) {
			yield [$case];
		}
	}
}

(new RemoteAPITest)->run();

A few changes happened in the Dumper class. There is an object hash among the dumps. It helps to recognize a dumped object identity.

# Before
(object) array()
(object) array()
(object) array()

# Now
(object) /* #f231 */ array()
(object) /* #1550 */ array()
(object) /* #f231 */ array()

Dumper::dumpException() shows a line of source code beside an Assert call in a stack trace.

# Before
Failed: 27 should be 25

in tests/Utils/Strings.phpt(23) Tester\Assert::same()
in Utils/tests/bootstrap.php(39) {closure}()
in tests/Utils/Strings.phpt(32) test()

# Now
Failed: 27 should be 25

in tests/Utils/Strings.phpt(23) Tester\Assert::same(25, Strings::indexOf($foo, '1'));
in Utils/tests/bootstrap.php(39) {closure}()
in tests/Utils/Strings.phpt(32) test()

The next change is related to @dataProvider. You could use the INI file path before, now you can use PHP script as a data provider. You have to return array or Traversable from it.

# dataprovider.php
return json_decode(__FILE__ . '/data.json');

# or
return new DirectoryIterator(__DIR__ . '/data-files');

# or just
return [
	'one' => ['a', 'b', 'c'],
	'two' => ['d', 'e', 'f'],
];

Next two small changes. Environment variable term = xterm-256color enables color printing. And FileMock now supports unlink()ing.

And one big change as the last. Tester now supports PHPDBG SAPI with PHP 7.0.0 or newer. The biggest impact of it targets code coverage. PHPDBG offers a mechanism to collect information about executed lines of source code. In other words, it can collect code coverage statistics. It is a faster alternative to Xdebug which is not needed with PHPDBG. Usage is simple:

vendor/bin/tester -p /path/to/phpdbg --coverage coverage.html --coverage-src src

Some plans on the end. Tester supports PHP 5.3 now. We agreed that we will wait two or three weeks after 1.7.0 release and we will skip to 5.4 at least. I believe, that Tester 1.7.0 is good enough for PHP 5.3 projects. But if you are against, leave us a comment with arguments.

Many thanks to volunteers which contributed! This release is actually their work. Check out the changes.

Tester's documentation is up to date.