Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ on:
jobs:
tests:
uses: zenstruck/.github/.github/workflows/php-test-symfony.yml@main
with:
phpunit: simple-phpunit

code-coverage:
uses: zenstruck/.github/.github/workflows/php-coverage-codecov.yml@main
with:
phpunit: simple-phpunit

composer-validate:
uses: zenstruck/.github/.github/workflows/php-composer-validate.yml@main

cs-check:
uses: zenstruck/.github/.github/workflows/php-cs-fixer.yml@main

sca:
uses: zenstruck/.github/.github/workflows/php-stan.yml@main
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
},
"require-dev": {
"dbrekelmans/bdi": "^0.3.0",
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": "^9.5",
"symfony/mime": ">=4.4.1",
"symfony/panther": "^1.0|^2.0",
"symfony/phpunit-bridge": "^5.3",
"symfony/phpunit-bridge": "^6.0",
"symfony/security-bundle": "^4.4|^5.0|^6.0"
},
"config": {
Expand Down
217 changes: 217 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
parameters:
ignoreErrors:
-
message: "#^Method Zenstruck\\\\Browser\\:\\:assertNotOn\\(\\) has parameter \\$parts with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser.php

-
message: "#^Method Zenstruck\\\\Browser\\:\\:assertOn\\(\\) has parameter \\$parts with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser.php

-
message: "#^Method Zenstruck\\\\Browser\\:\\:selectField\\(\\) has parameter \\$value with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser.php

-
message: "#^Method Zenstruck\\\\Browser\\:\\:selectFieldOptions\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser.php

-
message: "#^Parameter \\#2 \\$path of method Behat\\\\Mink\\\\Element\\\\TraversableElement\\:\\:attachFileToField\\(\\) expects string, array\\<string\\>\\|string given\\.$#"
count: 1
path: src/Browser.php

-
message: "#^Method Zenstruck\\\\Browser\\\\Assertion\\\\SameUrlAssertion\\:\\:__construct\\(\\) has parameter \\$partsToMatch with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/Assertion/SameUrlAssertion.php

-
message: "#^Method Zenstruck\\\\Browser\\\\Assertion\\\\SameUrlAssertion\\:\\:context\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/Assertion/SameUrlAssertion.php

-
message: "#^Method Zenstruck\\\\Browser\\\\Assertion\\\\SameUrlAssertion\\:\\:parseUrl\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/Assertion/SameUrlAssertion.php

-
message: "#^Method Zenstruck\\\\Browser\\\\Assertion\\\\SameUrlAssertion\\:\\:parseUrl\\(\\) should return array but returns array\\<string, int\\|string\\>\\|false\\.$#"
count: 1
path: src/Browser/Assertion/SameUrlAssertion.php

-
message: "#^Parameter \\#1 \\$array of function array_keys expects array, array\\<string, int\\|string\\>\\|false given\\.$#"
count: 1
path: src/Browser/Assertion/SameUrlAssertion.php

-
message: "#^Property Zenstruck\\\\Browser\\\\Assertion\\\\SameUrlAssertion\\:\\:\\$partsToMatch type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/Assertion/SameUrlAssertion.php

-
message: "#^Method Zenstruck\\\\Browser\\\\BrowserKitBrowser\\:\\:delete\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/BrowserKitBrowser.php

-
message: "#^Method Zenstruck\\\\Browser\\\\BrowserKitBrowser\\:\\:get\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/BrowserKitBrowser.php

-
message: "#^Method Zenstruck\\\\Browser\\\\BrowserKitBrowser\\:\\:post\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/BrowserKitBrowser.php

-
message: "#^Method Zenstruck\\\\Browser\\\\BrowserKitBrowser\\:\\:put\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/BrowserKitBrowser.php

-
message: "#^Method Zenstruck\\\\Browser\\\\BrowserKitBrowser\\:\\:request\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/BrowserKitBrowser.php

-
message: "#^Method Zenstruck\\\\Browser\\\\BrowserKitBrowser\\:\\:setDefaultHttpOptions\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/BrowserKitBrowser.php

-
message: "#^Parameter \\#1 \\$token of method Symfony\\\\Component\\\\HttpKernel\\\\Profiler\\\\Profiler\\:\\:loadProfile\\(\\) expects string, array\\|string given\\.$#"
count: 1
path: src/Browser/HttpBrowser.php

-
message: "#^Cannot access offset 'query' on array\\{scheme\\?\\: string, host\\?\\: string, port\\?\\: int, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\|false\\.$#"
count: 2
path: src/Browser/HttpOptions.php

-
message: "#^Method Zenstruck\\\\Browser\\\\HttpOptions\\:\\:__construct\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Method Zenstruck\\\\Browser\\\\HttpOptions\\:\\:create\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Method Zenstruck\\\\Browser\\\\HttpOptions\\:\\:files\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Method Zenstruck\\\\Browser\\\\HttpOptions\\:\\:merge\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Method Zenstruck\\\\Browser\\\\HttpOptions\\:\\:parameters\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Method Zenstruck\\\\Browser\\\\HttpOptions\\:\\:server\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Method Zenstruck\\\\Browser\\\\HttpOptions\\:\\:withBody\\(\\) has parameter \\$body with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Method Zenstruck\\\\Browser\\\\HttpOptions\\:\\:withFiles\\(\\) has parameter \\$files with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Method Zenstruck\\\\Browser\\\\HttpOptions\\:\\:withHeaders\\(\\) has parameter \\$headers with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Method Zenstruck\\\\Browser\\\\HttpOptions\\:\\:withQuery\\(\\) has parameter \\$query with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Method Zenstruck\\\\Browser\\\\HttpOptions\\:\\:withServer\\(\\) has parameter \\$server with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Parameter \\#1 \\$options of class Zenstruck\\\\Browser\\\\HttpOptions constructor expects array, array\\|Zenstruck\\\\Browser\\\\HttpOptions given\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, int\\|string given\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Property Zenstruck\\\\Browser\\\\HttpOptions\\:\\:\\$options type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/HttpOptions.php

-
message: "#^Method Zenstruck\\\\Browser\\\\Mink\\\\BrowserKitDriver\\:\\:getFormField\\(\\) should return Symfony\\\\Component\\\\DomCrawler\\\\Field\\\\FormField but returns array\\<Symfony\\\\Component\\\\DomCrawler\\\\Field\\\\FormField\\>\\|Symfony\\\\Component\\\\DomCrawler\\\\Field\\\\FormField\\.$#"
count: 1
path: src/Browser/Mink/BrowserKitDriver.php

-
message: "#^Method Zenstruck\\\\Browser\\\\Mink\\\\BrowserKitDriver\\:\\:getResponseHeaders\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/Mink/BrowserKitDriver.php

-
message: "#^Method Zenstruck\\\\Browser\\\\Mink\\\\BrowserKitDriver\\:\\:getValue\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/Mink/BrowserKitDriver.php

-
message: "#^Method Zenstruck\\\\Browser\\\\Mink\\\\BrowserKitDriver\\:\\:setValue\\(\\) has parameter \\$value with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/Mink/BrowserKitDriver.php

-
message: "#^Parameter \\#1 \\$path of function dirname expects string, string\\|false\\|null given\\.$#"
count: 1
path: src/Browser/Mink/BrowserKitDriver.php

-
message: "#^Parameter \\#1 \\$value of method Symfony\\\\Component\\\\DomCrawler\\\\Field\\\\FormField\\:\\:setValue\\(\\) expects string\\|null, array\\|bool\\|string given\\.$#"
count: 1
path: src/Browser/Mink/BrowserKitDriver.php

-
message: "#^Method Zenstruck\\\\Browser\\\\Mink\\\\PantherDriver\\:\\:getValue\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/Mink/PantherDriver.php

-
message: "#^Method Zenstruck\\\\Browser\\\\Mink\\\\PantherDriver\\:\\:setValue\\(\\) has parameter \\$value with no value type specified in iterable type array\\.$#"
count: 1
path: src/Browser/Mink/PantherDriver.php

-
message: "#^Parameter \\#1 \\$value of method Symfony\\\\Component\\\\DomCrawler\\\\Field\\\\FormField\\:\\:setValue\\(\\) expects string\\|null, array\\|bool\\|string given\\.$#"
count: 1
path: src/Browser/Mink/PantherDriver.php

-
message: "#^Parameter \\#3 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|bool\\|string given\\.$#"
count: 1
path: src/Browser/Mink/PantherDriver.php

7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- phpstan-baseline.neon

parameters:
level: 8
paths:
- src
14 changes: 11 additions & 3 deletions src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Browser

private Mink $mink;
private ?string $sourceDir = null;

/** @var string[] */
private array $savedSources = [];

/**
Expand Down Expand Up @@ -175,8 +177,8 @@ final public function checkField(string $selector): self
{
$field = $this->documentElement()->findField($selector);

if ($field && 'radio' === \mb_strtolower($field->getAttribute('type'))) {
$this->documentElement()->selectFieldOption($selector, $field->getAttribute('value'));
if ($field && 'radio' === \mb_strtolower((string) $field->getAttribute('type'))) {
$this->documentElement()->selectFieldOption($selector, (string) $field->getAttribute('value'));

return $this;
}
Expand Down Expand Up @@ -273,7 +275,11 @@ final public function click(string $selector): self
try {
$this->documentElement()->clickLink($selector);
} catch (ElementNotFoundException $e) {
$this->documentElement()->find('css', $selector)->click();
if (!$element = $this->documentElement()->find('css', $selector)) {
throw $e;
}

$element->click();
}
}

Expand Down Expand Up @@ -452,6 +458,8 @@ public function dumpCurrentState(string $filename): void

/**
* @internal
*
* @return array<string,string[]>
*/
public function savedArtifacts(): array
{
Expand Down
17 changes: 17 additions & 0 deletions src/Browser/BrowserKitBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@

/**
* @author Kevin Bond <kevinbond@gmail.com>
*
* @template B of AbstractBrowser
*/
abstract class BrowserKitBrowser extends Browser
{
/** @var B */
private AbstractBrowser $inner;
private ?HttpOptions $defaultHttpOptions = null;

/**
* @param B $inner
*/
public function __construct(AbstractBrowser $inner)
{
$this->inner = $inner;
Expand Down Expand Up @@ -119,6 +125,8 @@ final public function request(string $method, string $url, $options = []): self
/**
* @see request()
*
* @param HttpOptions|array $options
*
* @return static
*/
final public function get(string $url, $options = []): self
Expand All @@ -129,6 +137,8 @@ final public function get(string $url, $options = []): self
/**
* @see request()
*
* @param HttpOptions|array $options
*
* @return static
*/
final public function post(string $url, $options = []): self
Expand All @@ -139,6 +149,8 @@ final public function post(string $url, $options = []): self
/**
* @see request()
*
* @param HttpOptions|array $options
*
* @return static
*/
final public function put(string $url, $options = []): self
Expand All @@ -149,6 +161,8 @@ final public function put(string $url, $options = []): self
/**
* @see request()
*
* @param HttpOptions|array $options
*
* @return static
*/
final public function delete(string $url, $options = []): self
Expand Down Expand Up @@ -237,6 +251,9 @@ final public function assertJsonMatches(string $expression, $expected): self

abstract public function profile(): Profile;

/**
* @return B
*/
final protected function inner(): AbstractBrowser
{
return $this->inner;
Expand Down
2 changes: 2 additions & 0 deletions src/Browser/HttpBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/**
* @author Kevin Bond <kevinbond@gmail.com>
*
* @extends BrowserKitBrowser<SymfonyHttpBrowser>
*/
class HttpBrowser extends BrowserKitBrowser
{
Expand Down
4 changes: 4 additions & 0 deletions src/Browser/HttpOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ final public static function create($options = []): self
}

/**
* @param mixed $body
*
* @return static
*/
final public static function json($body = null): self
Expand All @@ -70,6 +72,8 @@ final public static function ajax(): self
}

/**
* @param mixed $body
*
* @return static
*/
final public static function jsonAjax($body = null): self
Expand Down
Loading