@@ -1837,9 +1837,16 @@ Testing Request Data
18371837
18381838The ``MockResponse `` class comes with some helper methods to test the request:
18391839
1840+ * ``getRequestMethod() `` - returns the HTTP method;
1841+ * ``getRequestUrl() `` - returns the URL the request would be sent to;
18401842* ``getRequestOptions() `` - returns an array containing other information about
18411843 the request such as headers, query parameters, body content etc.
18421844
1845+ .. versionadded :: 5.2
1846+
1847+ The ``getRequestMethod() `` and ``getRequestUrl() `` methods were introduced
1848+ in Symfony 5.2.
1849+
18431850Usage example::
18441851
18451852 $mockResponse = new MockResponse('', ['http_code' => 204]);
@@ -1852,6 +1859,12 @@ Usage example::
18521859 ],
18531860 ]);
18541861
1862+ $mockResponse->getRequestMethod();
1863+ // returns "DELETE"
1864+
1865+ $mockResponse->getRequestUrl();
1866+ // returns "https://example.com/api/article/1337"
1867+
18551868 $mockResponse->getRequestOptions()['headers'];
18561869 // returns ["Accept: */*", "Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l"]
18571870
@@ -1925,6 +1938,8 @@ test it in a real application::
19251938 $responseData = $service->createArticle($requestData);
19261939
19271940 // Assert
1941+ self::assertSame('POST', $mockResponse->getRequestMethod());
1942+ self::assertSame('https://example.com/api/article', $mockResponse->getRequestUrl());
19281943 self::assertContains(
19291944 'Content-Type: application/json',
19301945 $mockResponse->getRequestOptions()['headers']
0 commit comments