Skip to content

Commit

Permalink
Update to namespaced PHPUnit 6
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Feb 27, 2018
1 parent ac305eb commit 4fce867
Show file tree
Hide file tree
Showing 25 changed files with 80 additions and 52 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
- Detect readiness state of new Selenium servers (v3.5.3+ running in W3C-protocol mode) during startup, so that eg. no available Selenium server nodes are reported before attempting to start any test.

### Changed
- Require PHP 7.1+ and Symfony 4 components
- Require PHP 7.1+ and Symfony 4 components.
- Update to namespaced PHPUnit 6.0.
- `RunTestsProcessEvent` (dispatched from `run` command when initializing PHPUnit processes) now contains array of environment variables instead of ProcessBuilder. Use `setEnvironmentVars()` method to change the variables passed to the process.
- Default browser size is now defined using class constants instead of class variables. To override the default, instead of `public static $browserWidth = ...;` use `public const BROWSER_WIDTH = ...;`.
- When test class constants defining default browser width (`BROWSER_WIDTH`) or height (`BROWSER_HEIGHT`) is set to `null`, no default browser window size will be set on test startup.
Expand Down
2 changes: 1 addition & 1 deletion bin/phpunit-steward
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ function requireIfExists($file)

requireIfExists(__DIR__ . '/../vendor/autoload.php') || requireIfExists(__DIR__ . '/../../../autoload.php');

PHPUnit_TextUI_Command::main();
\PHPUnit\TextUI\Command::main();
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"php": "^7.1",
"ext-zip": "*",
"ext-curl": "*",
"phpunit/phpunit": "^5.7.11",
"phpunit/phpunit": "^6.4",
"symfony/console": "^4.0",
"symfony/process": "^4.0 !=4.0.2",
"symfony/finder": "^4.0",
Expand All @@ -49,7 +49,7 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.1",
"php-mock/php-mock-phpunit": "~1.0",
"php-mock/php-mock-phpunit": "^2.0.1",
"php-coveralls/php-coveralls": "^2.0",
"friendsofphp/php-cs-fixer": "^2.0",
"symfony/var-dumper": "^4.0",
Expand Down
3 changes: 2 additions & 1 deletion src-tests/Component/AbstractComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Lmc\Steward\Component\Fixtures\MockComponent;
use Lmc\Steward\ConfigHelper;
use Lmc\Steward\Test\AbstractTestCase;
use PHPUnit\Framework\Error\Error;
use PHPUnit\Framework\TestCase;

class AbstractComponentTest extends TestCase
Expand Down Expand Up @@ -61,7 +62,7 @@ public function testShouldNotLogDebugMessagesIfDebugModeIsNotEnabled()

