mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
docs: improve feature.rst
This commit is contained in:
parent
d273222b7e
commit
5fe0572c66
@ -21,23 +21,31 @@ are called if you implement your own methods.
|
||||
|
||||
.. literalinclude:: feature/001.php
|
||||
|
||||
Requesting A Page
|
||||
Requesting a Page
|
||||
=================
|
||||
|
||||
Essentially, feature tests simply allows you to call an endpoint on your application and get the results back.
|
||||
to do this, you use the ``call()`` method. The first parameter is the HTTP method to use (most frequently either GET or POST).
|
||||
The second parameter is the path on your site to test. The third parameter accepts an array that is used to populate the
|
||||
superglobal variables for the HTTP verb you are using. So, a method of **GET** would have the **$_GET** variable
|
||||
populated, while a **post** request would have the **$_POST** array populated.
|
||||
To do this, you use the ``call()`` method.
|
||||
|
||||
1. The first parameter is the HTTP method to use (most frequently either GET or POST).
|
||||
2. The second parameter is the URI path on your site to test.
|
||||
3. The third parameter ``$params`` accepts an array that is used to populate the
|
||||
superglobal variables for the HTTP verb you are using. So, a method of **GET**
|
||||
would have the **$_GET** variable populated, while a **POST** request would
|
||||
have the **$_POST** array populated.
|
||||
|
||||
.. note:: The ``$params`` array does not make sense for every HTTP verb, but is
|
||||
included for consistency.
|
||||
|
||||
.. literalinclude:: feature/002.php
|
||||
|
||||
Shorthand Methods
|
||||
-----------------
|
||||
|
||||
Shorthand methods for each of the HTTP verbs exist to ease typing and make things clearer:
|
||||
|
||||
.. literalinclude:: feature/003.php
|
||||
|
||||
.. note:: The ``$params`` array does not make sense for every HTTP verb, but is included for consistency.
|
||||
|
||||
Setting Different Routes
|
||||
------------------------
|
||||
|
||||
@ -74,22 +82,28 @@ to send out emails. You can tell the system to skip any event handling with the
|
||||
|
||||
.. literalinclude:: feature/007.php
|
||||
|
||||
Formatting The Request
|
||||
Formatting the Request
|
||||
-----------------------
|
||||
|
||||
You can set the format of your request's body using the ``withBodyFormat()`` method. Currently this supports either
|
||||
`json` or `xml`. This will take the parameters passed into ``call()``, ``post()``, ``get()``... and assign them to the
|
||||
body of the request in the given format. This will also set the `Content-Type` header for your request accordingly.
|
||||
``json`` or ``xml``.
|
||||
This is useful when testing JSON or XML APIs so that you can set the request in the form that the controller will expect.
|
||||
|
||||
This will take the parameters passed into ``call()``, ``post()``, ``get()``... and assign them to the
|
||||
body of the request in the given format.
|
||||
|
||||
This will also set the `Content-Type` header for your request accordingly.
|
||||
|
||||
.. literalinclude:: feature/008.php
|
||||
|
||||
Setting the Body
|
||||
----------------
|
||||
|
||||
You can set the body of your request with the ``withBody()`` method. This allows you to format the body how you want
|
||||
to format it. It is recommended that you use this if you have more complicated XMLs to test. This will also not set
|
||||
the Content-Type header for you so if you need that, you can set it with the ``withHeaders()`` method.
|
||||
to format it. It is recommended that you use this if you have more complicated XMLs to test.
|
||||
|
||||
This will not set
|
||||
the `Content-Type` header for you. If you need that, you can set it with the ``withHeaders()`` method.
|
||||
|
||||
Checking the Response
|
||||
=====================
|
||||
|
Loading…
x
Reference in New Issue
Block a user