From 41cfde19f66f4aca81facb4e54c16480b0f6859f Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 25 Sep 2018 09:51:48 +0200 Subject: [PATCH] throw exception when request() wasn't called --- src/Symfony/Component/BrowserKit/Client.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index a8e4f440e9..8102a22a10 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -297,7 +297,11 @@ abstract class Client */ 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 @@ abstract class Client */ 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);