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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.github export-ignore
/tests export-ignore
/stubs export-ignore
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@
}
],
"require": {
"php": ">=8.0",
"php": ">=8.1",
"behat/mink": "^1.8",
"symfony/browser-kit": "^5.4|^6.0|^7.0",
"symfony/css-selector": "^5.4|^6.0|^7.0",
"symfony/dom-crawler": "^5.4|^6.0|^7.0",
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
"symfony/browser-kit": "^6.4|^7.0|^8.0",
"symfony/css-selector": "^6.4|^7.0|^8.0",
"symfony/dom-crawler": "^6.4|^7.0|^8.0",
"symfony/framework-bundle": "^6.4|^7.0|^8.0",
"zenstruck/assert": "^1.1",
"zenstruck/callback": "^1.4.2"
},
"require-dev": {
"dbrekelmans/bdi": "^1.0",
"justinrainbow/json-schema": "^5.3",
"mtdowling/jmespath.php": "^2.6",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^9.6.21|^10.4",
"symfony/mime": "^5.4|^6.0|^7.0",
"symfony/console": "^6.4|^7.0|^8.0",
"symfony/mime": "^6.4|^7.0|^8.0",
"symfony/panther": "^1.1|^2.0.1",
"symfony/phpunit-bridge": "^6.0|^7.0",
"symfony/security-bundle": "^5.4|^6.0|^7.0"
"symfony/phpunit-bridge": "^6.4|^7.0|^8.0",
"symfony/security-bundle": "^6.4|^7.0|^8.0"
},
"suggest": {
"justinrainbow/json-schema": "Json schema validator. Needed to use Json::assertMatchesSchema().",
Expand Down
142 changes: 0 additions & 142 deletions phpstan-baseline.neon

This file was deleted.

6 changes: 2 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
includes:
- phpstan-baseline.neon

parameters:
level: 8
level: 5
paths:
- src
- stubs

excludePaths:
# skip phpunit 10 missing classes
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
bootstrap="tests/bootstrap.php"
failOnRisky="true"
failOnWarning="true"
colors="true"
Expand Down
7 changes: 6 additions & 1 deletion src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
use Psr\Container\ContainerInterface;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\CookieJar;
use Symfony\Component\BrowserKit\Request;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Response;
use Zenstruck\Browser\Assertion\SameUrlAssertion;
use Zenstruck\Browser\Component;
use Zenstruck\Browser\Session;
Expand Down Expand Up @@ -47,6 +49,9 @@ public function __construct(Driver $driver, array $options = [])
$this->sourceDebug = $options['source_debug'] ?? false;
}

