Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8 Support #828

Merged
merged 2 commits into from
Nov 16, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* text=auto

/scripts export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v1
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: mbstring, intl, zip
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ composer.phar
composer.lock
vendor
.php_cs.cache
.phpunit.result.cache
phpunit.xml
logs/

Expand Down
2 changes: 1 addition & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ return PhpCsFixer\Config::create()
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'php_unit_dedicate_assert' => true,
'php_unit_dedicate_assert' => false,
driesvints marked this conversation as resolved.
Show resolved Hide resolved
'php_unit_expectation' => ['target' => '5.6'],
'php_unit_method_casing' => ['case' => 'camel_case'],
'php_unit_mock' => true,
Expand Down
22 changes: 18 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ language: php
dist: xenial

php:
- '5.6'
- '7.0'
- '7.1'
- '7.2'
- '7.3'
Expand All @@ -21,10 +19,25 @@ services:

matrix:
include:
- name: 'PHP nightly build'
php: 'nightly'
env: DEPENDENCIES="--ignore-platform-req=php"

- name: 'PHP 7.0'
php: '7.0'
env: RUN_PHPUNIT_PATCHES="true"

- name: 'PHP 5.6'
php: '5.6'
env: RUN_PHPUNIT_PATCHES="true"

# Build with lowest possible dependencies on lowest possible PHP
- name: 'Lowest dependencies build'
php: '5.6'
env: DEPENDENCIES="--prefer-lowest"
env:
- DEPENDENCIES="--prefer-lowest"
- RUN_PHPUNIT_PATCHES="true"


# Firefox inside Travis environment
- name: 'Firefox 45 on Travis (OSS protocol); via legacy Selenium server'
Expand Down Expand Up @@ -80,6 +93,7 @@ install:
- travis_retry composer update --no-interaction $DEPENDENCIES

before_script:
- if [ "$RUN_PHPUNIT_PATCHES" = "true" ]; then ./scripts/apply-phpunit-patches.sh; fi
- if [ "$BROWSER_NAME" = "chrome" ]; then
mkdir chromedriver;
CHROME_VERSION=$(google-chrome --product-version);
Expand Down Expand Up @@ -126,4 +140,4 @@ after_script:
- if [ -f ./logs/chromedriver.log ]; then cat ./logs/chromedriver.log; fi

after_success:
- travis_retry php vendor/bin/php-coveralls -v
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then travis_retry php vendor/bin/php-coveralls -v; fi
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"homepage": "https://github.com/php-webdriver/php-webdriver",
"license": "MIT",
"require": {
"php": "^5.6 || ~7.0",
"php": "^5.6 || ~7.0 || ^8.0",
"ext-curl": "*",
"ext-json": "*",
"ext-zip": "*",
Expand All @@ -25,12 +25,10 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0",
"ondram/ci-detector": "^2.1 || ^3.5",
"php-coveralls/php-coveralls": "^2.0",
"php-mock/php-mock-phpunit": "^1.1",
"php-coveralls/php-coveralls": "^2.4",
"php-mock/php-mock-phpunit": "^1.1 || ^2.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpunit/phpunit": "^5.7",
"sebastian/environment": "^1.3.4 || ^2.0 || ^3.0",
"sminnee/phpunit-mock-objects": "^3.4",
"phpunit/phpunit": "^5.7 || ^7 || ^8 || ^9",
"squizlabs/php_codesniffer": "^3.5",
"symfony/var-dumper": "^3.3 || ^4.0 || ^5.0"
},
Expand Down
20 changes: 20 additions & 0 deletions scripts/apply-phpunit-patches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# All commands below must no fail
set -e

# Be in the root dir
cd "$(dirname $0)/../"

find tests/ -type f -print0 | xargs -0 sed -i 's/function setUpBeforeClass(): void/function setUpBeforeClass()/g';
find tests/ -type f -print0 | xargs -0 sed -i 's/function setUp(): void/function setUp()/g';
find tests/ -type f -print0 | xargs -0 sed -i 's/function tearDown(): void/function tearDown()/g';

