Closed
Description
Description
I love the test assert methods provided by Symfony but their error messages are sometimes cryptic.
Example
This test:
$this->assertSelectorTextContains('#errorMessages', 'Lorem Ipsum dolor sit amet');
Generates this error message:
1) App\Tests\Controller\SomeController::testErrors
Failed asserting that Symfony\Component\DomCrawler\Crawler Object &000000006f47faf00000000020f6e407 (
'uri' => 'http://localhost/...'
'defaultNamespacePrefix' => 'default'
'namespaces' => Array &0 ()
'baseHref' => '...'
'document' => DOMDocument Object &000000006f47f0290000000020f6e407 ()
'nodes' => Array &1 (
0 => DOMElement Object &000000006f47faa70000000020f6e407 ()
)
'isHtml' => true
'html5Parser' => null
) matches selector "#errorMessages" and has a node matching selector "#errorMessages" with content containing "Lorem Ipsum dolor sit amet".
This is the error message I'd like to see:
1) App\Tests\Controller\SomeController::testErrors
Failed asserting that selector "#errorMessages" contains "Lorem Ipsum dolor sit amet".
The "#errorMessages" element exists, but its content is "Foo bar lorem ipsum"
or:
1) App\Tests\Controller\SomeController::testErrors
Failed asserting that selector "#errorMessages" contains "Lorem Ipsum dolor sit amet".
The "#errorMessages" selector does not match any elements.
As usual, we must answer many questions before trying to fix this: do we really want to do this? Is it technically possible to do it? Would it work for all asserts and all possible scenarios? Thanks!