/**
* @return AbstractBrowser<Request, Response>
*/
final public function client(): AbstractBrowser
{
return $this->session->client();
Expand Down Expand Up @@ -409,7 +414,7 @@ final public function use(callable $callback): self
final public function saveSource(string $filename): self
{
if ($this->sourceDir) {
$filename = \sprintf('%s/%s', mb_rtrim($this->sourceDir, '/'), mb_ltrim($filename, '/'));
$filename = \sprintf('%s/%s', \rtrim($this->sourceDir, '/'), \ltrim($filename, '/'));
}

(new Filesystem())->dumpFile($this->savedSources[] = $filename, $this->session()->source($this->sourceDebug));
Expand Down
2 changes: 1 addition & 1 deletion src/Browser/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function decoded()
return $this->decoded;
}

if ('' === mb_trim($this->source)) {
if ('' === \trim($this->source)) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Browser/KernelBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final public function __construct(SymfonyKernelBrowser $client, array $options =
$client->followRedirects((bool) ($options['follow_redirects'] ?? true));
$client->catchExceptions((bool) ($options['catch_exceptions'] ?? true));

parent::__construct(new BrowserKitDriver($client), $options);
parent::__construct(new BrowserKitDriver($client), $options); // @phpstan-ignore argument.type
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Browser/PantherBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ final public function pause(): self
final public function takeScreenshot(string $filename): self
{
if ($this->screenshotDir) {
$filename = \sprintf('%s/%s', mb_rtrim($this->screenshotDir, '/'), mb_ltrim($filename, '/'));
$filename = \sprintf('%s/%s', \rtrim($this->screenshotDir, '/'), \ltrim($filename, '/'));
}

$this->client()->takeScreenshot($this->savedScreenshots[] = $filename);
Expand All @@ -160,7 +160,7 @@ final public function takeScreenshot(string $filename): self
final public function saveConsoleLog(string $filename): self
{
if ($this->consoleLogDir) {
$filename = \sprintf('%s/%s', mb_rtrim($this->consoleLogDir, '/'), mb_ltrim($filename, '/'));
$filename = \sprintf('%s/%s', \rtrim($this->consoleLogDir, '/'), \ltrim($filename, '/'));
}

$log = $this->client()->manage()->getLog('browser');
Expand Down
5 changes: 5 additions & 0 deletions src/Browser/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use Behat\Mink\Session as MinkSession;
use Behat\Mink\WebAssert;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Request;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\HttpFoundation\Response;
use Zenstruck\Assert as ZenstruckAssert;
use Zenstruck\Browser\Session\Assert;
use Zenstruck\Browser\Session\Driver;
Expand All @@ -44,6 +46,9 @@ public static function varDump($what): void
\function_exists('dump') ? dump($what) : \var_dump($what);
}

/**
* @return AbstractBrowser<Request, Response>
*/
public function client(): AbstractBrowser
{
return $this->getDriver()->client();
Expand Down
9 changes: 9 additions & 0 deletions src/Browser/Session/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Behat\Mink\Driver\CoreDriver;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Request;
use Symfony\Component\HttpFoundation\Response;
use Zenstruck\Browser\HttpOptions;

/**
Expand All @@ -23,14 +25,21 @@
*/
abstract class Driver extends CoreDriver
{
/** @var AbstractBrowser<Request, Response> */
private AbstractBrowser $client;
private bool $started = false;

/**
* @param AbstractBrowser<Request, Response> $client
*/
public function __construct(AbstractBrowser $client)
{
$this->client = $client;
}

/**
* @return AbstractBrowser<Request, Response>
*/
public function client(): AbstractBrowser
{
return $this->client;
Expand Down
11 changes: 6 additions & 5 deletions src/Browser/Session/Driver/BrowserKitDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function getTagName($xpath): string

public function getText($xpath): string
{
return mb_trim($this->getFilteredCrawler($xpath)->text(null, true));
return \trim($this->getFilteredCrawler($xpath)->text(null, true));
}

public function getHtml($xpath): string
Expand All @@ -239,10 +239,7 @@ public function getAttribute($xpath, $name): ?string
return null;
}

/**
* @return array|bool|string|null
*/
public function getValue($xpath)
public function getValue($xpath) // @phpstan-ignore return.unusedType
{
if (\in_array($this->getAttribute($xpath, 'type'), ['submit', 'image', 'button'], true)) {
return $this->getAttribute($xpath, 'value');
Expand Down Expand Up @@ -522,6 +519,10 @@ private function getFormNode(\DOMElement $element): \DOMElement
if (null === $formNode = $formNode->parentNode) {
throw new DriverException('The selected node does not have a form ancestor.');
}

if (!$formNode instanceof \DOMElement) {
throw new DriverException('The selected node does not have a form ancestor.');
}
} while ('form' !== $formNode->nodeName);

return $formNode;
Expand Down
11 changes: 4 additions & 7 deletions src/Browser/Session/Driver/PantherDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class PantherDriver extends Driver

public function __construct(Client $client)
{
parent::__construct($client);
parent::__construct($client); // @phpstan-ignore argument.type
}

public function request(string $method, string $url, HttpOptions $options): void
Expand Down Expand Up @@ -89,13 +89,10 @@ public function getText($xpath): string
return $this->client()->getTitle();
}

return mb_trim($crawler->text(null, true));
return \trim($crawler->text(null, true));
}

/**
* @return array|bool|string|null
*/
public function getValue($xpath)
public function getValue($xpath) // @phpstan-ignore return.unusedType
{
try {
$formField = $this->formField($xpath);
Expand Down Expand Up @@ -237,7 +234,7 @@ public function executeScript($script): void

public function evaluateScript($script)
{
if (0 !== \mb_strpos(mb_trim($script), 'return ')) {
if (0 !== \mb_strpos(\trim($script), 'return ')) {
$script = 'return '.$script;
}

Expand Down
Loading