Skip to content

Assertions aggregation into a named block #312

@milo

Description

@milo

Idea

In Nette components test suits is quite common to use a test() function:

test(function () {
    Assert::...()
    Assert::...()
    Assert::...()
});

Sometimes, I'm using it too and I would like to make it official & supported. Plus add possibility to name such blocks of assertions. For example:

Assert::block('Invariability', function () {
    Assert::...()
    Assert::...()
    Assert::...()
});

The description of block will be shown in stack trace, e.g.:

-- FAILED: tests\RunnerOutput\JUnitPrinter.phpt
   Invariability
      Exited with error code 255 (expected 0)
      E_NOTICE: Undefined property: .....

      in src\Framework\Dumper.php(265)
      in src\Framework\Environment.php(127) Tester\Dumper::dumpException()

It should be nested, it can be used for testMethods(), it could solve the #293, related to #133.

Actually, it emulates TestCase methods stack trace a little bit.

Implementation

public static function block($name, \Closure $cb)
{
    try {
        $cb();
    } catch (\Exception $e) {
        throw new AssertBlockException($name, $e);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions