diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index a8e4f440e98a..8102a22a107e 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -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()); } /** @@ -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);