Skip to content

Commit

Permalink
Merge pull request #430 from thewunder/phpunit_7_plus
Browse files Browse the repository at this point in the history
phpunit_7_plus
  • Loading branch information
thewunder committed Jul 2, 2019
2 parents 6cd8b2a + 0303015 commit 3129be3
Show file tree
Hide file tree
Showing 23 changed files with 82 additions and 77 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ PHPUnit_Selenium

This is the list of changes made to PHPUnit_Selenium.

PHPUnit_Selenium 7.0.0
----------------------

* #422: Add support for PHPUnit 7

PHPUnit_Selenium 4.1.0
----------------------

Expand Down
5 changes: 3 additions & 2 deletions PHPUnit/Extensions/Selenium2TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public function prepareSession()
return $this->session;
}

public function run(TestResult $result = NULL)
public function run(TestResult $result = NULL): TestResult
{
$this->testId = get_class($this) . '__' . $this->getName();

Expand Down Expand Up @@ -356,6 +356,7 @@ public function run(TestResult $result = NULL)

/**
* @throws RuntimeException
* @throws Exception
*/
protected function runTest()
{
Expand Down Expand Up @@ -396,7 +397,7 @@ public static function suite($className)
return PHPUnit_Extensions_SeleniumTestSuite::fromTestCaseClass($className);
}

public function onNotSuccessfulTest(Throwable $e)
public function onNotSuccessfulTest(Throwable $e): void
{
$this->getStrategy()->notSuccessfulTest();
parent::onNotSuccessfulTest($e);
Expand Down
9 changes: 5 additions & 4 deletions PHPUnit/Extensions/Selenium2TestCase/ScreenshotListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
* @since File available since Release 1.2.8
*/
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\Test;

/**
Expand All @@ -57,21 +56,23 @@
* @since Class available since Release 1.2.8
*/
class PHPUnit_Extensions_Selenium2TestCase_ScreenshotListener
extends BaseTestListener
implements \PHPUnit\Framework\TestListener
{
use \PHPUnit\Framework\TestListenerDefaultImplementation;

private $directory;

public function __construct($directory)
{
$this->directory = $directory;
}

public function addError(Test $test, Exception $e, $time)
public function addError(Test $test, Throwable $e, float $time): void
{
$this->storeAScreenshot($test);
}

public function addFailure(Test $test, AssertionFailedError $e, $time)
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
$this->storeAScreenshot($test);
}
Expand Down
4 changes: 2 additions & 2 deletions PHPUnit/Extensions/SeleniumBrowserSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class PHPUnit_Extensions_SeleniumBrowserSuite extends TestSuite
*/
protected $testCase = TRUE;

public function addTestMethod(ReflectionClass $class, ReflectionMethod $method)
public function addTestMethod(ReflectionClass $class, ReflectionMethod $method): void
{
return parent::addTestMethod($class, $method);
parent::addTestMethod($class, $method);
}

public static function fromClassAndBrowser($className, array $browser)
Expand Down
2 changes: 1 addition & 1 deletion PHPUnit/Extensions/SeleniumCommon/phpunit_coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
$GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = getcwd();

if (isset($_GET['PHPUNIT_SELENIUM_TEST_ID'])) {
$facade = new File_Iterator_Facade;
$facade = new \SebastianBergmann\FileIterator\Facade();
$sanitizedCookieName = str_replace(array('\\'), '_', $_GET['PHPUNIT_SELENIUM_TEST_ID']);
$files = $facade->getFilesAsArray(
$GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'],
Expand Down
6 changes: 4 additions & 2 deletions PHPUnit/Extensions/SeleniumTestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ class PHPUnit_Extensions_SeleniumTestSuite extends TestSuite

/**
* Making the method public.
* @param ReflectionClass $class
* @param ReflectionMethod $method
*/
public function addTestMethod(ReflectionClass $class, ReflectionMethod $method)
public function addTestMethod(ReflectionClass $class, ReflectionMethod $method): void
{
return parent::addTestMethod($class, $method);
parent::addTestMethod($class, $method);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ Use [Composer](https://getcomposer.org) and run `composer require --dev phpunit/
Requirements
---

This `4.x` mainline supports (only) PHPUnit 6.x. This version is only compatible with PHP 7.
Version `7.x` supports PHPUnit 7.x and is compatible with PHP 7.1+

There are two older, unsupported lines which will probably see no new releases:
Older unsupported lines which will probably see no new releases:

- `4.x` mainline supports (only) PHPUnit 6.x. This version is only compatible with PHP 7
- `3.x`: supports PHPUnit 5.x. Only compatible with PHP 5.6 and PHP 7.
- `2.x`: supports PHPUnit >= 4.8 instead.

Expand Down
2 changes: 1 addition & 1 deletion Tests/CodeCoverageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class CodeCoverageTest extends PHPUnit_Extensions_Selenium2TestCase
{
protected $coverageScriptUrl = 'http://localhost/phpunit_coverage.php';

public function setUp()
public function setUp(): void
{
$this->markTestIncomplete('Would require PHP 5.4 for running .php files on the server');
$this->setBrowser(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM2_BROWSER);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Selenium2TestCase/BaseTestCase.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
class Tests_Selenium2TestCase_BaseTestCase extends PHPUnit_Extensions_Selenium2TestCase
{
public function setUp()
public function setUp(): void
{
$this->setHost(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST);
$this->setPort((int)PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT);
Expand Down
9 changes: 6 additions & 3 deletions Tests/Selenium2TestCase/Coverage/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
class Tests_Selenium2TestCase_Coverage_CookieTest extends Tests_Selenium2TestCase_BaseTestCase
{
// this is a dummy URL (returns down coverage data in HTML), but Firefox still sets domain cookie, which is what's needed
protected $coverageScriptUrl = 'http://127.0.0.1:8080/coverage/dummy.html';
protected $coverageScriptUrl = PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL .'/coverage/dummy.html';

public function run(TestResult $result = NULL)
public function run(TestResult $result = NULL): TestResult
{
// make sure code coverage collection is enabled
if ($result === NULL) {
Expand All @@ -19,6 +19,7 @@ public function run(TestResult $result = NULL)
parent::run($result);

$result->getCodeCoverage()->clear();
return $result;
}

protected function getTestIdCookie()
Expand All @@ -29,7 +30,9 @@ protected function getTestIdCookie()
public function testTestIdCookieIsSet()
{
$this->url('/');
return $this->getTestIdCookie();
$testIdCookie = $this->getTestIdCookie();
$this->assertNotEmpty($testIdCookie);
return $testIdCookie;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Tests/Selenium2TestCase/Coverage/SingleFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Tests_Selenium2TestCase_Coverage_SingleFileTest extends TestCase
{
private $dummyTestId = 'ns_dummyTestId';

public function setUp()
public function setUp(): void
{
if (!extension_loaded('xdebug')) {
$this->markTestSkipped('Needs xdebug to run');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Selenium2TestCase/CustomDesiredCapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
class Extensions_Selenium2TestCase_CustomDesiredCapabilitiesTest extends Tests_Selenium2TestCase_BaseTestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->setDesiredCapabilities(array(
Expand Down
16 changes: 4 additions & 12 deletions Tests/Selenium2TestCase/FailuresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,21 @@
*/
class Extensions_Selenium2TestCaseFailuresTest extends Tests_Selenium2TestCase_BaseTestCase
{
/**
* @expectedException BadMethodCallException
*/
public function testInexistentCommandCausesTheTestToFail()
{
$this->expectException(BadMethodCallException::class);
$this->inexistentSessionCommand();
}

/**
* @expectedException DomainException
*/
public function testExceptionsAreReThrownOnNotSuccessfulTests()
{
$this->expectException(DomainException::class);
$this->onNotSuccessfulTest(new DomainException);
}

/**
* @expectedException RuntimeException
*/
public function testInexistentElementCausesTheTestToFail()
{
$this->expectException(RuntimeException::class);
$this->url('html/test_open.html');
$this->byId('notExistent');
}
Expand All @@ -90,11 +84,9 @@ public function testStaleElementsCannotBeAccessed()
}
}

/**
* @expectedException InvalidArgumentException
*/
public function testSelectObjectsCanOnlyBeCreatedOverSelectTags()
{
$this->expectException(InvalidArgumentException::class);
$this->url('html/test_element_selection.html');
$div = $this->byId('theDivId');
$select = $this->select($div);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Selenium2TestCase/MobileFeaturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Tests_Selenium2TestCase_MobileFeaturesTest extends PHPUnit_Extensions_Sele
)
);

public function setUp()
public function setUp(): void
{
if (!defined('SAUCE_ACCESS_KEY') || !defined('SAUCE_USERNAME')) {
$this->markTestSkipped("SAUCE_USERNAME and SAUCE_ACCESS_KEY must be set to run tests on Sauce");
Expand Down
6 changes: 3 additions & 3 deletions Tests/Selenium2TestCase/MultipleBrowsersMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ public static function browsers()
);
}

public function setUp()
public function setUp(): void
{
if (!defined('PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL')) {
$this->markTestSkipped("You must serve the selenium-1-tests folder from an HTTP server and configure the PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL constant accordingly.");
}
$this->setBrowserUrl(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL);
}

public function tearDown()
public function tearDown(): void
{
self::$testsRun++;
}

public static function tearDownAfterClass()
public static function tearDownAfterClass(): void
{
$expected = count(self::browsers());
$actual = self::$testsRun;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Selenium2TestCase/MultipleBrowsersPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Extensions_Selenium2TestCaseMultipleBrowsersPropertyTest extends PHPUnit_E
private $_browserWeSetUp = '';


public function setUp()
public function setUp(): void
{
if (!defined('PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL')) {
$this->markTestSkipped("You must serve the selenium-1-tests folder from an HTTP server and configure the PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL constant accordingly.");
Expand Down
1 change: 1 addition & 0 deletions Tests/Selenium2TestCase/RegressionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function testDependency()
{
$this->url("html/test_open.html");
$title = $this->title();
$this->assertEquals('Test open', $title);
return $title;
}

Expand Down
12 changes: 8 additions & 4 deletions Tests/Selenium2TestCase/ScreenshotListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

class Tests_Selenium2TestCase_ScreenshotListenerTest extends Tests_Selenium2TestCase_BaseTestCase
{
public function setUp()
/** @var PHPUnit_Extensions_Selenium2TestCase_ScreenshotListener */
private $listener;

public function setUp(): void
{
parent::setUp();
$this->directory = sys_get_temp_dir();
Expand All @@ -20,7 +23,7 @@ public function testStoresAScreenshotInCaseOfError()
{
$this->url('html/test_open.html');

$this->listener->addError($this, new Exception(), NULL);
$this->listener->addError($this, new Exception(), microtime(true));

$this->assertThereIsAScreenshotNamed('Tests_Selenium2TestCase_ScreenshotListenerTest__testStoresAScreenshotInCaseOfError__*.png');
}
Expand All @@ -30,7 +33,7 @@ public function testStoresAScreenshotInCaseOfFailure()
$this->url('html/test_open.html');

$exception = new AssertionFailedError();
$this->listener->addFailure($this, $exception, NULL);
$this->listener->addFailure($this, $exception, microtime(true));

$this->assertThereIsAScreenshotNamed('Tests_Selenium2TestCase_ScreenshotListenerTest__testStoresAScreenshotInCaseOfFailure*.png');
}
Expand All @@ -39,7 +42,8 @@ public function testScreenshotGenerationMayFailWithoutJeopardizingTheRestOfTheSu
{
$test = new Tests_Selenium2TestCase_NotCapableOfTakingScreenshotsTest();

$this->listener->addError($test, new RuntimeException(), NULL);
$this->listener->addError($test, new RuntimeException(), microtime(true));
$this->addToAssertionCount(1);
}

private function assertThereIsAScreenshotNamed($filename)
Expand Down
2 changes: 1 addition & 1 deletion Tests/Selenium2TestCase/SessionInSetupTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
class Tests_Selenium2TestCase_SessionInSetupTest extends PHPUnit_Extensions_Selenium2TestCase
{
public function setUp()
public function setUp(): void
{
$this->setHost(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST);
$this->setPort((int)PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT);
Expand Down
6 changes: 2 additions & 4 deletions Tests/Selenium2TestCase/TimeoutTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
class Tests_Selenium2TestCase_TimeoutTest extends Tests_Selenium2TestCase_BaseTestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->setSeleniumServerRequestsTimeout(60);
Expand All @@ -13,11 +13,9 @@ public function testOpen()
$this->assertStringEndsWith('html/test_open.html', $this->url());
}

/**
* @expectedException PHPUnit_Extensions_Selenium2TestCase_Exception
*/
public function testAnImplicitWaitValueToRespectOnTheServerMustBeSmallerThanTheSeleniumServerCallsTimeout()
{
$this->expectException(PHPUnit_Extensions_Selenium2TestCase_Exception::class);
$this->timeouts()->implicitWait(120000);
}

Expand Down
12 changes: 5 additions & 7 deletions Tests/Selenium2TestCase/WaitUntilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public function testWaitSuccessfully()
return TRUE;
}
}, 8000);

$this->addToAssertionCount(1);
}

/**
* @expectedException PHPUnit_Extensions_Selenium2TestCase_WebDriverException
*/
public function testWaitUnsuccessfully()
{
$this->expectException(PHPUnit_Extensions_Selenium2TestCase_WebDriverException::class);
$this->url('html/test_wait.html');

$this->waitUntil(function($testCase) {
Expand All @@ -81,12 +81,10 @@ public function testWaitUnsuccessfully()
}, 42);
}

/**
* @expectedException PHPUnit_Extensions_Selenium2TestCase_Exception
* @expectedExceptionMessage The valid callback is expected
*/
public function testInvalidCallback()
{
$this->expectException(PHPUnit_Extensions_Selenium2TestCase_Exception::class);
$this->expectExceptionMessage('The valid callback is expected');
$this->waitUntil('not a callback');
}

Expand Down

0 comments on commit 3129be3

Please sign in to comment.