8000 Fix tests · symfony/panther@e6fa3e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit e6fa3e3

Browse files
committed
Fix tests
1 parent 40ccacf commit e6fa3e3

13 files changed

+51
-57
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
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

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"php": ">=7.1",
2121
"php-webdriver/webdriver": "^1.8.1",
2222
"symfony/browser-kit": "^4.3 || ^5.0",
23-
"symfony/dom-crawler": "^4.3 || ^5.0",
23+
"symfony/dom-crawler": "^4.3 || ^5.0, !=4.4.6, !=5.0.6",
2424
"symfony/http-client": "^4.3 || ^5.0",
2525
"symfony/polyfill-php72": "^1.9",
2626
"symfony/process": "^3.4 || ^4.0 || ^5.0"

phpstan.neon

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ 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+
# Expected
7+
- '#Method Symfony\\Component\\Panther\\PantherTestCase::createPantherClient\(\) should return Symfony\\Component\\Panther\\Client but returns Symfony\\Component\\BrowserKit\\AbstractBrowser\|null\.#'
8+
- '#Symfony\\Component\\Panther\\Tests\\DummyKernel#'
89
# False positive
9-
- '#getClient#'
10-
- '#Result of && is always false\.#'
11-
- '#Ternary operator condition is always false\.#'
12-
- '#Call to function method_exists\(\) with #'
10+
- '#Call to an undefined method ReflectionType::getName\(\)\.#'
1311
# To fix in PHP WebDriver
1412
- '#Parameter \#2 \$desired_capabilities of static method Facebook\\WebDriver\\Remote\\RemoteWebDriver::create\(\) expects array\|Facebook\\WebDriver\\Remote\\DesiredCapabilities\|null, Facebook\\WebDriver\\WebDriverCapabilities given\.#'
1513
# Require a redesign of the underlying Symfony components
1614
- '#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]+\.#'
1815
- '#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\(\)#'
16+
- '#Method Symfony\\Component\\Panther\\DomCrawler\\Crawler::getIterator\(\) should return ArrayIterator&iterable<DOMNode> but returns ArrayIterator<mixed, Facebook\\WebDriver\\WebDriverElement>\.#'

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
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
{

tests/DummyKernel.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function unserialize($serialized)
3131
{
3232
}
3333

34-
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
34+
public function handle(Request $request, int $type = self::MASTER_REQUEST, bool $catch = true)
3535
{
3636
}
3737

@@ -55,11 +55,11 @@ public function getBundles()
5555
{
5656
}
5757

58-
public function getBundle($name, $first = true)
58+
public function getBundle(string $name)
5959
{
6060
}
6161

62-
public function locateResource($name, $dir = null, $first = true)
62+
public function locateResource(string $name)
6363
{
6464
}
6565

@@ -82,35 +82,36 @@ public function getRootDir()
8282
public function getContainer()
8383
{
8484
return new class() implements ContainerInterface {
85-
public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
85+
public function get($id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
8686
{
87+
return null;
8788
}
8889

8990
public function has($id)
9091
{
9192
return false;
9293
}
9394

94-
public function set($id, $service)
95+
public function set(string $id, $service)
9596
{
9697
}
9798

98-
public function initialized($id)
99+
public function initialized(string $id)
99100
{
100101
return true;
101102
}
102103

103-
public function getParameter($name)
104+
public function getParameter(string $name)
104105
{
105106
return null;
106107
}
107108

108-
public function hasParameter($name)
109+
public function hasParameter(string $name)
109110
{
110111
return false;
111112
}
112113

113-
public function setParameter($name, $value)
114+
public function setParameter(string $name, $value)
114115
{
115116
}
116117
};

0 commit comments

Comments
 (0)
0