Skip to content

Commit

Permalink
Convert eol to LF
Browse files Browse the repository at this point in the history
Thanks to stof
  • Loading branch information
martinqt committed Oct 18, 2012
1 parent 2946e29 commit fee09dd
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions cookbook/testing/http_authentication.rst
@@ -1,36 +1,36 @@
.. index::
single: Tests; HTTP authentication

How to simulate HTTP Authentication in a Functional Test
========================================================

If your application needs HTTP authentication, pass the username and password
as server variables to ``createClient()``::

$client = static::createClient(array(), array(
'PHP_AUTH_USER' => 'username',
'PHP_AUTH_PW' => 'pa$$word',
));

You can also override it on a per request basis::

$client->request('DELETE', '/post/12', array(), array(), array(
'PHP_AUTH_USER' => 'username',
'PHP_AUTH_PW' => 'pa$$word',
));

When your application is using a ``form_login``, you can simplify your tests
by allowing your test configuration to make use of HTTP authentication. This
way you can use the above to authenticate in tests, but still have your users
login via the normal ``form_login``. The trick is to include the ``http_basic``
key in your firewall, along with the ``form_login`` key:

.. configuration-block::

.. code-block:: yaml
# app/config/config_test.yml
security:
firewalls:
your_firewall_name:
http_basic:
.. index::
single: Tests; HTTP authentication

How to simulate HTTP Authentication in a Functional Test
========================================================

If your application needs HTTP authentication, pass the username and password
as server variables to ``createClient()``::

$client = static::createClient(array(), array(
'PHP_AUTH_USER' => 'username',
'PHP_AUTH_PW' => 'pa$$word',
));

You can also override it on a per request basis::

$client->request('DELETE', '/post/12', array(), array(), array(
'PHP_AUTH_USER' => 'username',
'PHP_AUTH_PW' => 'pa$$word',
));

When your application is using a ``form_login``, you can simplify your tests
by allowing your test configuration to make use of HTTP authentication. This
way you can use the above to authenticate in tests, but still have your users
login via the normal ``form_login``. The trick is to include the ``http_basic``
key in your firewall, along with the ``form_login`` key:

.. configuration-block::

.. code-block:: yaml
# app/config/config_test.yml
security:
firewalls:
your_firewall_name:
http_basic:

0 comments on commit fee09dd

Please sign in to comment.