8000 Merge pull request #322 from dunglas/fix-tests · symfony/panther@036cbf6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 036cbf6

Browse files
authored
Merge pull request #322 from dunglas/fix-tests
Fix tests
2 parents e557c9a + efa5a90 commit 036cbf6

11 files changed

+43
-48
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cache:
1919

2020
before_install:
2121
- if [[ $lint = '1' ]]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.16.1/php-cs-fixer.phar; fi
22-
- if [[ $lint = '1' ]]; then wget https://github.com/phpstan/phpstan/releases/download/0.11.19/phpstan.phar; fi
22+
- if [[ $lint = '1' ]]; then wget https://github.com/phpstan/phpstan/releases/download/0.12.8/phpstan.phar; fi
2323

2424
before_script:
2525
- phpenv config-rm xdebug.ini
@@ -34,4 +34,4 @@ install:
3434
script:
3535
- vendor/bin/simple-phpunit
3636
- if [[ $lint = '1' ]]; then php php-cs-fixer.phar fix --dry-run --diff --no-ansi; fi
37-
- if [[ $lint = '1' ]]; then php phpstan.phar analyse src tests --level=6; fi
37+
- if [[ $lint = '1' ]]; then php phpstan.phar analyse src tests --level=5; fi

phpstan.neon

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ parameters:
33
- vendor/bin/.phpunit/phpunit-8.3-0/vendor/autoload.php
44
inferPrivatePropertyTypeFromConstructor: true
55
ignoreErrors:
6-
# https://github.com/symfony/symfony/pull/33278
7-
- '#KernelBrowser#'
6+
- message: '#.+#'
7+
path: tests/DummyKernel.php
8+
# Expected
9+
- '#Method Symfony\\Component\\Panther\\PantherTestCase::createPantherClient\(\) should return Symfony\\Component\\Panther\\Client but returns Symfony\\Component\\BrowserKit\\AbstractBrowser\|null\.#'
810
# False positive
9-
- '#getClient#'
10-
- '#Result of && is always false\.#'
11-
- '#Ternary operator condition is always false\.#'
12-
- '#Call to function method_exists\(\) with #'
11+
- '#Call to an undefined method ReflectionType::getName\(\)\.#'
1312
# To fix in PHP WebDriver
1413
- '#Parameter \#2 \$desired_capabilities of static method Facebook\\WebDriver\\Remote\\RemoteWebDriver::create\(\) expects array\|Facebook\\WebDriver\\Remote\\DesiredCapabilities\|null, Facebook\\WebDriver\\WebDriverCapabilities given\.#'
1514
# Require a redesign of the underlying Symfony components
1615
- '#Call to an undefined method DOMNode::getTagName\(\)\.#'
17-
- '#Panther\\[a-zA-Z\\]+::__construct\(\) does not call parent constructor from Symfony\\Component\\(BrowserKit|DomCrawler)\\[a-zA-Z]+\.#'
1816
- '#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\(\)#'
17+
- '#Method Symfony\\Component\\Panther\\DomCrawler\\Crawler::getIterator\(\) should return ArrayIterator&iterable<DOMNode> but returns ArrayIterator<mixed, Facebook\\WebDriver\\WebDriverElement>\.#'
18+
- '#Method Symfony\\Component\\Panther\\DomCrawler\\Crawler::.+\(\) should return static\(Symfony\\Component\\Panther\\DomCrawler\\Crawler\) but returns Symfony\\Component\\Panther\\DomCrawler\\Crawler#'

src/Cookie/CookieJar.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public function clear()
6363

6464
public function updateFromSetCookie(array $setCookies, $uri = null)
6565
{
66-
$this->throwNotSupported(__METHOD__);
66+
throw $this->createNotSupportedException(__METHOD__);
6767
}
6868

6969
public function updateFromResponse(Response $response, $uri = null)
7070
{
71-
$this->throwNotSupported(__METHOD__);
71+
throw $this->createNotSupportedException(__METHOD__);
7272
}
7373

7474
public function all()
@@ -83,17 +83,17 @@ public function all()
8383

8484
public function allValues($uri, $returnsRawValue = false)
8585
{
86-
$this->throwNotSupported(__METHOD__);
86+
throw $this->createNotSupportedException(__METHOD__);
8787
}
8888

