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
28 changes: 8 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ on:

jobs:
tests:
name: PHP ${{ matrix.php }}, SF ${{ matrix.symfony }} - ${{ matrix.stability }}
name: PHP ${{ matrix.php }}, SF ${{ matrix.symfony }} - ${{ matrix.versions }}
runs-on: ubuntu-latest
strategy:
matrix:
php: [7.4, 8.0]
stability: [hightest]
symfony: [4.4.*, 5.2.*, 5.3.*]
versions: [hightest]
symfony: [4.4.*, 5.3.*, 5.4.*]
include:
- php: 7.4
stability: lowest
versions: lowest
symfony: '*'
# - php: 8.0
# stability: highest
# symfony: '5.4.*@dev'
# versions: highest
# symfony: '6.0.*'
steps:
- name: Checkout code
uses: actions/checkout@v2.3.3
Expand All @@ -31,21 +31,12 @@ jobs:
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Setup chromedriver
uses: nanasess/setup-chromedriver@v1.0.1

- name: Install Symfony Flex
run: composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-main

- name: Set minimum-stability to dev
run: composer config minimum-stability dev
if: ${{ contains(matrix.symfony, '@dev') }}
tools: flex

- name: Install dependencies
uses: ramsey/composer-install@v1
with:
dependency-versions: ${{ matrix.stability }}
dependency-versions: ${{ matrix.versions }}
composer-options: --prefer-dist
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}
Expand Down Expand Up @@ -80,9 +71,6 @@ jobs:
coverage: xdebug
ini-values: xdebug.mode=coverage

- name: Setup chromedriver
uses: nanasess/setup-chromedriver@v1.0.1

- name: Install dependencies
uses: ramsey/composer-install@v1
with:
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
},
"autoload-dev": {
"psr-4": { "Zenstruck\\Browser\\Tests\\": "tests/" }
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
65 changes: 34 additions & 31 deletions src/Browser/Mink/BrowserKitDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,37 +108,37 @@ public function setRemoveScriptFromUrl($remove = true)
$this->removeScriptFromUrl = (bool) $remove;
}

public function start()
public function start(): void
{
$this->started = true;
}

public function isStarted()
public function isStarted(): bool
{
return $this->started;
}

public function stop()
public function stop(): void
{
$this->reset();
$this->started = false;
}

public function reset()
public function reset(): void
{
// Restarting the client resets the cookies and the history
$this->client->restart();
$this->forms = [];
$this->serverParameters = [];
}

public function visit($url)
public function visit($url): void
{
$this->client->request('GET', $this->prepareUrl($url), [], [], $this->serverParameters);
$this->forms = [];
}

