Skip to content
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

Document the assertion system #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions guides/assertion-system.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Assertion system
================

The ``\Behat\Mink\WebAssert`` class provides a set of assertions. There are assertions
about the address of the page, the cookies, the status code, the response headers,
the content of the page, the page elements...

API with exceptions
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had no ideas for the title.

-------------------

An assertion can improve code readability and avoid having a fatal error in method chaining.

For example, instead of:

.. code-block:: php

$registerForm = $page->find('css', 'form.register');

if (null === $registerForm) {
throw new \Exception('The element is not found');
}

$field = $registerForm->findField('Email');

if (null === $field) {
throw new \Exception('The element is not found');
}

$field->setValue('[email protected]');

you can do:

.. code-block:: php

// Throw exception when not found instead of returning null.
$registerForm = $mink->assertSession()->elementExists('css', 'form.register');

$field = $mink->assertSession()->fieldExists('Email', $registerForm);

$field->setValue('[email protected]');


Webassert and multisessions
---------------------------

You could use an another session by calling ``assertSession`` with a session name
or an instance of ``\Behat\Mink\Session``.

.. code-block:: php

$mink->assertSession()->elementExists('css', 'form.register');
$mink->assertSession('goutte')->elementExists('css', 'form.register');
$mink->assertSession($mink->getSession('goutte'))->elementExists('css', 'form.register');
1 change: 1 addition & 0 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Learn Mink with the topical guides:
guides/interacting-with-pages
guides/drivers
guides/managing-sessions
guides/assertion-system
contributing

Testing Tools Integration
Expand Down