sed -i 's/endTest(\\PHPUnit\\Framework\\Test \$test, float \$time): void/endTest(\\PHPUnit_Framework_Test \$test, \$time)/g' tests/functional/ReportSauceLabsStatusListener.php;
sed -i 's/: void/ /g' tests/functional/ReportSauceLabsStatusListener.php;
# Drop the listener from the config file
sed -i '/<listeners>/,+2d' phpunit.xml.dist;
sed -i 's/function runBare(): void/function runBare()/g' tests/functional/WebDriverTestCase.php;

# Return back to original dir
cd - > /dev/null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OndraM @williamdes would it be okay with you two if I used this script for algolia/algoliasearch-client-php#644 as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you can copy it :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

2 changes: 1 addition & 1 deletion tests/functional/Chrome/ChromeDriverServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class ChromeDriverServiceTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
if (!getenv('BROWSER_NAME') === 'chrome' || getenv('SAUCELABS') || !getenv('CHROMEDRIVER_PATH')) {
$this->markTestSkipped('ChromeDriverServiceTest is run only when running against local chrome');
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/Chrome/ChromeDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class ChromeDriverTest extends TestCase
/** @var ChromeDriver */
protected $driver;

protected function setUp()
protected function setUp(): void
{
if (!getenv('BROWSER_NAME') === 'chrome' || getenv('SAUCELABS') || !getenv('CHROMEDRIVER_PATH')) {
$this->markTestSkipped('ChromeDriverServiceTest is run only when running against local chrome');
}
}

protected function tearDown()
protected function tearDown(): void
{
if ($this->driver instanceof RemoteWebDriver && $this->driver->getCommandExecutor() !== null) {
$this->driver->quit();
Expand Down
28 changes: 14 additions & 14 deletions tests/functional/RemoteTargetLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testShouldSwitchToWindow()
);

// At first the window should not be switched
$this->assertContains('open_new_window.html', $this->driver->getCurrentURL());
$this->compatAssertStringContainsString('open_new_window.html', $this->driver->getCurrentURL());
$this->assertSame($originalWindowHandle, $this->driver->getWindowHandle());

/**
Expand All @@ -38,7 +38,7 @@ public function testShouldSwitchToWindow()
$this->driver->switchTo()->window($newWindowHandle);

// After switchTo() is called, the active window should be changed
$this->assertContains('index.html', $this->driver->getCurrentURL());
$this->compatAssertStringContainsString('index.html', $this->driver->getCurrentURL());
$this->assertNotSame($originalWindowHandle, $this->driver->getWindowHandle());
}

Expand All @@ -64,25 +64,25 @@ public function testShouldSwitchToFrameByItsId()

$this->driver->get($this->getTestPageUrl('page_with_frame.html'));

$this->assertContains($parentPage, $this->driver->getPageSource());
$this->compatAssertStringContainsString($parentPage, $this->driver->getPageSource());

$this->driver->switchTo()->frame(0);
$this->assertContains($firstChildFrame, $this->driver->getPageSource());
$this->compatAssertStringContainsString($firstChildFrame, $this->driver->getPageSource());

$this->driver->switchTo()->frame(null);
$this->assertContains($parentPage, $this->driver->getPageSource());
$this->compatAssertStringContainsString($parentPage, $this->driver->getPageSource());

$this->driver->switchTo()->frame(1);
$this->assertContains($secondChildFrame, $this->driver->getPageSource());
$this->compatAssertStringContainsString($secondChildFrame, $this->driver->getPageSource());

$this->driver->switchTo()->frame(null);
$this->assertContains($parentPage, $this->driver->getPageSource());
$this->compatAssertStringContainsString($parentPage, $this->driver->getPageSource());

$this->driver->switchTo()->frame(0);
$this->assertContains($firstChildFrame, $this->driver->getPageSource());
$this->compatAssertStringContainsString($firstChildFrame, $this->driver->getPageSource());

$this->driver->switchTo()->defaultContent();
$this->assertContains($parentPage, $this->driver->getPageSource());
$this->compatAssertStringContainsString($parentPage, $this->driver->getPageSource());
}

public function testShouldSwitchToParentFrame()
Expand All @@ -92,13 +92,13 @@ public function testShouldSwitchToParentFrame()

$this->driver->get($this->getTestPageUrl('page_with_frame.html'));

$this->assertContains($parentPage, $this->driver->getPageSource());
$this->compatAssertStringContainsString($parentPage, $this->driver->getPageSource());

$this->driver->switchTo()->frame(0);
$this->assertContains($firstChildFrame, $this->driver->getPageSource());
$this->compatAssertStringContainsString($firstChildFrame, $this->driver->getPageSource());

$this->driver->switchTo()->parent();
$this->assertContains($parentPage, $this->driver->getPageSource());
$this->compatAssertStringContainsString($parentPage, $this->driver->getPageSource());
}

public function testShouldSwitchToFrameByElement()
Expand All @@ -108,7 +108,7 @@ public function testShouldSwitchToFrameByElement()
$element = $this->driver->findElement(WebDriverBy::id('iframe_content'));
$this->driver->switchTo()->frame($element);

$this->assertContains('This is the content of the iFrame', $this->driver->getPageSource());
$this->compatAssertStringContainsString('This is the content of the iFrame', $this->driver->getPageSource());
}

/**
Expand Down Expand Up @@ -139,6 +139,6 @@ public function testShouldAcceptStringAsFrameIdInJsonWireMode()

$this->driver->switchTo()->frame('iframe_content');

$this->assertContains('This is the content of the iFrame', $this->driver->getPageSource());
$this->compatAssertStringContainsString('This is the content of the iFrame', $this->driver->getPageSource());
}
}
6 changes: 3 additions & 3 deletions tests/functional/RemoteWebDriverCreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testShouldStartBrowserAndCreateInstanceOfRemoteWebDriver()
$this->assertInstanceOf(HttpCommandExecutor::class, $this->driver->getCommandExecutor());
$this->assertNotEmpty($this->driver->getCommandExecutor()->getAddressOfRemoteServer());

$this->assertInternalType('string', $this->driver->getSessionID());
$this->assertTrue(is_string($this->driver->getSessionID()));
$this->assertNotEmpty($this->driver->getSessionID());

$returnedCapabilities = $this->driver->getCapabilities();
Expand Down Expand Up @@ -104,7 +104,7 @@ public function testShouldCreateInstanceFromExistingSessionId()
$this->requestTimeout
);
$originalDriver->get($this->getTestPageUrl('index.html'));
$this->assertContains('/index.html', $originalDriver->getCurrentURL());
$this->compatAssertStringContainsString('/index.html', $originalDriver->getCurrentURL());

// Store session ID
$sessionId = $originalDriver->getSessionID();
Expand All @@ -114,7 +114,7 @@ public function testShouldCreateInstanceFromExistingSessionId()
$this->driver = RemoteWebDriver::createBySessionID($sessionId, $this->serverUrl, null, null, $isW3cCompliant);

// Check we reused the previous instance (window) and it has the same URL
$this->assertContains('/index.html', $this->driver->getCurrentURL());
$this->compatAssertStringContainsString('/index.html', $this->driver->getCurrentURL());

// Do some interaction with the new driver
$this->assertNotEmpty($this->driver->findElement(WebDriverBy::id('id_test'))->getText());
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/RemoteWebDriverFindElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testShouldReturnEmptyArrayIfElementsCannotBeFound()

$elements = $this->driver->findElements(WebDriverBy::cssSelector('not_existing'));

$this->assertInternalType('array', $elements);
$this->assertTrue(is_array($elements));
$this->assertCount(0, $elements);
}

Expand All @@ -44,7 +44,7 @@ public function testShouldFindMultipleElements()

$elements = $this->driver->findElements(WebDriverBy::cssSelector('ul > li'));

$this->assertInternalType('array', $elements);
$this->assertTrue(is_array($elements));
$this->assertCount(5, $elements);
$this->assertContainsOnlyInstancesOf(RemoteWebElement::class, $elements);
}
Expand Down
18 changes: 9 additions & 9 deletions tests/functional/RemoteWebDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function testShouldGetPageSource()
$this->driver->get($this->getTestPageUrl('index.html'));

$source = $this->driver->getPageSource();
$this->assertContains('<h1 id="welcome">', $source);
$this->assertContains('Welcome to the php-webdriver testing page.', $source);
$this->compatAssertStringContainsString('<h1 id="welcome">', $source);
$this->compatAssertStringContainsString('Welcome to the php-webdriver testing page.', $source);
}

/**
Expand All @@ -63,7 +63,7 @@ public function testShouldGetSessionId()

$sessionId = $this->driver->getSessionID();

$this->assertInternalType('string', $sessionId);
$this->assertTrue(is_string($sessionId));
$this->assertNotEmpty($sessionId);
}

Expand All @@ -79,7 +79,7 @@ public function testShouldGetAllSessions()

$sessions = RemoteWebDriver::getAllSessions($this->serverUrl, 30000);

$this->assertInternalType('array', $sessions);
$this->assertTrue(is_array($sessions));
$this->assertCount(1, $sessions);

$this->assertArrayHasKey('capabilities', $sessions[0]);
Expand Down Expand Up @@ -124,7 +124,7 @@ public function testShouldGetWindowHandles()
$windowHandle = $this->driver->getWindowHandle();
$windowHandles = $this->driver->getWindowHandles();

$this->assertInternalType('string', $windowHandle);
$this->assertTrue(is_string($windowHandle));
$this->assertNotEmpty($windowHandle);
$this->assertSame([$windowHandle], $windowHandles);

Expand Down Expand Up @@ -266,7 +266,7 @@ public function testShouldTakeScreenshot()
$outputPng = $this->driver->takeScreenshot();

$image = imagecreatefromstring($outputPng);
$this->assertInternalType('resource', $image);
$this->assertTrue(is_resource($image));

$this->assertGreaterThan(0, imagesx($image));
$this->assertGreaterThan(0, imagesy($image));
Expand All @@ -292,7 +292,7 @@ public function testShouldSaveScreenshotToFile()
$this->driver->takeScreenshot($screenshotPath);

$image = imagecreatefrompng($screenshotPath);
$this->assertInternalType('resource', $image);
$this->assertTrue(is_resource($image));

$this->assertGreaterThan(0, imagesx($image));
$this->assertGreaterThan(0, imagesy($image));
Expand Down Expand Up @@ -323,9 +323,9 @@ public function testShouldGetRemoteEndStatus()
{
$status = $this->driver->getStatus();

$this->assertInternalType('boolean', $status->isReady());
$this->assertTrue(is_bool($status->isReady()));
$this->assertNotEmpty($status->getMessage());

$this->assertInternalType('array', $status->getMeta());
$this->assertTrue(is_array($status->getMeta()));
}
}
6 changes: 3 additions & 3 deletions tests/functional/RemoteWebElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function testShouldReturnEmptyArrayIfChildElementsCannotBeFound()

$childElements = $element->findElements(WebDriverBy::cssSelector('not_existing'));

$this->assertInternalType('array', $childElements);
$this->assertTrue(is_array($childElements));
$this->assertCount(0, $childElements);
}

Expand All @@ -330,7 +330,7 @@ public function testShouldFindMultipleChildElements()
$allElements = $this->driver->findElements(WebDriverBy::cssSelector('li'));
$childElements = $element->findElements(WebDriverBy::cssSelector('li'));

$this->assertInternalType('array', $childElements);
$this->assertTrue(is_array($childElements));
$this->assertCount(5, $allElements); // there should be 5 <li> elements on page
$this->assertCount(3, $childElements); // but we should find only subelements of one <ul>
$this->assertContainsOnlyInstancesOf(RemoteWebElement::class, $childElements);
Expand Down Expand Up @@ -373,7 +373,7 @@ public function testShouldTakeAndSaveElementScreenshot()

// Assert string output
$imageFromString = imagecreatefromstring($outputPngString);
$this->assertInternalType('resource', $imageFromString);
$this->assertTrue(is_resource($imageFromString));
$this->assertEquals(5, imagesx($imageFromString));
$this->assertEquals(5, imagesy($imageFromString));

Expand Down