You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/basic.md
+5-139Lines changed: 5 additions & 139 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,11 @@ Basic usage
4
4
> [!TIP]
5
5
> Some methods provided by this bundle have been [implemented in Symfony](https://symfony.com/doc/current/testing.html#application-tests). Alternative ways will be shown below.
6
6
7
-
Use `$this->makeClient` to create a Client object. Client is a Symfony class
7
+
Use `$this->createClientWithParams()` to create a Client object. Client is a Symfony class
8
8
that can simulate HTTP requests to your controllers and then inspect the
9
9
results. It is covered by the [functional tests](http://symfony.com/doc/current/book/testing.html#functional-tests)
10
10
section of the Symfony documentation.
11
11
12
-
After making a request, use `assertStatusCode` to verify the HTTP status code.
13
-
If it fails it will display the last exception message or validation errors
14
-
encountered by the Client object.
15
-
16
12
If you are expecting validation errors, test them with `assertValidationErrors`.
17
13
18
14
```php
@@ -22,120 +18,28 @@ class MyControllerTest extends WebTestCase
22
18
{
23
19
public function testContact()
24
20
{
25
-
$client = $this->makeClient();
21
+
$client = $this->createClient();
26
22
$crawler = $client->request('GET', '/contact');
27
-
$this->assertStatusCode(200, $client);
23
+
self::assertResponseStatusCodeSame(200);
28
24
29
25
$form = $crawler->selectButton('Submit')->form();
30
26
$crawler = $client->submit($form);
31
27
32
28
// We should get a validation error for the empty fields.
In order to test more specific status codes, use `assertStatusCode()`:
108
-
109
-
##### assertStatusCode()
110
-
111
-
Check the HTTP status code from the request:
112
-
113
-
```php
114
-
$client = $this->makeClient();
115
-
$client->request('GET', '/contact');
116
-
117
-
// Standard response for successful HTTP request
118
-
$this->assertStatusCode(302, $client);
119
-
```
120
-
121
-
> [!TIP]
122
-
> Call `assertResponseStatusCodeSame()` from Symfony's `WebTestCase` ([documentation](https://symfony.com/doc/current/testing.html#response-assertions)):
123
-
124
-
```php
125
-
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
126
-
127
-
class MyControllerTest extends WebTestCase
128
-
{
129
-
public function testContact()
130
-
{
131
-
$client = static::createClient();
132
-
$client->request('GET', '/contact');
133
-
134
-
self::assertResponseStatusCodeSame(302);
135
-
}
136
-
}
137
-
```
138
-
139
43
#### Get Crawler or content
140
44
141
45
##### fetchCrawler()
@@ -181,44 +85,6 @@ class MyControllerTest extends WebTestCase
181
85
}
182
86
```
183
87
184
-
##### fetchContent()
185
-
186
-
Get the content of a URL:
187
-
188
-
```php
189
-
$content = $this->fetchContent('/contact');
190
-
191
-
// `filter()` can't be used since the output is HTML code, check the content directly
192
-
$this->assertStringContainsString(
193
-
'<h1>LiipFunctionalTestBundle</h1>',
194
-
$content
195
-
);
196
-
```
197
-
198
-
> [!TIP]
199
-
> Call `getResponse()->getContent()` or use `assertSelectorText*()` from Symfony's `WebTestCase` ([documentation](https://symfony.com/doc/current/testing.html#crawler-assertions)):
200
-
201
-
```php
202
-
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
0 commit comments