Skip to content

Commit

Permalink
Merge pull request #322 from dunglas/fix-tests
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
dunglas committed Apr 22, 2020
2 parents 40ccacf + d716723 commit 1dc9152
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -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
Expand All @@ -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
14 changes: 7 additions & 7 deletions phpstan.neon
Expand Up @@ -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<DOMNode> but returns ArrayIterator<mixed, Facebook\\WebDriver\\WebDriverElement>\.#'
- '#Method Symfony\\Component\\Panther\\DomCrawler\\Crawler::.+\(\) should return static\(Symfony\\Component\\Panther\\DomCrawler\\Crawler\) but returns Symfony\\Component\\Panther\\DomCrawler\\Crawler#'
10 changes: 5 additions & 5 deletions src/Cookie/CookieJar.php
Expand Up @@ -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()
Expand 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
Expand Down
31 changes: 13 additions & 18 deletions src/DomCrawler/Crawler.php
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/DomCrawler/Field/ChoiceFormField.php
Expand Up @@ -140,7 +140,7 @@ public function setValue($value)

public function addChoice(\DOMElement $node)
{
$this->throwNotSupported(__METHOD__);
throw $this->createNotSupportedException(__METHOD__);
}

/**
Expand Down Expand Up @@ -186,7 +186,7 @@ public function availableOptionValues()
*/
public function disableValidation()
{
$this->throwNotSupported(__METHOD__);
throw $this->createNotSupportedException(__METHOD__);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/DomCrawler/Field/FormFieldTrait.php
Expand Up @@ -36,7 +36,7 @@ public function __construct(WebDriverElement $element)

public function getLabel()
{
$this->throwNotSupported(__METHOD__);
throw $this->createNotSupportedException(__METHOD__);
}

public function getName()
Expand Down
8 changes: 5 additions & 3 deletions src/DomCrawler/Form.php
Expand Up @@ -100,14 +100,16 @@ public function getElement(): WebDriverElement

public function getFormNode()
{
$this->throwNotSupported(__METHOD__);
throw $this->createNotSupportedException(__METHOD__);
}

public function setValues(array $values)
{
foreach ($values as $name => $value) {
$this->setValue($name, $value);
}

return $this;
}

/**
Expand Down Expand Up @@ -202,7 +204,7 @@ public function has($name)

public function remove($name)
{
$this->throwNotSupported(__METHOD__);
throw $this->createNotSupportedException(__METHOD__);
}

public function set(FormField $field)
Expand Down Expand Up @@ -242,7 +244,7 @@ public function offsetSet($name, $value)

public function offsetUnset($name)
{
$this->throwNotSupported(__METHOD__);
throw $this->createNotSupportedException(__METHOD__);
}

protected function getRawUri()
Expand Down
4 changes: 2 additions & 2 deletions src/DomCrawler/Image.php
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/DomCrawler/Link.php
Expand Up @@ -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()
Expand Down
7 changes: 2 additions & 5 deletions src/ExceptionThrower.php
Expand Up @@ -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));
}
}
3 changes: 2 additions & 1 deletion src/WebTestAssertionsTrait.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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 = [])
{
Expand Down

0 comments on commit 1dc9152

Please sign in to comment.