Skip to content

Commit

Permalink
Merge pull request #448 from pajon/phpunit9
Browse files Browse the repository at this point in the history
PHPUnit 9
  • Loading branch information
thewunder authored Apr 7, 2020
2 parents 7c8bef6 + fdb7cb5 commit d46cc90
Show file tree
Hide file tree
Showing 27 changed files with 132 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .ci/vagrant_pre_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ apt-get install software-properties-common -y
apt-get install python-software-properties -y

# installing xvfb, java and php
apt-get install xvfb php7.2-cli php7.2-curl php7.2-xml php7.2-mbstring php-xdebug ncurses-term unzip xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic vim -y --no-install-recommends
apt-get install xvfb php7.3-cli php7.3-curl php7.3-xml php7.3-mbstring php-xdebug ncurses-term unzip xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic vim -y --no-install-recommends

1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php
dist: xenial
php:
- 7.2
- 7.3
- 7.4

Expand Down
6 changes: 4 additions & 2 deletions PHPUnit/Extensions/Selenium2TestCase/ScreenshotListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ private function storeAScreenshot(Test $test)
{
if ($test instanceof Selenium2TestCase)
{
$className = str_replace('\\', '_', get_class($test));

try {
$file = $this->directory . '/' . get_class($test) . '__' . $test->getName() . '__' . date('Y-m-d\TH-i-s') . '.png';
$file = $this->directory . '/' . $className . '__' . $test->getName() . '__' . date('Y-m-d\TH-i-s') . '.png';
file_put_contents($file, $test->currentScreenshot());
} catch (\Exception $e) {
$file = $this->directory . '/' . get_class($test) . '__' . $test->getName() . '__' . date('Y-m-d\TH-i-s') . '.txt';
$file = $this->directory . '/' . $className . '__' . $test->getName() . '__' . date('Y-m-d\TH-i-s') . '.txt';
file_put_contents($file, "Screenshot generation doesn't work." . "\n"
. $e->getMessage() . "\n"
. $e->getTraceAsString());
Expand Down
2 changes: 2 additions & 0 deletions Tests/CodeCoverageTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Tests;

use PHPUnit\Extensions\Selenium2TestCase;

class CodeCoverageTest extends Selenium2TestCase
Expand Down
4 changes: 3 additions & 1 deletion Tests/Selenium2TestCase/BaseTestCase.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace Tests\Selenium2TestCase;

use PHPUnit\Extensions\Selenium2TestCase;

class Tests_Selenium2TestCase_BaseTestCase extends Selenium2TestCase
class BaseTestCase extends Selenium2TestCase
{
public function setUp(): void
{
Expand Down
6 changes: 5 additions & 1 deletion Tests/Selenium2TestCase/Coverage/CookieTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

namespace Tests\Selenium2TestCase\Coverage;

use PHPUnit\Framework\TestResult;
use Tests\Selenium2TestCase\BaseTestCase;

class Tests_Selenium2TestCase_Coverage_CookieTest extends Tests_Selenium2TestCase_BaseTestCase
class CookieTest extends 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 = PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL .'/coverage/dummy.html';
Expand Down
4 changes: 3 additions & 1 deletion Tests/Selenium2TestCase/Coverage/RemoteCoverageTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace Tests\Selenium2TestCase\Coverage;

use PHPUnit\Extensions\SeleniumCommon\RemoteCoverage;
use PHPUnit\Framework\TestCase;

class Tests_Selenium2TestCase_Coverage_RemoteCoverageTest extends TestCase
class RemoteCoverageTest extends TestCase
{
public function testObtainsCodeCoverageInformationFromAPossiblyRemoteHttpServer()
{
Expand Down
5 changes: 4 additions & 1 deletion Tests/Selenium2TestCase/Coverage/SingleFileTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

namespace Tests\Selenium2TestCase\Coverage;

use PHPUnit\Framework\TestCase;

class Tests_Selenium2TestCase_Coverage_SingleFileTest extends TestCase
class SingleFileTest extends TestCase
{
private $dummyTestId = 'ns_dummyTestId';

Expand Down
5 changes: 4 additions & 1 deletion Tests/Selenium2TestCase/CustomDesiredCapabilitiesTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace Tests\Selenium2TestCase;

/**
* Tests for PHPUnit_Extensions_SeleniumTestCase.
*
Expand All @@ -8,7 +11,7 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/
class Extensions_Selenium2TestCase_CustomDesiredCapabilitiesTest extends Tests_Selenium2TestCase_BaseTestCase
class CustomDesiredCapabilitiesTest extends BaseTestCase
{
public function setUp(): void
{
Expand Down
12 changes: 10 additions & 2 deletions Tests/Selenium2TestCase/FailuresTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<?php

namespace Tests\Selenium2TestCase;

use BadMethodCallException;
use DomainException;
use InvalidArgumentException;
use RuntimeException;

/**
* PHPUnit
*
Expand Down Expand Up @@ -50,7 +58,7 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/
class Extensions_Selenium2TestCaseFailuresTest extends Tests_Selenium2TestCase_BaseTestCase
class Selenium2TestCaseFailuresTest extends BaseTestCase
{
public function testInexistentCommandCausesTheTestToFail()
{
Expand Down Expand Up @@ -80,7 +88,7 @@ public function testStaleElementsCannotBeAccessed()
$div->text();
$this->fail('The element shouldn\'t be accessible.');
} catch (RuntimeException $e) {
$this->assertContains('http://seleniumhq.org/exceptions/stale_element_reference.html', $e->getMessage());
$this->assertStringContainsString('http://seleniumhq.org/exceptions/stale_element_reference.html', $e->getMessage());
}
}

Expand Down
5 changes: 4 additions & 1 deletion Tests/Selenium2TestCase/LogTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace Tests\Selenium2TestCase;

/**
* PHPUnit
*
Expand Down Expand Up @@ -50,7 +53,7 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/
class Tests_Selenium2TestCase_LogTest extends Tests_Selenium2TestCase_BaseTestCase
class LogTest extends BaseTestCase
{
private static $expectedLogTypes = array(
'default' => array(
Expand Down
5 changes: 4 additions & 1 deletion Tests/Selenium2TestCase/MobileFeaturesTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace Tests\Selenium2TestCase;

/**
* PHPUnit
*
Expand Down Expand Up @@ -62,7 +65,7 @@
define('SAUCE_HOST', '');
}

class Tests_Selenium2TestCase_MobileFeaturesTest extends Selenium2TestCase
class MobileFeaturesTest extends Selenium2TestCase
{
public static $browsers = array(
array(
Expand Down
6 changes: 5 additions & 1 deletion Tests/Selenium2TestCase/MultipleBrowsersMethodTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace Tests\Selenium2TestCase;

/**
* PHPUnit
*
Expand Down Expand Up @@ -41,6 +44,7 @@
* @link http://www.phpunit.de/
*/

use Exception;
use PHPUnit\Extensions\Selenium2TestCase;

/**
Expand All @@ -50,7 +54,7 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/
class Extensions_Selenium2TestCaseMultipleBrowsersMethodTest extends Selenium2TestCase
class MultipleBrowsersMethodTest extends Selenium2TestCase
{
private $browserWeSetUp = '';
private static $testsRun = 0;
Expand Down
5 changes: 4 additions & 1 deletion Tests/Selenium2TestCase/MultipleBrowsersPropertyTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace Tests\Selenium2TestCase;

/**
* PHPUnit
*
Expand Down Expand Up @@ -52,7 +55,7 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/
class Extensions_Selenium2TestCaseMultipleBrowsersPropertyTest extends Selenium2TestCase
class MultipleBrowsersPropertyTest extends Selenium2TestCase
{
public static $browsers = array(
array(
Expand Down
15 changes: 9 additions & 6 deletions Tests/Selenium2TestCase/PageObjectTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?php
class Tests_PageObjectTest extends Tests_Selenium2TestCase_BaseTestCase

namespace Tests\Selenium2TestCase;

class PageObjectTest extends BaseTestCase
{
public function testAPageInteractsWithElementsExposingAnHigherLevelApi()
{
$this->url('html/test_type_page1.html');
$page = new Tests_AuthenticationPage($this);
$page = new AuthenticationPage($this);
$welcomePage = $page->username('TestUser')
->password('TestPassword')
->submit();
$welcomePage->assertWelcomeIs('Welcome, TestUser!');
}
}

class Tests_AuthenticationPage
class AuthenticationPage
{
public function __construct($test)
{
Expand All @@ -36,11 +39,11 @@ public function password($value)
public function submit()
{
$this->test->clickOnElement('submitButton');
return new Tests_WelcomePage($this->test);
return new WelcomePage($this->test);
}
}

class Tests_WelcomePage
class WelcomePage
{
public function __construct($test)
{
Expand All @@ -50,6 +53,6 @@ public function __construct($test)

public function assertWelcomeIs($text)
{
$this->test->assertRegExp("/$text/", $this->header->text());
$this->test->assertMatchesRegularExpression("/$text/", $this->header->text());
}
}
5 changes: 4 additions & 1 deletion Tests/Selenium2TestCase/RegressionsTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace Tests\Selenium2TestCase;

/**
* PHPUnit
*
Expand Down Expand Up @@ -50,7 +53,7 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/
class Extensions_Selenium2TestCaseRegressionsTest extends Tests_Selenium2TestCase_BaseTestCase
class RegressionsTest extends BaseTestCase
{
/**
* @return string
Expand Down
6 changes: 5 additions & 1 deletion Tests/Selenium2TestCase/ScreenshotListenerTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php

namespace Tests\Selenium2TestCase;

use Exception;
use PHPUnit\Extensions\Selenium2TestCase;
use PHPUnit\Extensions\Selenium2TestCase\ScreenshotListener;
use PHPUnit\Framework\AssertionFailedError;
use RuntimeException;

class Tests_Selenium2TestCase_ScreenshotListenerTest extends Tests_Selenium2TestCase_BaseTestCase
class ScreenshotListenerTest extends BaseTestCase
{
/** @var ScreenshotListener */
private $listener;
Expand Down
6 changes: 5 additions & 1 deletion Tests/Selenium2TestCase/SessionCommand/FileTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

class Tests_Selenium2TestCase_SessionCommand_FileTest extends Tests_Selenium2TestCase_BaseTestCase
namespace Tests\Selenium2TestCase\SessionCommand;

use Tests\Selenium2TestCase\BaseTestCase;

class FileTest extends BaseTestCase
{
public function testUploadFile()
{
Expand Down
4 changes: 3 additions & 1 deletion Tests/Selenium2TestCase/SessionInSetupTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace Tests\Selenium2TestCase;

use PHPUnit\Extensions\Selenium2TestCase;

class Tests_Selenium2TestCase_SessionInSetupTest extends Selenium2TestCase
class SessionInSetupTest extends Selenium2TestCase
{
public function setUp(): void
{
Expand Down
7 changes: 5 additions & 2 deletions Tests/Selenium2TestCase/SetUpPageTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace Tests\Selenium2TestCase;

/**
* PHPUnit
*
Expand Down Expand Up @@ -48,14 +51,14 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/
class Tests_Selenium2TestCase_SetUpPageTest extends Tests_Selenium2TestCase_BaseTestCase {
class SetUpPageTest extends BaseTestCase {
public function setUpPage()
{
$this->url('html/test_type_page1.html');
}

public function testSetUpPageIsExecuted()
{
$this->assertRegExp('/html\/test_type_page1\.html$/', $this->url());
$this->assertMatchesRegularExpression('/html\/test_type_page1\.html$/', $this->url());
}
}
11 changes: 8 additions & 3 deletions Tests/Selenium2TestCase/SuiteBuildingTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace Tests\Selenium2TestCase;

/**
* PHPUnit
*
Expand Down Expand Up @@ -43,6 +46,8 @@

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use Tests\Selenium2TestCase\fixtures\MultipleBrowsersTestCaseSample;
use Tests\Selenium2TestCase\fixtures\TestCaseSample;

require_once 'PHPUnit/Extensions/Selenium2TestCase.php';

Expand All @@ -55,20 +60,20 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/
class Extensions_Selenium2SuiteBuildingTest extends TestCase
class SuiteBuildingTest extends TestCase
{
public function testSampleTestCaseBuildsAFullSuiteContainingAllItsTests()
{
require_once __DIR__ . '/fixtures/SuiteBuildingSuites.php';
$suite = Extensions_Selenium2TestCaseSample::suite('Extensions_Selenium2TestCaseSample');
$suite = TestCaseSample::suite(TestCaseSample::class);
$this->assertInstanceOf(TestSuite::class, $suite);
$this->assertEquals(2, count($suite->tests()));
}

public function testAMultipleBrowsersTestCaseBuildsACopyOfEachTestForEachBrowser()
{
require_once __DIR__ . '/fixtures/SuiteBuildingSuites.php';
$suite = Extensions_Selenium2MultipleBrowsersTestCaseSample::suite('Extensions_Selenium2MultipleBrowsersTestCaseSample');
$suite = MultipleBrowsersTestCaseSample::suite(MultipleBrowsersTestCaseSample::class);
$this->assertInstanceOf(TestSuite::class, $suite);
$this->assertEquals(2, count($suite->tests()));
}
Expand Down
5 changes: 4 additions & 1 deletion Tests/Selenium2TestCase/TimeoutTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
class Tests_Selenium2TestCase_TimeoutTest extends Tests_Selenium2TestCase_BaseTestCase

namespace Tests\Selenium2TestCase;

class TimeoutTest extends BaseTestCase
{
public function setUp(): void
{
Expand Down
Loading

0 comments on commit d46cc90

Please sign in to comment.