public function getCurrentUrl()
public function getCurrentUrl(): string
{
// This should be encapsulated in `getRequest` method if any other method needs the request
try {
Expand All @@ -155,25 +155,25 @@ public function getCurrentUrl()
return $request->getUri();
}

public function reload()
public function reload(): void
{
$this->client->reload();
$this->forms = [];
}

public function forward()
public function forward(): void
{
$this->client->forward();
$this->forms = [];
}

public function back()
public function back(): void
{
$this->client->back();
$this->forms = [];
}

public function setBasicAuth($user, $password)
public function setBasicAuth($user, $password): void
{
if (false === $user) {
unset($this->serverParameters['PHP_AUTH_USER'], $this->serverParameters['PHP_AUTH_PW']);
Expand All @@ -185,7 +185,7 @@ public function setBasicAuth($user, $password)
$this->serverParameters['PHP_AUTH_PW'] = $password;
}

public function setRequestHeader($name, $value)
public function setRequestHeader($name, $value): void
{
$contentHeaders = ['CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true];
$name = \str_replace('-', '_', \mb_strtoupper($name));
Expand All @@ -198,12 +198,12 @@ public function setRequestHeader($name, $value)
$this->serverParameters[$name] = $value;
}

public function getResponseHeaders()
public function getResponseHeaders(): array
{
return $this->getResponse()->getHeaders();
}

public function setCookie($name, $value = null)
public function setCookie($name, $value = null): void
{
if (null === $value) {
$this->deleteCookie($name);
Expand All @@ -215,7 +215,7 @@ public function setCookie($name, $value = null)
$jar->set(new Cookie($name, $value));
}

public function getCookie($name)
public function getCookie($name): ?string
{
// Note that the following doesn't work well because
// Symfony\Component\BrowserKit\CookieJar stores cookies by name,
Expand All @@ -237,7 +237,7 @@ public function getCookie($name)
return null;
}

public function getStatusCode()
public function getStatusCode(): int
{
$response = $this->getResponse();

Expand All @@ -249,12 +249,12 @@ public function getStatusCode()
return $response->getStatusCode();
}

public function getContent()
public function getContent(): string
{
return $this->getResponse()->getContent();
}

public function findElementXpaths($xpath)
public function findElementXpaths($xpath): array
{
$nodes = $this->getCrawler()->filterXPath($xpath);

Expand All @@ -266,12 +266,12 @@ public function findElementXpaths($xpath)
return $elements;
}

public function getTagName($xpath)
public function getTagName($xpath): string
{
return $this->getCrawlerNode($this->getFilteredCrawler($xpath))->nodeName;
}

public function getText($xpath)
public function getText($xpath): string
{
$text = $this->getFilteredCrawler($xpath)->text(null, true);
// TODO drop our own normalization once supporting only dom-crawler 4.4+ as it already does it.
Expand All @@ -281,12 +281,12 @@ public function getText($xpath)
return \trim($text);
}

public function getHtml($xpath)
public function getHtml($xpath): string
{
return $this->getFilteredCrawler($xpath)->html();
}

public function getOuterHtml($xpath)
public function getOuterHtml($xpath): string
{
$crawler = $this->getFilteredCrawler($xpath);

Expand All @@ -299,7 +299,7 @@ public function getOuterHtml($xpath)
return $node->ownerDocument->saveHTML($node);
}

public function getAttribute($xpath, $name)
public function getAttribute($xpath, $name): ?string
{
$node = $this->getFilteredCrawler($xpath);

Expand All @@ -310,6 +310,9 @@ public function getAttribute($xpath, $name)
return null;
}

/**
* @return mixed
*/
public function getValue($xpath)
{
if (\in_array($this->getAttribute($xpath, 'type'), ['submit', 'image', 'button'], true)) {
Expand Down Expand Up @@ -339,22 +342,22 @@ public function getValue($xpath)
return $value;
}

public function setValue($xpath, $value)
public function setValue($xpath, $value): void
{
$this->getFormField($xpath)->setValue($value);
}

public function check($xpath)
public function check($xpath): void
{
$this->getCheckboxField($xpath)->tick();
}

public function uncheck($xpath)
public function uncheck($xpath): void
{
$this->getCheckboxField($xpath)->untick();
}

public function selectOption($xpath, $value, $multiple = false)
public function selectOption($xpath, $value, $multiple = false): void
{
$field = $this->getFormField($xpath);

Expand All @@ -371,7 +374,7 @@ public function selectOption($xpath, $value, $multiple = false)
$field->select($value);
}

public function isSelected($xpath)
public function isSelected($xpath): bool
{
$optionValue = $this->getOptionValue($this->getCrawlerNode($this->getFilteredCrawler($xpath)));
$selectField = $this->getFormField('('.$xpath.')/ancestor-or-self::*[local-name()="select"]');
Expand All @@ -380,7 +383,7 @@ public function isSelected($xpath)
return \is_array($selectValue) ? \in_array($optionValue, $selectValue, true) : $optionValue === $selectValue;
}

public function click($xpath)
public function click($xpath): void
{
$crawler = $this->getFilteredCrawler($xpath);
$node = $this->getCrawlerNode($crawler);
Expand All @@ -400,7 +403,7 @@ public function click($xpath)
}
}

public function isChecked($xpath)
public function isChecked($xpath): bool
{
$field = $this->getFormField($xpath);

Expand All @@ -417,7 +420,7 @@ public function isChecked($xpath)
return $radio->getAttribute('value') === $field->getValue();
}

public function attachFile($xpath, $path)
public function attachFile($xpath, $path): void
{
$files = (array) $path;
$field = $this->getFormField($xpath);
Expand Down Expand Up @@ -450,7 +453,7 @@ public function attachFile($xpath, $path)
}
}

public function submitForm($xpath)
public function submitForm($xpath): void
{
$crawler = $this->getFilteredCrawler($xpath);

Expand Down
6 changes: 6 additions & 0 deletions src/Browser/Mink/PantherDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public function getText($xpath): string
return \trim($text);
}

/**
* @return mixed
*/
public function getValue($xpath)
{
try {
Expand Down Expand Up @@ -202,6 +205,9 @@ public function executeScript($script)
return $this->client->executeScript($script);
}

/**
* @return mixed
*/
public function evaluateScript($script)
{
if (0 !== \mb_strpos(\trim($script), 'return ')) {
Expand Down