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

Use the "::class" in test suite for class referencing #124

Merged
merged 1 commit into from
Mar 13, 2024
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
8 changes: 3 additions & 5 deletions tests/aik099/PHPUnit/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use aik099\PHPUnit\Application;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
use aik099\PHPUnit\TestSuite\TestSuiteFactory;

class ApplicationTest extends AbstractTestCase
{
Expand Down Expand Up @@ -51,10 +52,7 @@ public function testInstanceIsShared()
*/
public function testGetTestSuiteFactory()
{
$this->assertInstanceOf(
'aik099\\PHPUnit\\TestSuite\\TestSuiteFactory',
$this->_application->getTestSuiteFactory()
);
$this->assertInstanceOf(TestSuiteFactory::class, $this->_application->getTestSuiteFactory());
}

/**
Expand All @@ -64,7 +62,7 @@ public function testGetTestSuiteFactory()
*/
public function testGetObject()
{
$this->assertInstanceOf('aik099\\PHPUnit\\Application', $this->_application->getObject('application'));
$this->assertInstanceOf(Application::class, $this->_application->getObject('application'));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
use ConsoleHelpers\PHPUnitCompat\Framework\TestResult;
use Mockery as m;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Driver\DriverInterface;
use Behat\Mink\Session;

abstract class ApiBrowserConfigurationTestCase extends BrowserConfigurationTest
{
Expand Down Expand Up @@ -56,10 +59,10 @@ abstract class ApiBrowserConfigurationTestCase extends BrowserConfigurationTest
protected function setUpTest()
{
if ( $this->needsAPIClient() ) {
$this->apiClient = m::mock('\\aik099\\PHPUnit\\APIClient\\IAPIClient');
$this->apiClient = m::mock(IAPIClient::class);
}

$this->apiClientFactory = m::mock('\\aik099\\PHPUnit\\APIClient\\APIClientFactory');
$this->apiClientFactory = m::mock(APIClientFactory::class);

parent::setUpTest();

Expand Down Expand Up @@ -309,19 +312,19 @@ public function testOnTestEnded($driver_type)
$test_case = $this->createTestCase('TEST_NAME');

if ( $driver_type == 'selenium' ) {
$driver = m::mock('\\Behat\\Mink\\Driver\\Selenium2Driver');
$driver = m::mock(Selenium2Driver::class);
$driver->shouldReceive('getWebDriverSessionId')->once()->andReturn('SID');

$this->apiClient->shouldReceive('updateStatus')->with('SID', true, 'test status message')->once();
$test_case->shouldReceive('hasFailed')->once()->andReturn(false); // For shared strategy.
$test_case->shouldReceive('getStatusMessage')->once()->andReturn('test status message'); // For shared strategy.
}
else {
$driver = m::mock('\\Behat\\Mink\\Driver\\DriverInterface');
$driver = m::mock(DriverInterface::class);
$this->expectException('RuntimeException');
}

$session = m::mock('Behat\\Mink\\Session');
$session = m::mock(Session::class);
$session->shouldReceive('getDriver')->once()->andReturn($driver);
$session->shouldReceive('isStarted')->once()->andReturn(true);

Expand Down Expand Up @@ -353,7 +356,7 @@ public function testTestEndedWithoutSession($stopped_or_missing)
$test_case = $this->createTestCase('TEST_NAME');

if ( $stopped_or_missing ) {
$session = m::mock('Behat\\Mink\\Session');
$session = m::mock(Session::class);
$session->shouldReceive('isStarted')->once()->andReturn(false);
$test_case->shouldReceive('getSession')->with(false)->once()->andReturn($session);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Mockery as m;
use tests\aik099\PHPUnit\AbstractTestCase;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
use aik099\PHPUnit\BrowserTestCase;

class BrowserConfigurationFactoryTest extends AbstractTestCase
{
Expand Down Expand Up @@ -51,7 +52,7 @@ public function testCreateBrowserConfiguration(array $browser_config, $type)
{
$browser_aliases = array('alias-one' => array());

$test_case = m::mock('aik099\\PHPUnit\\BrowserTestCase');
$test_case = m::mock(BrowserTestCase::class);
$test_case->shouldReceive('getBrowserAliases')->once()->andReturn($browser_aliases);

$cleaned_browser_config = $browser_config;
Expand All @@ -72,7 +73,7 @@ public function testCreateBrowserConfiguration(array $browser_config, $type)

$actual_browser = $this->_factory->createBrowserConfiguration($browser_config, $test_case);
$this->assertEquals($type, $actual_browser->getType());
$this->assertInstanceOf('aik099\\PHPUnit\\BrowserConfiguration\\BrowserConfiguration', $actual_browser);
$this->assertInstanceOf(BrowserConfiguration::class, $actual_browser);
}

/**
Expand All @@ -99,7 +100,7 @@ public function testCreateBrowserConfigurationError()

$browser_aliases = array('alias-one' => array());

$test_case = m::mock('aik099\\PHPUnit\\BrowserTestCase');
$test_case = m::mock(BrowserTestCase::class);
$test_case->shouldReceive('getBrowserAliases')->once()->andReturn($browser_aliases);

$this->_factory->createBrowserConfiguration(array('type' => 'test'), $test_case);
Expand Down Expand Up @@ -128,7 +129,7 @@ public function testRegisterFailure()
*/
private function _createBrowserConfiguration($type)
{
$browser_configuration = m::mock('aik099\\PHPUnit\\BrowserConfiguration\\BrowserConfiguration');
$browser_configuration = m::mock(BrowserConfiguration::class);
$browser_configuration->shouldReceive('getType')->andReturn($type);

return $browser_configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
use tests\aik099\PHPUnit\Fixture\WithBrowserConfig;
use tests\aik099\PHPUnit\Fixture\WithoutBrowserConfig;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
use aik099\PHPUnit\MinkDriver\IMinkDriverFactory;

class BrowserConfigurationTest extends AbstractTestCase
{

use ExpectException;

const TEST_CASE_CLASS = '\\aik099\\PHPUnit\\BrowserTestCase';
const TEST_CASE_CLASS = BrowserTestCase::class;

const HOST = 'example_host';

Expand Down Expand Up @@ -89,7 +90,7 @@ class BrowserConfigurationTest extends AbstractTestCase
protected function setUpTest()
{
if ( !$this->browserConfigurationClass ) {
$this->browserConfigurationClass = 'aik099\\PHPUnit\\BrowserConfiguration\\BrowserConfiguration';
$this->browserConfigurationClass = BrowserConfiguration::class;
}

$this->setup = array(
Expand All @@ -116,9 +117,9 @@ protected function setUpTest()
*/
protected function createDriverFactoryRegistry()
{
$registry = m::mock('\\aik099\\PHPUnit\\MinkDriver\\DriverFactoryRegistry');
$registry = m::mock(DriverFactoryRegistry::class);

$selenium2_driver_factory = m::mock('\\aik099\\PHPUnit\\MinkDriver\\IMinkDriverFactory');
$selenium2_driver_factory = m::mock(IMinkDriverFactory::class);
$selenium2_driver_factory->shouldReceive('getDriverDefaults')->andReturn(array(
'baseUrl' => 'http://www.super-url.com',
'driverOptions' => array(
Expand All @@ -130,7 +131,7 @@ protected function createDriverFactoryRegistry()
->with('selenium2')
->andReturn($selenium2_driver_factory);

$zombie_driver_factory = m::mock('\\aik099\\PHPUnit\\MinkDriver\\IMinkDriverFactory');
$zombie_driver_factory = m::mock(IMinkDriverFactory::class);
$zombie_driver_factory->shouldReceive('getDriverDefaults')->andReturn(array());
$registry
->shouldReceive('get')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace tests\aik099\PHPUnit\BrowserConfiguration;


use aik099\PHPUnit\BrowserConfiguration\BrowserStackBrowserConfiguration;

class BrowserStackBrowserConfigurationTest extends ApiBrowserConfigurationTestCase
{

Expand All @@ -21,7 +23,7 @@ class BrowserStackBrowserConfigurationTest extends ApiBrowserConfigurationTestCa
*/
protected function setUpTest()
{
$this->browserConfigurationClass = 'aik099\\PHPUnit\\BrowserConfiguration\\BrowserStackBrowserConfiguration';
$this->browserConfigurationClass = BrowserStackBrowserConfiguration::class;

$this->tunnelCapabilities = array(
'browserstack.local' => 'true',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace tests\aik099\PHPUnit\BrowserConfiguration;


use aik099\PHPUnit\BrowserConfiguration\SauceLabsBrowserConfiguration;

class SauceLabsBrowserConfigurationTest extends ApiBrowserConfigurationTestCase
{

Expand All @@ -21,7 +23,7 @@ class SauceLabsBrowserConfigurationTest extends ApiBrowserConfigurationTestCase
*/
protected function setUpTest()
{
$this->browserConfigurationClass = 'aik099\\PHPUnit\\BrowserConfiguration\\SauceLabsBrowserConfiguration';
$this->browserConfigurationClass = SauceLabsBrowserConfiguration::class;

$this->tunnelCapabilities = array(
'tunnel-identifier' => 'env:PHPUNIT_MINK_TUNNEL_ID',
Expand Down
46 changes: 22 additions & 24 deletions tests/aik099/PHPUnit/BrowserTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@
use tests\aik099\PHPUnit\Fixture\WithBrowserConfig;
use tests\aik099\PHPUnit\Fixture\WithoutBrowserConfig;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
use aik099\PHPUnit\MinkDriver\IMinkDriverFactory;
use Behat\Mink\Session;
use ConsoleHelpers\CodeCoverageCompat\Driver\Driver;

class BrowserTestCaseTest extends AbstractTestCase
{

use ExpectException;

const BROWSER_CLASS = '\\aik099\\PHPUnit\\BrowserConfiguration\\BrowserConfiguration';
const BROWSER_CLASS = BrowserConfiguration::class;

const MANAGER_CLASS = '\\aik099\\PHPUnit\\Session\\SessionStrategyManager';
const MANAGER_CLASS = SessionStrategyManager::class;

const SESSION_STRATEGY_INTERFACE = '\\aik099\\PHPUnit\\Session\\ISessionStrategy';
const SESSION_STRATEGY_INTERFACE = ISessionStrategy::class;

/**
* Browser configuration factory.
Expand All @@ -59,9 +62,7 @@ protected function setUpTest()
define('PHPUNIT_TESTSUITE', true);
}

$this->browserConfigurationFactory = m::mock(
'aik099\\PHPUnit\\BrowserConfiguration\\IBrowserConfigurationFactory'
);
$this->browserConfigurationFactory = m::mock(IBrowserConfigurationFactory::class);
}

/**
Expand Down Expand Up @@ -109,9 +110,9 @@ public function testSetBrowserCorrect()
*/
protected function createDriverFactoryRegistry()
{
$registry = m::mock('\\aik099\\PHPUnit\\MinkDriver\\DriverFactoryRegistry');
$registry = m::mock(DriverFactoryRegistry::class);

$driver_factory = m::mock('\\aik099\\PHPUnit\\MinkDriver\\IMinkDriverFactory');
$driver_factory = m::mock(IMinkDriverFactory::class);
$driver_factory->shouldReceive('getDriverDefaults')->andReturn(array());

$registry
Expand Down Expand Up @@ -203,8 +204,8 @@ public function testGetSession()
{
$browser = $this->getBrowser(0);

$expected_session1 = m::mock('\\Behat\\Mink\\Session');
$expected_session2 = m::mock('\\Behat\\Mink\\Session');
$expected_session1 = m::mock(Session::class);
$expected_session2 = m::mock(Session::class);

/** @var ISessionStrategy $session_strategy */
$session_strategy = m::mock(self::SESSION_STRATEGY_INTERFACE);
Expand Down Expand Up @@ -291,10 +292,7 @@ public function testGetCollectCodeCoverageInformationSuccess()
);
}
else {
$code_coverage = new CodeCoverage(
m::mock('\\ConsoleHelpers\\CodeCoverageCompat\\Driver\\Driver'),
new Filter()
);
$code_coverage = new CodeCoverage(m::mock(Driver::class), new Filter());
}

$test_result->setCodeCoverage($code_coverage);
Expand Down Expand Up @@ -331,7 +329,7 @@ public function testRunCreateResult()
/** @var BrowserTestCase $test_case */
list($test_case,) = $this->prepareForRun();

$this->assertInstanceOf('\\ConsoleHelpers\\PHPUnitCompat\\Framework\\TestResult', $test_case->run());
$this->assertInstanceOf(TestResult::class, $test_case->run());
}

/**
Expand Down Expand Up @@ -368,7 +366,7 @@ public function testRunWithCoverageWithoutRemoteUrl()
$browser = $test_case->getBrowser();
$browser->shouldReceive('getBaseUrl')->once()->andReturn('A');

$session = m::mock('\\Behat\\Mink\\Session');
$session = m::mock(Session::class);
$session->shouldReceive('visit')->with('A')->once();
$session->shouldReceive('setCookie')->with(RemoteCoverageTool::TEST_ID_VARIABLE, null)->once();
$session->shouldReceive('setCookie')->with(RemoteCoverageTool::TEST_ID_VARIABLE, m::not(''))->once();
Expand All @@ -377,7 +375,7 @@ public function testRunWithCoverageWithoutRemoteUrl()

$test_case->run($result);

if ( \class_exists('\SebastianBergmann\CodeCoverage\ProcessedCodeCoverageData') ) {
if ( \class_exists(ProcessedCodeCoverageData::class) ) {
$actual_coverage = $code_coverage->getData();
$expected_coverage = new ProcessedCodeCoverageData();
$expected_coverage->setLineCoverage(array(
Expand Down Expand Up @@ -443,7 +441,7 @@ public function testRunWithCoverage()
$browser = $test_case->getBrowser();
$browser->shouldReceive('getBaseUrl')->once()->andReturn('A');

$session = m::mock('\\Behat\\Mink\\Session');
$session = m::mock(Session::class);
$session->shouldReceive('visit')->with('A')->once();
$session->shouldReceive('setCookie')->with(RemoteCoverageTool::TEST_ID_VARIABLE, null)->once();
$session->shouldReceive('setCookie')->with(RemoteCoverageTool::TEST_ID_VARIABLE, m::not(''))->once();
Expand All @@ -454,7 +452,7 @@ public function testRunWithCoverage()

$covered_by_test = 'tests\aik099\PHPUnit\Fixture\WithoutBrowserConfig::getTestId';

if ( \class_exists('\SebastianBergmann\CodeCoverage\ProcessedCodeCoverageData') ) {
if ( \class_exists(ProcessedCodeCoverageData::class) ) {
$expected_coverage = new ProcessedCodeCoverageData();
$expected_coverage->setLineCoverage(array(
$this->getCoverageFixtureFile() => array(
Expand Down Expand Up @@ -502,10 +500,10 @@ protected function getCoverageFixtureFile()
*/
protected function getRemoteCoverageHelperMock(array $expected_coverage = null)
{
$remote_coverage_helper = m::mock('aik099\\PHPUnit\\RemoteCoverage\\RemoteCoverageHelper');
$remote_coverage_helper = m::mock(RemoteCoverageHelper::class);

if ( $expected_coverage !== null ) {
if ( \class_exists('\SebastianBergmann\CodeCoverage\RawCodeCoverageData') ) {
if ( \class_exists(RawCodeCoverageData::class) ) {
$remote_coverage_helper
->shouldReceive('get')
->with('some-url', 'tests\aik099\PHPUnit\Fixture\WithoutBrowserConfig__getTestId')
Expand All @@ -519,7 +517,7 @@ protected function getRemoteCoverageHelperMock(array $expected_coverage = null)
}
}

if ( \class_exists('\SebastianBergmann\CodeCoverage\RawCodeCoverageData') ) {
if ( \class_exists(RawCodeCoverageData::class) ) {
$remote_coverage_helper
->shouldReceive('getEmpty')
->andReturn(RawCodeCoverageData::fromXdebugWithoutPathCoverage(array()));
Expand All @@ -546,13 +544,13 @@ protected function getCodeCoverageMock(array $expected_coverage)
$driver = m::mock('\PHP_CodeCoverage_Driver');
}
else {
$driver = m::mock('\\ConsoleHelpers\\CodeCoverageCompat\\Driver\\Driver');
$driver = m::mock(Driver::class);
}

$driver->shouldReceive('start')->once();

// Can't assert call count, because expectations are verified prior to coverage being queried.
if ( \class_exists('\SebastianBergmann\CodeCoverage\RawCodeCoverageData') ) {
if ( \class_exists(RawCodeCoverageData::class) ) {
$driver->shouldReceive('stop')
/*->once()*/
->andReturn(
Expand Down