Changes in Nette Tester 1.7.0

by Miloslav Hůla 3 years ago | Tester

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

HtmlGenerator, which generates HTML code coverage report, now counts lines from not evaluated files as not covered. The only impact is, that you can see lower percentual coverage in report. Imagine the situation, that you have two source files (same lenght 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 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();

Few changes happend in Dumper class. There is a 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 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()

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 mechanism to collect information about executed lines of source code. By the other words, it can collect code coverage statistics. It is 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 belive, 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 relase is actually their work. Check out the changes.

Tester's documentation is up to date.

Recent posts