-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Testing] Add docs for new WebTestCase assertions #11271
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
.. index:: | ||
single: Tests; Assertions | ||
|
||
Functional Test specific Assertions | ||
=================================== | ||
|
||
.. versionadded:: 4.3 | ||
|
||
The shortcut methods for assertions using ``WebTestCase`` were introduced | ||
in Symfony 4.3. | ||
|
||
When doing functional tests, sometimes you need to make complex assertions in | ||
order to check whether the ``Request``, the ``Response`` or the ``Crawler`` | ||
contain the expected information to make your test succeed. | ||
|
||
Here is an example with plain PHPUnit:: | ||
|
||
$this->assertGreaterThan( | ||
0, | ||
$crawler->filter('html:contains("Hello World")')->count() | ||
); | ||
|
||
Now here is the example with the assertions specific to Symfony:: | ||
|
||
$this->assertSelectorTextContains('html', 'Hello World'); | ||
|
||
.. note:: | ||
|
||
These assertions only work if a request has been made with the ``Client`` | ||
in a test case extending the ``WebTestCase`` class. | ||
|
||
Pierstoval marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Assertions Reference | ||
--------------------- | ||
|
||
Response | ||
~~~~~~~~ | ||
|
||
- ``assertResponseIsSuccessful()`` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it is usefull to have the full signature here or transform them all to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We cannot link to a specific method when using GitHub, so that's a bit sad. For class, it will be a good solution though. We must discuss whether it's usefull to link functions, or just like to the class on github directly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in a PR github seems to have this method information. Otherwiese we could have a proxy wich calculates the needed line number on demand for the github url |
||
- ``assertResponseStatusCodeSame()`` | ||
- ``assertResponseRedirects()`` | ||
- ``assertResponseHasHeader()`` | ||
- ``assertResponseNotHasHeader()`` | ||
- ``assertResponseHeaderSame()`` | ||
- ``assertResponseHeaderNotSame()`` | ||
- ``assertResponseHasCookie()`` | ||
- ``assertResponseNotHasCookie()`` | ||
- ``assertResponseCookieValueSame()`` | ||
|
||
Request | ||
~~~~~~~ | ||
|
||
- ``assertRequestAttributeValueSame()`` | ||
- ``assertRouteSame()`` | ||
|
||
Browser | ||
~~~~~~~ | ||
|
||
- ``assertBrowserHasCookie()`` | ||
- ``assertBrowserNotHasCookie()`` | ||
- ``assertBrowserCookieValueSame()`` | ||
|
||
Crawler | ||
~~~~~~~ | ||
|
||
- ``assertSelectorExists()`` | ||
- ``assertSelectorNotExists()`` | ||
- ``assertSelectorTextContains()`` | ||
- ``assertSelectorTextSame()`` | ||
- ``assertSelectorTextNotContains()`` | ||
- ``assertPageTitleSame()`` | ||
- ``assertPageTitleContains()`` | ||
- ``assertInputValueSame()`` | ||
- ``assertInputValueNotSame()`` | ||
|
||
Troubleshooting | ||
--------------- | ||
|
||
These assertions will not work with `symfony/panther`_ as they use the | ||
``Request`` and ``Response`` objects from the ``HttpFoundation`` | ||
component, and the ``KernelBrowser`` from the ``FrameworkBundle``. | ||
Panther only uses the ``BrowserKit`` component. | ||
|
||
.. _`symfony/panther`: https://github.com/symfony/panther |
Uh oh!
There was an error while loading. Please reload this page.