Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Testing] Improve error messages of assert methods #37757

Copy link
Copy link
Closed
@javiereguiluz

Description

@javiereguiluz
Issue body actions

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.