zenstruck / browser

A fluent interface for your Symfony functional tests.
MIT License
186 stars 17 forks source link

`KernelBrowser::clickAndValidate()` #83

Open kbond opened 2 years ago

kbond commented 2 years ago

The idea is to click a form submit and ensure there are no validation errors. If there are, fail.

public function clickAndValidate(string $locator): self
{
    return $this->clickAndIntercept($locator)
        ->use(function (ValidatorDataCollector $collector) {
            Assert::that($collector->getViolationsCount())
                ->isEmpty('There were {actual} validation violations.')
            ;
        })
    ;
}

Displaying the actual violations (not just the count) would be nice but the ValidatorDataCollector makes this difficult as the violations are inside a Symfony\Component\VarDumper\Cloner\Data object. One possibility is to actually dump this but there is a lot of other data in here that isn't terribly useful and would just clutter your console.