throw exception when request() wasn't called

This commit is contained in:
Christian Flothmann 2018-09-25 09:51:48 +02:00
parent 5dadd95dea
commit 41cfde19f6

View File

@ -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);