public function testShouldFailIfNotExistingMethodIsCalled()
{
$this->expectException(\PHPUnit_Framework_Error::class);
$this->expectException(Error::class);
$this->expectExceptionMessage(
'Call to undefined method Lmc\Steward\Component\AbstractComponent::notExisting()'
);
Expand Down
4 changes: 3 additions & 1 deletion src-tests/Console/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Lmc\Steward\Console;

class ApplicationTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class ApplicationTest extends TestCase
{
public function testShouldAddCustomInputDefinition()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest> There was 1 failu
Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest> 1) Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest::testThatWillFail%A
Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest> Sorry :-(%A
Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest> FAILURES!
Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest> Tests: 1, Assertions: 0, Failures: 1.%A
Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest> Tests: 1, Assertions: 1, Failures: 1.%A
[%s] Finished execution of testcase "Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest" (result: failed, time: %f sec)
[%s] Failing testcase "Lmc\Steward\Console\Command\Fixtures\FailingTests\DependantTest", because it was depending on failed "Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest"
[%s] Waiting (running: 0, queued: 0, done: 2 [failed: 2])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest> There was 1 failu
Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest> 1) Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest::testThatWillFail%A
Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest> Sorry :-(%A
Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest> FAILURES!%A
Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest> Tests: 1, Assertions: 0, Failures: 1.%A
Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest> Tests: 1, Assertions: 1, Failures: 1.%A
[%s] Failing testcase "Lmc\Steward\Console\Command\Fixtures\FailingTests\DependantTest", because it was depending on failed "Lmc\Steward\Console\Command\Fixtures\FailingTests\FailingTest"
[%s] Waiting (running: 0, queued: 0, done: 2 [failed: 2])
[%s] All testcases done in %f seconds
Expand Down
3 changes: 2 additions & 1 deletion src-tests/Console/Configuration/ConfigFileReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Lmc\Steward\Console\Configuration;

use Assert\InvalidArgumentException;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Steward\Console\Configuration\ConfigFileReader
*/
class ConfigFileReaderTest extends \PHPUnit_Framework_TestCase
class ConfigFileReaderTest extends TestCase
{
/**
* @dataProvider providePathToConfigFile
Expand Down
3 changes: 2 additions & 1 deletion src-tests/Console/Configuration/ConfigResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Assert\InvalidArgumentException;
use Lmc\Steward\Console\Command\CleanCommand;
use Lmc\Steward\Console\Command\RunCommand;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\EventDispatcher\EventDispatcher;
Expand All @@ -13,7 +14,7 @@
/**
* @covers \Lmc\Steward\Console\Configuration\ConfigResolver
*/
class ConfigResolverTest extends \PHPUnit_Framework_TestCase
class ConfigResolverTest extends TestCase
{
public function testShouldResolveDefaultGeneralOptions()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
use Lmc\Steward\Console\Configuration\Fixtures\DoesNotImplementInterface;
use Lmc\Steward\Console\Configuration\Fixtures\ImplementsCapabilitiesResolverInterface;
use Lmc\Steward\Selenium\CustomCapabilitiesResolverInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @covers \Lmc\Steward\Console\Configuration\OptionsResolverConfigurator
*/
class OptionsResolverConfiguratorTest extends \PHPUnit_Framework_TestCase
class OptionsResolverConfiguratorTest extends TestCase
{
public function testShouldConfigureGivenOptionsResolver()
{
Expand Down
1 change: 1 addition & 0 deletions src-tests/FunctionalTests/Select2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function testShouldCreateNewInstanceForSelect2AndDetectIfItIsMultiple($se
$this->assertContainsOnlyInstancesOf(WebDriverElement::class, $options);

$actualOptions = [];
/** @var WebDriverElement $option */
foreach ($options as $option) {
$actualOptions[] = $option->getText();
}
Expand Down
3 changes: 2 additions & 1 deletion src-tests/Listener/Fixtures/DummyPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lmc\Steward\Listener\Fixtures;

use Lmc\Steward\Publisher\AbstractPublisher;
use PHPUnit\Framework\Test;

class DummyPublisher extends AbstractPublisher
{
Expand All @@ -18,7 +19,7 @@ public function publishResults(
public function publishResult(
$testCaseName,
$testName,
\PHPUnit_Framework_Test $testInstance,
Test $testInstance,
$status,
$result = null,
$message = null
Expand Down
3 changes: 2 additions & 1 deletion src-tests/Listener/Fixtures/ExceptionThrowingPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lmc\Steward\Listener\Fixtures;

use Lmc\Steward\Publisher\AbstractPublisher;
use PHPUnit\Framework\Test;

/**
* Throw an exception anytime its public methods are called
Expand All @@ -22,7 +23,7 @@ public function publishResults(
public function publishResult(
$testCaseName,
$testName,
\PHPUnit_Framework_Test $testInstance,
Test $testInstance,
$status,
$result = null,
$message = null
Expand Down
8 changes: 5 additions & 3 deletions src-tests/Listener/SnapshotListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Lmc\Steward\Test\AbstractTestCase;
use Lmc\Steward\WebDriver\RemoteWebDriver;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\WarningTestCase;

/**
* @covers \Lmc\Steward\Listener\SnapshotListener
Expand Down Expand Up @@ -87,7 +89,7 @@ public function testShouldTakeSnapshot(
public function provideBasicTestEvent()
{
$dummyException = new \Exception('Error exception', 333);
$dummyFailureException = new \PHPUnit_Framework_AssertionFailedError('Failure exception');
$dummyFailureException = new AssertionFailedError('Failure exception');

return [
['addError', $dummyException, 'FooBarTest', 'testFooBar', '', [], 'FooBarTest-testFooBar'],
Expand Down Expand Up @@ -126,11 +128,11 @@ public function provideTestWithDataSet()

public function testShouldNotTakeSnapshotIfTestIsNotStewardAbstractTestCase()
{
$test = new \PHPUnit_Framework_WarningTestCase('foo');
$test = new WarningTestCase('foo');

$listener = new SnapshotListener();
$listener->addError($test, new \Exception('Error', 333), 3.3);
$listener->addFailure($test, new \PHPUnit_Framework_AssertionFailedError('Failure'), 3.3);
$listener->addFailure($test, new AssertionFailedError('Failure'), 3.3);

$this->assertEmpty($test->getActualOutput());
}
Expand Down
3 changes: 2 additions & 1 deletion src-tests/Listener/TestStatusListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Lmc\Steward\Publisher\TestingBotPublisher;
use Lmc\Steward\Selenium\SeleniumServerAdapter;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\WarningTestCase;

class TestStatusListenerTest extends TestCase
{
Expand All @@ -33,7 +34,7 @@ public function testShouldNotDoAnythingWhenWarningTestCaseOccurs()

$listener = new TestStatusListener($publishers, $this->seleniumAdapterMock);

$warningTestCase = new \PHPUnit_Framework_WarningTestCase('Warning');
$warningTestCase = new WarningTestCase('Warning');

$listener->startTest($warningTestCase);
$listener->endTest($warningTestCase, 1);
Expand Down
9 changes: 4 additions & 5 deletions src-tests/Process/ProcessWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Assert\InvalidArgumentException;
use Lmc\Steward\Publisher\XmlPublisher;
use PHPUnit\Framework\TestCase;
use PHPUnit\TextUI\TestRunner;
use Symfony\Component\Process\Exception\ProcessTimedOutException;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -124,11 +125,9 @@ public function provideProcessResult()
{
return [
// $exitCode, $expectedResult
'Testcase succeeded' => [\PHPUnit_TextUI_TestRunner::SUCCESS_EXIT, ProcessWrapper::PROCESS_RESULT_PASSED],
'Exception thrown from PHPUnit' =>
[\PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT, ProcessWrapper::PROCESS_RESULT_FAILED],
'Some test failed' =>
[\PHPUnit_TextUI_TestRunner::FAILURE_EXIT, ProcessWrapper::PROCESS_RESULT_FAILED],
'Testcase succeeded' => [TestRunner::SUCCESS_EXIT, ProcessWrapper::PROCESS_RESULT_PASSED],
'Exception thrown from PHPUnit' => [TestRunner::EXCEPTION_EXIT, ProcessWrapper::PROCESS_RESULT_FAILED],
'Some test failed' => [TestRunner::FAILURE_EXIT, ProcessWrapper::PROCESS_RESULT_FAILED],
'PHP fatal error' => [255, ProcessWrapper::PROCESS_RESULT_FATAL],
'Process was killed' => [9, ProcessWrapper::PROCESS_RESULT_FATAL],
'Process was terminated' => [9, ProcessWrapper::PROCESS_RESULT_FATAL],
Expand Down
5 changes: 3 additions & 2 deletions src-tests/Publisher/XmlPublisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Lmc\Steward\Test\AbstractTestCase;
use Lmc\Steward\WebDriver\RemoteWebDriver;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;

class XmlPublisherTest extends TestCase
Expand All @@ -14,7 +15,7 @@ class XmlPublisherTest extends TestCase

/** @var XmlPublisher */
protected $publisher;
/** @var \PHPUnit_Framework_MockObject_MockObject|\PHPUnit_Framework_Test */
/** @var \PHPUnit_Framework_MockObject_MockObject|Test */
protected $testInstanceMock;

public function setUp()
Expand All @@ -25,7 +26,7 @@ public function setUp()
ConfigHelper::unsetConfigInstance();

$this->publisher = new XmlPublisher();
$this->testInstanceMock = $this->getMockBuilder(\PHPUnit_Framework_Test::class)
$this->testInstanceMock = $this->getMockBuilder(Test::class)
->getMock();
}

Expand Down
6 changes: 4 additions & 2 deletions src/Listener/SnapshotListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
use Lmc\Steward\ConfigProvider;
use Lmc\Steward\Test\AbstractTestCase;
use Lmc\Steward\Utils\Strings;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\Test;

/**
* Listener to take snapshots of the page (screenshot and html snapshot) on each error or failure.
*/
class SnapshotListener extends BaseTestListener
{
public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time)
public function addError(Test $test, \Exception $e, $time)
{
if ($test instanceof AbstractTestCase) {
$this->takeSnapshot($test);
}
}

public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time)
public function addFailure(Test $test, AssertionFailedError $e, $time)
{
if ($test instanceof AbstractTestCase) {
$this->takeSnapshot($test);
Expand Down
19 changes: 12 additions & 7 deletions src/Listener/TestStatusListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
use Lmc\Steward\Publisher\XmlPublisher;
use Lmc\Steward\Selenium\SeleniumServerAdapter;
use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\DataProviderTestSuite;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\WarningTestCase;

/**
* Listener to log status of test case and at the end of suite publish them using registered publishers.
Expand Down Expand Up @@ -69,14 +74,14 @@ public function __construct(array $customTestPublishers, SeleniumServerAdapter $
}
}

public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
public function startTestSuite(TestSuite $suite)
{
$this->startDate = new \DateTimeImmutable();
}

public function startTest(\PHPUnit_Framework_Test $test)
public function startTest(Test $test)
{
if (!$test instanceof \PHPUnit_Framework_TestCase || $test instanceof \PHPUnit_Framework_WarningTestCase) {
if (!$test instanceof TestCase || $test instanceof WarningTestCase) {
return;
}

Expand All @@ -100,9 +105,9 @@ public function startTest(\PHPUnit_Framework_Test $test)
}
}

public function endTest(\PHPUnit_Framework_Test $test, $time)
public function endTest(Test $test, $time)
{
if (!$test instanceof \PHPUnit_Framework_TestCase || $test instanceof \PHPUnit_Framework_WarningTestCase) {
if (!$test instanceof TestCase || $test instanceof WarningTestCase) {
return;
}

Expand All @@ -128,9 +133,9 @@ public function endTest(\PHPUnit_Framework_Test $test, $time)
}
}

public function endTestSuite(\PHPUnit_Framework_TestSuite $suite)
public function endTestSuite(TestSuite $suite)
{
if ($suite instanceof \PHPUnit_Framework_TestSuite_DataProvider) {
if ($suite instanceof DataProviderTestSuite) {
return;
}

Expand Down
10 changes: 6 additions & 4 deletions src/Listener/WebDriverListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Lmc\Steward\WebDriver\RemoteWebDriver;
use Nette\Reflection\AnnotationsParser;
use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\WarningTestCase;

/**
* Listener for initialization and destruction of WebDriver before and after each test.
Expand Down Expand Up @@ -48,9 +50,9 @@ protected function getCapabilitiesResolver()
return $this->capabilitiesResolver;
}

public function startTest(\PHPUnit_Framework_Test $test)
public function startTest(Test $test)
{
if ($test instanceof \PHPUnit_Framework_WarningTestCase) {
if ($test instanceof WarningTestCase) {
return;
}

Expand Down Expand Up @@ -99,9 +101,9 @@ public function startTest(\PHPUnit_Framework_Test $test)
);
}

public function endTest(\PHPUnit_Framework_Test $test, $time)
public function endTest(Test $test, $time)
{
if ($test instanceof \PHPUnit_Framework_WarningTestCase) {
if ($test instanceof WarningTestCase) {
return;
}

Expand Down
Loading

0 comments on commit 4fce867

Please sign in to comment.