8989
public function allRawValues($uri)
9090
{
91-
$this->throwNotSupported(__METHOD__);
91+
throw $this->createNotSupportedException(__METHOD__);
9292
}
9393

9494
public function flushExpiredCookies()
9595
{
96-
$this->throwNotSupported(__METHOD__);
96+
throw $this->createNotSupportedException(__METHOD__);
9797
}
9898

9999
private function symfonyToWebDriver(Cookie $cookie): WebDriverCookie

src/DomCrawler/Crawler.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,47 +43,47 @@ public function __construct(array $elements = [], WebDriver $webDriver, ?string
4343

4444
public function clear(): void
4545
{
46-
$this->throwNotSupported(__METHOD__);
46+
throw $this->createNotSupportedException(__METHOD__);
4747
}
4848

4949
public function add($node): void
5050
{
51-
$this->throwNotSupported(__METHOD__);
51+
throw $this->createNotSupportedException(__METHOD__);
5252
}
5353

5454
public function addContent($content, $type = null): void
5555
{
56-
$this->throwNotSupported(__METHOD__);
56+
throw $this->createNotSupportedException(__METHOD__);
5757
}
5858

5959
public function addHtmlContent($content, $charset = 'UTF-8'): void
6060
{
61-
$this->throwNotSupported(__METHOD__);
61+
throw $this->createNotSupportedException(__METHOD__);
6262
}
6363

6464
public function addXmlContent($content, $charset = 'UTF-8', $options = LIBXML_NONET): void
6565
{
66-
$this->throwNotSupported(__METHOD__);
66+
throw $this->createNotSupportedException(__METHOD__);
6767
}
6868

6969
public function addDocument(\DOMDocument $dom): void
7070
{
71-
$this->throwNotSupported(__METHOD__);
71+
throw $this->createNotSupportedException(__METHOD__);
7272
}
7373

7474
public function addNodeList(\DOMNodeList $nodes): void
7575
{
76-
$this->throwNotSupported(__METHOD__);
76+
throw $this->createNotSupportedException(__METHOD__);
7777
}
7878

7979
public function addNodes(array $nodes): void
8080
{
81-
$this->throwNotSupported(__METHOD__);
81+
throw $this->createNotSupportedException(__METHOD__);
8282
}
8383

8484
public function addNode(\DOMNode $node): void
8585
{
86-
$this->throwNotSupported(__METHOD__);
86+
throw $this->createNotSupportedException(__METHOD__);
8787
}
8888

8989
public function eq($position): self
@@ -122,11 +122,6 @@ public function reduce(\Closure $closure): self
122122
return $this->createSubCrawler($elements);
123123
}
124124

