Skip to content

Commit

Permalink
bug #28592 [BrowserKit] throw exception when request() wasn't called …
Browse files Browse the repository at this point in the history
…(xabbuh)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[BrowserKit] throw exception when request() wasn't called

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | #27807 (comment)

Commits
-------

41cfde1 throw exception when request() wasn't called
  • Loading branch information
nicolas-grekas committed Sep 29, 2018
2 parents d5e3f2f + 41cfde1 commit 3afe4e7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Symfony/Component/BrowserKit/Client.php
Expand Up @@ -297,7 +297,11 @@ public function click(Link $link)
*/
public function clickLink(string $linkText): Crawler
{
return $this->click($this->getCrawler()->selectLink($linkText)->link());
if (null === $this->crawler) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

return $this->click($this->crawler->selectLink($linkText)->link());
}

/**
Expand Down Expand Up @@ -332,7 +336,11 @@ public function submit(Form $form, array $values = array()/*, array $serverParam
*/
public function submitForm(string $button, array $fieldValues = array(), string $method = 'POST', array $serverParameters = array()): Crawler
{
$buttonNode = $this->getCrawler()->selectButton($button);
if (null === $this->crawler) {
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
}

$buttonNode = $this->crawler->selectButton($button);
$form = $buttonNode->form($fieldValues, $method);

return $this->submit($form, array(), $serverParameters);
Expand Down

0 comments on commit 3afe4e7

Please sign in to comment.