8000 [Testing] Improve error messages of assert methods · Issue #37757 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Testing] Improve error messages of assert methods #37757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
javiereguiluz opened this issue Aug 6, 2020 · 2 comments
Closed

[Testing] Improve error messages of assert methods #37757

javiereguiluz opened this issue Aug 6, 2020 · 2 comments

Comments

@javiereguiluz
Copy link
Member
javiereguiluz commented Aug 6, 2020

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!

@stof stof added the DomCrawler label Aug 7, 2020
@carsonbot
Copy link

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@xabbuh
Copy link
Member
xabbuh commented Feb 26, 2021

same as #33551 I think

@xabbuh xabbuh closed this as completed Feb 26, 2021
fabpot added a commit that referenced this issue Aug 26, 2021
…orTextContains constraint (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[DomCrawler] improve failure messages of the CrawlerSelectorTextContains constraint

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #33551, #37757
| License       | MIT
| Doc PR        |

Commits
-------

ba451ab improve failure messages of the CrawlerSelectorTextContains constraint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
2A52
0