125-
public function first()
126-
{
127-
return $this->eq(0);
128-
}
129-
130125
public function last()
131126
{
132127
return $this->eq(\count($this->elements) - 1);
@@ -219,7 +214,7 @@ public function html($default = null): string
219214

220215
public function evaluate($xpath): self
221216
{
222-
$this->throwNotSupported(__METHOD__);
217+
throw $this->createNotSupportedException(__METHOD__);
223218
}
224219

225220
public function extract($attributes)
@@ -321,12 +316,12 @@ public function form(array $values = null, $method = null)
321316

322317
public function setDefaultNamespacePrefix($prefix)
323318
{
324-
$this->throwNotSupported(__METHOD__);
319+
throw $this->createNotSupportedException(__METHOD__);
325320
}
326321

327322
public function registerNamespace($prefix, $namespace)
328323
{
329-
$this->throwNotSupported(__METHOD__);
324+
throw $this->createNotSupportedException(__METHOD__);
330325
}
331326

332327
public function getNode($position): ?\DOMElement
@@ -351,7 +346,7 @@ public function getIterator(): \ArrayIterator
351346

352347
protected function sibling($node, $siblingDir = 'nextSibling')
353348
{
354-
$this->throwNotSupported(__METHOD__);
349+
throw $this->createNotSupportedException(__METHOD__);
355350
}
356351

357352
private function selectFromXpath(string $xpath): self

src/DomCrawler/Field/ChoiceFormField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function setValue($value)
140140

141141
public function addChoice(\DOMElement $node)
142142
{
143-
$this->throwNotSupported(__METHOD__);
143+
throw $this->createNotSupportedException(__METHOD__);
144144
}
145145

146146
/**
@@ -186,7 +186,7 @@ public function availableOptionValues()
186186
*/
187187
public function disableValidation()
188188
{
189-
$this->throwNotSupported(__METHOD__);
189+
throw $this->createNotSupportedException(__METHOD__);
190190
}
191191

192192
/**

src/DomCrawler/Field/FormFieldTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(WebDriverElement $element)
3636

3737
public function getLabel()
3838
{
39-
$this->throwNotSupported(__METHOD__);
39+
throw $this->createNotSupportedException(__METHOD__);
4040
}
4141

4242
public function getName()

src/DomCrawler/Form.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,16 @@ public function getElement(): WebDriverElement
100100

101101
public function getFormNode()
102102
{
103-
$this->throwNotSupported(__METHOD__);
103+
throw $this->createNotSupportedException(__METHOD__);
104104
}
105105

106106
public function setValues(array $values)
107107
{
108108
foreach ($values as $name => $value) {
109109
$this->setValue($name, $value);
110110
}
111+
112+
return $this;
111113
}
112114

113115
/**
@@ -202,7 +204,7 @@ public function has($name)
202204

203205
public function remove($name)
204206
{
205-
$this->throwNotSupported(__METHOD__);
207+
throw $this->createNotSupportedException(__METHOD__);
206208
}
207209

208210
public function set(FormField $field)
@@ -242,7 +244,7 @@ public function offsetSet($name, $value)
242244

243245
public function offsetUnset($name)
244246
{
245-
$this->throwNotSupported(__METHOD__);
247+
throw $this->createNotSupportedException(__METHOD__);
246248
}
247249

248250
10000 protected function getRawUri()

src/DomCrawler/Image.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public function __construct(WebDriverElement $element)
3838

3939
public function getNode()
4040
{
41-
$this->throwNotSupported(__METHOD__);
41+
throw $this->createNotSupportedException(__METHOD__);
4242
}
4343

4444
protected function setNode(\DOMElement $node)
4545
{
46-
$this->throwNotSupported(__METHOD__);
46+
throw $this->createNotSupportedException(__METHOD__);
4747
}
4848

4949
protected function getRawUri()

src/DomCrawler/Link.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public function getElement(): WebDriverElement
4545

4646
public function getNode()
4747
{
48-
$this->throwNotSupported(__METHOD__);
48+
throw $this->createNotSupportedException(__METHOD__);
4949
}
5050

5151
protected function setNode(\DOMElement $node)
5252
{
53-
$this->throwNotSupported(__METHOD__);
53+
throw $this->createNotSupportedException(__METHOD__);
5454
}
5555

5656
protected function getRawUri()

src/ExceptionThrower.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
*/
2121
trait ExceptionThrower
2222
{
23-
/**
24-
* @throws \InvalidArgumentException
25-
*/
26-
private function throwNotSupported(string $method)
23+
private function createNotSupportedException(string $method): \InvalidArgumentException
2724
{
28-
throw new \InvalidArgumentException(\sprintf('The "%s" method is not supported when using WebDriver.', $method));
25+
return new \InvalidArgumentException(\sprintf('The "%s" method is not supported when using WebDriver.', $method));
2926
}
3027
}

src/WebTestAssertionsTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
1717
use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait as BaseWebTestAssertionsTrait;
18+
use Symfony\Component\BrowserKit\AbstractBrowser;
1819
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1920
use Symfony\Component\Panther\Client as PantherClient;
2021

@@ -69,7 +70,7 @@ public static function assertPageTitleContains(string $expectedTitle, string $me
6970
* @param array $options An array of options to pass to the createKernel method
7071
* @param array $server An array of server parameters
7172
*
72-
* @return KernelBrowser A KernelBrowser instance
73+
* @return AbstractBrowser A browser instance
7374
*/
7475
protected static function createClient(array $options = [], array $server = [])
7576
{

0 commit comments

Comments
 (0)
0