diff --git a/.travis.yml b/.travis.yml index 1633f1bc..6ff21016 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ cache: before_install: - if [[ $lint = '1' ]]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.16.1/php-cs-fixer.phar; fi - - if [[ $lint = '1' ]]; then wget https://github.com/phpstan/phpstan/releases/download/0.11.19/phpstan.phar; fi + - if [[ $lint = '1' ]]; then wget https://github.com/phpstan/phpstan/releases/download/0.12.8/phpstan.phar; fi before_script: - phpenv config-rm xdebug.ini @@ -34,4 +34,4 @@ install: script: - vendor/bin/simple-phpunit - if [[ $lint = '1' ]]; then php php-cs-fixer.phar fix --dry-run --diff --no-ansi; fi - - if [[ $lint = '1' ]]; then php phpstan.phar analyse src tests --level=6; fi + - if [[ $lint = '1' ]]; then php phpstan.phar analyse src tests --level=5; fi diff --git a/phpstan.neon b/phpstan.neon index 76932238..240fe8b7 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,16 +3,16 @@ parameters: - vendor/bin/.phpunit/phpunit-8.3-0/vendor/autoload.php inferPrivatePropertyTypeFromConstructor: true ignoreErrors: - # https://github.com/symfony/symfony/pull/33278 - - '#KernelBrowser#' + - message: '#.+#' + path: tests/DummyKernel.php + # Expected + - '#Method Symfony\\Component\\Panther\\PantherTestCase::createPantherClient\(\) should return Symfony\\Component\\Panther\\Client but returns Symfony\\Component\\BrowserKit\\AbstractBrowser\|null\.#' # False positive - - '#getClient#' - - '#Result of && is always false\.#' - - '#Ternary operator condition is always false\.#' - - '#Call to function method_exists\(\) with #' + - '#Call to an undefined method ReflectionType::getName\(\)\.#' # To fix in PHP WebDriver - '#Parameter \#2 \$desired_capabilities of static method Facebook\\WebDriver\\Remote\\RemoteWebDriver::create\(\) expects array\|Facebook\\WebDriver\\Remote\\DesiredCapabilities\|null, Facebook\\WebDriver\\WebDriverCapabilities given\.#' # Require a redesign of the underlying Symfony components - '#Call to an undefined method DOMNode::getTagName\(\)\.#' - - '#Panther\\[a-zA-Z\\]+::__construct\(\) does not call parent constructor from Symfony\\Component\\(BrowserKit|DomCrawler)\\[a-zA-Z]+\.#' - '#Return type \(void\) of method Symfony\\Component\\Panther\\DomCrawler\\Crawler::clear\(\) should be compatible with return type \(Facebook\\WebDriver\\WebDriverElement\) of method Facebook\\WebDriver\\WebDriverElement::clear\(\)#' + - '#Method Symfony\\Component\\Panther\\DomCrawler\\Crawler::getIterator\(\) should return ArrayIterator&iterable but returns ArrayIterator\.#' + - '#Method Symfony\\Component\\Panther\\DomCrawler\\Crawler::.+\(\) should return static\(Symfony\\Component\\Panther\\DomCrawler\\Crawler\) but returns Symfony\\Component\\Panther\\DomCrawler\\Crawler#' diff --git a/src/Cookie/CookieJar.php b/src/Cookie/CookieJar.php index 5f52bdf6..d00c8bca 100644 --- a/src/Cookie/CookieJar.php +++ b/src/Cookie/CookieJar.php @@ -63,12 +63,12 @@ public function clear() public function updateFromSetCookie(array $setCookies, $uri = null) { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function updateFromResponse(Response $response, $uri = null) { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function all() @@ -83,17 +83,17 @@ public function all() public function allValues($uri, $returnsRawValue = false) { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function allRawValues($uri) { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function flushExpiredCookies() { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } private function symfonyToWebDriver(Cookie $cookie): WebDriverCookie diff --git a/src/DomCrawler/Crawler.php b/src/DomCrawler/Crawler.php index 6bcb31bf..70c39b35 100644 --- a/src/DomCrawler/Crawler.php +++ b/src/DomCrawler/Crawler.php @@ -43,47 +43,47 @@ public function __construct(array $elements = [], WebDriver $webDriver, ?string public function clear(): void { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function add($node): void { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function addContent($content, $type = null): void { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function addHtmlContent($content, $charset = 'UTF-8'): void { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function addXmlContent($content, $charset = 'UTF-8', $options = LIBXML_NONET): void { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function addDocument(\DOMDocument $dom): void { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function addNodeList(\DOMNodeList $nodes): void { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function addNodes(array $nodes): void { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function addNode(\DOMNode $node): void { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function eq($position): self @@ -122,11 +122,6 @@ public function reduce(\Closure $closure): self return $this->createSubCrawler($elements); } - public function first() - { - return $this->eq(0); - } - public function last() { return $this->eq(\count($this->elements) - 1); @@ -219,7 +214,7 @@ public function html($default = null): string public function evaluate($xpath): self { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function extract($attributes) @@ -321,12 +316,12 @@ public function form(array $values = null, $method = null) public function setDefaultNamespacePrefix($prefix) { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function registerNamespace($prefix, $namespace) { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function getNode($position): ?\DOMElement @@ -351,7 +346,7 @@ public function getIterator(): \ArrayIterator protected function sibling($node, $siblingDir = 'nextSibling') { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } private function selectFromXpath(string $xpath): self diff --git a/src/DomCrawler/Field/ChoiceFormField.php b/src/DomCrawler/Field/ChoiceFormField.php index 2e77d686..83ecd10e 100644 --- a/src/DomCrawler/Field/ChoiceFormField.php +++ b/src/DomCrawler/Field/ChoiceFormField.php @@ -140,7 +140,7 @@ public function setValue($value) public function addChoice(\DOMElement $node) { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } /** @@ -186,7 +186,7 @@ public function availableOptionValues() */ public function disableValidation() { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } /** diff --git a/src/DomCrawler/Field/FormFieldTrait.php b/src/DomCrawler/Field/FormFieldTrait.php index 79c118b1..5ab82e87 100644 --- a/src/DomCrawler/Field/FormFieldTrait.php +++ b/src/DomCrawler/Field/FormFieldTrait.php @@ -36,7 +36,7 @@ public function __construct(WebDriverElement $element) public function getLabel() { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function getName() diff --git a/src/DomCrawler/Form.php b/src/DomCrawler/Form.php index 2c261289..575681d6 100644 --- a/src/DomCrawler/Form.php +++ b/src/DomCrawler/Form.php @@ -100,7 +100,7 @@ public function getElement(): WebDriverElement public function getFormNode() { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function setValues(array $values) @@ -108,6 +108,8 @@ public function setValues(array $values) foreach ($values as $name => $value) { $this->setValue($name, $value); } + + return $this; } /** @@ -202,7 +204,7 @@ public function has($name) public function remove($name) { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } public function set(FormField $field) @@ -242,7 +244,7 @@ public function offsetSet($name, $value) public function offsetUnset($name) { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } protected function getRawUri() diff --git a/src/DomCrawler/Image.php b/src/DomCrawler/Image.php index b1f51fca..5bd5dc3b 100644 --- a/src/DomCrawler/Image.php +++ b/src/DomCrawler/Image.php @@ -38,12 +38,12 @@ public function __construct(WebDriverElement $element) public function getNode() { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } protected function setNode(\DOMElement $node) { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } protected function getRawUri() diff --git a/src/DomCrawler/Link.php b/src/DomCrawler/Link.php index 7274f38d..79155eba 100644 --- a/src/DomCrawler/Link.php +++ b/src/DomCrawler/Link.php @@ -45,12 +45,12 @@ public function getElement(): WebDriverElement public function getNode() { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } protected function setNode(\DOMElement $node) { - $this->throwNotSupported(__METHOD__); + throw $this->createNotSupportedException(__METHOD__); } protected function getRawUri() diff --git a/src/ExceptionThrower.php b/src/ExceptionThrower.php index b024fde7..d13069cb 100644 --- a/src/ExceptionThrower.php +++ b/src/ExceptionThrower.php @@ -20,11 +20,8 @@ */ trait ExceptionThrower { - /** - * @throws \InvalidArgumentException - */ - private function throwNotSupported(string $method) + private function createNotSupportedException(string $method): \InvalidArgumentException { - throw new \InvalidArgumentException(\sprintf('The "%s" method is not supported when using WebDriver.', $method)); + return new \InvalidArgumentException(\sprintf('The "%s" method is not supported when using WebDriver.', $method)); } } diff --git a/src/WebTestAssertionsTrait.php b/src/WebTestAssertionsTrait.php index f66ac946..9e783235 100644 --- a/src/WebTestAssertionsTrait.php +++ b/src/WebTestAssertionsTrait.php @@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait as BaseWebTestAssertionsTrait; +use Symfony\Component\BrowserKit\AbstractBrowser; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use Symfony\Component\Panther\Client as PantherClient; @@ -69,7 +70,7 @@ public static function assertPageTitleContains(string $expectedTitle, string $me * @param array $options An array of options to pass to the createKernel method * @param array $server An array of server parameters * - * @return KernelBrowser A KernelBrowser instance + * @return AbstractBrowser A browser instance */ protected static function createClient(array $options = [], array $server = []) {