Skip to content

Commit

Permalink
Document the assertion system
Browse files Browse the repository at this point in the history
  • Loading branch information
aaa2000 committed Oct 3, 2015
1 parent e7f9322 commit 03eca7e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
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
-------------------

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

0 comments on commit 03eca7e

Please sign in to comment.