Skip to content

Fix docs about making external requests with BrowserKit #8823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions components/browser_kit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ The BrowserKit Component
The BrowserKit component simulates the behavior of a web browser, allowing
you to make requests, click on links and submit forms programmatically.

.. note::

The BrowserKit component can only make internal requests to your application.
If you need to make requests to external sites and applications, consider
using `Goutte`_, a simple web scraper based on Symfony Components.

Installation
------------

Expand Down Expand Up @@ -60,7 +66,7 @@ URL::
use Acme\Client;

$client = new Client();
$crawler = $client->request('GET', 'http://symfony.com');
$crawler = $client->request('GET', '/');

The value returned by the ``request()`` method is an instance of the
:class:`Symfony\\Component\\DomCrawler\\Crawler` class, provided by the
Expand All @@ -78,7 +84,7 @@ performs the needed HTTP GET request to simulate the link click::
use Acme\Client;

$client = new Client();
$crawler = $client->request('GET', 'http://symfony.com');
$crawler = $client->request('GET', '/product/123');
$link = $crawler->selectLink('Go elsewhere...')->link();
$client->click($link);

Expand Down Expand Up @@ -120,7 +126,7 @@ retrieve any cookie while making requests with the client::

// Make a request
$client = new Client();
$crawler = $client->request('GET', 'http://symfony.com');
$crawler = $client->request('GET', '/');

// Get the cookie Jar
$cookieJar = $client->getCookieJar();
Expand Down Expand Up @@ -152,7 +158,7 @@ Looping Through Cookies

// Make a request
$client = new Client();
$crawler = $client->request('GET', 'http://symfony.com');
$crawler = $client->request('GET', '/');

// Get the cookie Jar
$cookieJar = $client->getCookieJar();
Expand Down Expand Up @@ -198,9 +204,8 @@ history::

use Acme\Client;

// make a real request to an external site
$client = new Client();
$client->request('GET', 'http://symfony.com');
$client->request('GET', '/');

// select and click on a link
$link = $crawler->selectLink('Documentation')->link();
Expand All @@ -217,9 +222,8 @@ also delete all the cookies::

use Acme\Client;

// make a real request to an external site
$client = new Client();
$client->request('GET', 'http://symfony.com');
$client->request('GET', '/');

// delete history
$client->restart();
Expand Down