Skip to content

Commit

Permalink
Declare nullable parameter types explicitly for PHP 8.4 compatibility (
Browse files Browse the repository at this point in the history
  • Loading branch information
W0rma authored Jul 29, 2024
1 parent ba43d1e commit 9f9537a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Codeception/Constraint/WebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function matches($nodes): bool
* @param string|array|WebDriverBy $selector
* @param ComparisonFailure|null $comparisonFailure
*/
protected function fail($nodes, $selector, ComparisonFailure $comparisonFailure = null): never
protected function fail($nodes, $selector, ?ComparisonFailure $comparisonFailure = null): never
{
if (count($nodes) === 0) {
throw new ElementNotFound($selector, 'Element located either by name, CSS or XPath');
Expand Down Expand Up @@ -89,7 +89,7 @@ protected function failureDescription($nodes): string
* @param string|null $contains
* @return string
*/
protected function nodesList(array $nodes, string $contains = null): string
protected function nodesList(array $nodes, ?string $contains = null): string
{
$output = "";
foreach ($nodes as $node) {
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Constraint/WebDriverNot.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function matches($nodes): bool
* @param string|array|WebDriverBy $selector
* @param ComparisonFailure|null $comparisonFailure
*/
protected function fail($nodes, $selector, ComparisonFailure $comparisonFailure = null): never
protected function fail($nodes, $selector, ?ComparisonFailure $comparisonFailure = null): never
{
if (!is_string($selector) || strpos($selector, "'") === false) {
$selector = Locator::humanReadableString($selector);
Expand Down
26 changes: 13 additions & 13 deletions src/Codeception/Module/WebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public function _failed(TestInterface $test, $fail)
/**
* Print out latest Selenium Logs in debug mode
*/
public function debugWebDriverLogs(TestInterface $test = null): void
public function debugWebDriverLogs(?TestInterface $test = null): void
{
if ($this->webDriver === null) {
$this->debug('WebDriver::debugWebDriverLogs method has been called when webDriver is not set');
Expand Down Expand Up @@ -903,7 +903,7 @@ public function _savePageSource(string $filename): void
* // saved to: tests/_output/debug/2017-05-26_14-24-11_4b3403665fea6.png
* ```
*/
public function makeScreenshot(string $name = null): void
public function makeScreenshot(?string $name = null): void
{
if (empty($name)) {
$name = uniqid(date("Y-m-d_H-i-s_"));
Expand Down Expand Up @@ -933,7 +933,7 @@ public function makeScreenshot(string $name = null): void
*
* @param WebDriverBy|array $selector
*/
public function makeElementScreenshot($selector, string $name = null): void
public function makeElementScreenshot($selector, ?string $name = null): void
{
if (empty($name)) {
$name = uniqid(date("Y-m-d_H-i-s_"));
Expand All @@ -949,7 +949,7 @@ public function makeElementScreenshot($selector, string $name = null): void
$this->debugSection('Screenshot Saved', "file://{$screenName}");
}

public function makeHtmlSnapshot(string $name = null): void
public function makeHtmlSnapshot(?string $name = null): void
{
if (empty($name)) {
$name = uniqid(date("Y-m-d_H-i-s_"));
Expand Down Expand Up @@ -1327,7 +1327,7 @@ protected function findField($selector): WebDriverElement
return reset($arr);
}

public function seeLink(string $text, string $url = null): void
public function seeLink(string $text, ?string $url = null): void
{
$this->enableImplicitWait();
$nodes = $this->getBaseElement()->findElements(WebDriverBy::partialLinkText($text));
Expand Down Expand Up @@ -2768,7 +2768,7 @@ public function executeInSelenium(Closure $function)
* });
* ```
*/
public function switchToWindow(string $name = null): void
public function switchToWindow(?string $name = null): void
{
$this->webDriver->switchTo()->window($name);
}
Expand All @@ -2795,7 +2795,7 @@ public function switchToWindow(string $name = null): void
*
* @param string|null $locator (name, CSS or XPath)
*/
public function switchToIFrame(string $locator = null): void
public function switchToIFrame(?string $locator = null): void
{
$this->findAndSwitchToFrame($locator, 'iframe');
}
Expand All @@ -2822,12 +2822,12 @@ public function switchToIFrame(string $locator = null): void
*
* @param string|null $locator (name, CSS or XPath)
*/
public function switchToFrame(string $locator = null): void
public function switchToFrame(?string $locator = null): void
{
$this->findAndSwitchToFrame($locator);
}

private function findAndSwitchToFrame(string $locator = null, string $tag = 'frame'): void
private function findAndSwitchToFrame(?string $locator = null, string $tag = 'frame'): void
{
if ($locator === null) {
$this->webDriver->switchTo()->defaultContent();
Expand Down Expand Up @@ -2962,7 +2962,7 @@ public function dragAndDrop($source, $target): void
* @param null|string|array|WebDriverBy $cssOrXPath css or xpath of the web element
* @throws ElementNotFound
*/
public function moveMouseOver($cssOrXPath = null, int $offsetX = null, int $offsetY = null): void
public function moveMouseOver($cssOrXPath = null, ?int $offsetX = null, ?int $offsetY = null): void
{
$where = null;
if (null !== $cssOrXPath) {
Expand Down Expand Up @@ -2991,7 +2991,7 @@ public function moveMouseOver($cssOrXPath = null, int $offsetX = null, int $offs
*
* @throws ElementNotFound
*/
public function clickWithLeftButton($cssOrXPath = null, int $offsetX = null, int $offsetY = null): void
public function clickWithLeftButton($cssOrXPath = null, ?int $offsetX = null, ?int $offsetY = null): void
{
$this->moveMouseOver($cssOrXPath, $offsetX, $offsetY);
$this->webDriver->getMouse()->click();
Expand All @@ -3014,7 +3014,7 @@ public function clickWithLeftButton($cssOrXPath = null, int $offsetX = null, int
* @param null|string|array|WebDriverBy $cssOrXPath css or xpath of the web element (body by default).
* @throws ElementNotFound
*/
public function clickWithRightButton($cssOrXPath = null, int $offsetX = null, int $offsetY = null): void
public function clickWithRightButton($cssOrXPath = null, ?int $offsetX = null, ?int $offsetY = null): void
{
$this->moveMouseOver($cssOrXPath, $offsetX, $offsetY);
$this->webDriver->getMouse()->contextClick();
Expand Down Expand Up @@ -3487,7 +3487,7 @@ protected function isPhantom(): bool
*
* @param string|array|WebDriverBy $selector
*/
public function scrollTo($selector, int $offsetX = null, int $offsetY = null): void
public function scrollTo($selector, ?int $offsetX = null, ?int $offsetY = null): void
{
$el = $this->matchFirstOrFail($this->getBaseElement(), $selector);
$x = $el->getLocation()->getX() + $offsetX;
Expand Down

0 comments on commit 9f9537a

Please sign in to comment.