Skip to content

Commit

Permalink
Fix tests + Add PSR-4 to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pajon committed Apr 6, 2020
1 parent 97676a2 commit fdb7cb5
Show file tree
Hide file tree
Showing 23 changed files with 125 additions and 36 deletions.
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
5 changes: 4 additions & 1 deletion Tests/Selenium2TestCase/URLTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace Tests\Selenium2TestCase;

/**
* PHPUnit
*
Expand Down Expand Up @@ -51,7 +54,7 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
*/
class Extensions_Selenium2TestCase_URLTest extends TestCase
class URLTest extends TestCase
{
public function testDescendsAnURLWithAnAdditionalFolder()
{
Expand Down
5 changes: 4 additions & 1 deletion Tests/Selenium2TestCase/WaitUntilTest.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 Tests_Selenium2TestCase_WaitUntilTest extends Tests_Selenium2TestCase_BaseTestCase
class WaitUntilTest extends BaseTestCase
{
public function testWaitSuccessfully()
{
Expand Down
Loading

0 comments on commit fdb7cb5

Please sign in to comment.