diff --git a/CHANGELOG.md b/CHANGELOG.md index 5858b43c..61d89807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ ### Fixed - Remote server running in W3C-protocol mode (eg. Selenium v3.5.3+) was erroneously detected as BrowserStack cloud service. - `--xdebug` option did not have any effect unless passed as the last option. +- Do not start browser for test skipped because it was depending on some already failed test (using `@depends` annotation). ### Removed - `TestUtils` class which was already deprecated in 2.1. diff --git a/composer.json b/composer.json index b7e82e67..f85dbcf7 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "ext-filter": "*", "ext-SimpleXML": "*", "ext-libxml": "*", - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "7.4.x-dev", "symfony/console": "^4.0", "symfony/process": "^4.0 !=4.0.2", "symfony/finder": "^4.0", @@ -55,7 +55,7 @@ "ondram/ci-detector": "^3.0" }, "require-dev": { - "php-mock/php-mock-phpunit": "^2.1.0", + "php-mock/php-mock-phpunit": "^2.1.2", "phpunit/php-code-coverage": "^6.0", "php-coveralls/php-coveralls": "^2.0", "symfony/var-dumper": "^4.0", diff --git a/src-tests/Console/Command/Fixtures/SkippedTests/SkippedTest.php b/src-tests/Console/Command/Fixtures/SkippedTests/SkippedTest.php new file mode 100644 index 00000000..72043434 --- /dev/null +++ b/src-tests/Console/Command/Fixtures/SkippedTests/SkippedTest.php @@ -0,0 +1,20 @@ +fail(); + } + + /** + * @depends testWhichFails + */ + public function testsWhichShouldBeSkipped(): void + { + } +} diff --git a/src-tests/Console/Command/RunCommandIntegrationTest.php b/src-tests/Console/Command/RunCommandIntegrationTest.php index bddc16c6..b0092a49 100644 --- a/src-tests/Console/Command/RunCommandIntegrationTest.php +++ b/src-tests/Console/Command/RunCommandIntegrationTest.php @@ -12,6 +12,7 @@ * Run command tests that require real Selenium server to execute the tests. * * @covers \Lmc\Steward\Console\Command\RunCommand + * @covers \Lmc\Steward\Listener\WebDriverListener * @covers \Lmc\Steward\Process\ExecutionLoop * @group integration * @runTestsInSeparateProcesses @@ -158,4 +159,19 @@ public function testShouldExitWithCode0EvenWithFailedTestsWhenNoExitOptionIsPass $this->assertSame(0, $this->tester->getStatusCode()); } + + public function testShouldNotStartBrowserForSkippedTests(): void + { + $this->tester->execute( + [ + 'command' => $this->command->getName(), + 'environment' => 'staging', + 'browser' => 'chrome', + '--tests-dir' => __DIR__ . '/Fixtures/SkippedTests', + ], + ['verbosity' => OutputInterface::VERBOSITY_DEBUG] + ); + + $this->assertSame(1, mb_substr_count($this->tester->getDisplay(), 'Initializing "chrome" WebDriver')); + } } diff --git a/src/Listener/WebDriverListener.php b/src/Listener/WebDriverListener.php index cb7ce5cd..85bd0a0f 100644 --- a/src/Listener/WebDriverListener.php +++ b/src/Listener/WebDriverListener.php @@ -16,6 +16,7 @@ use PHPUnit\Framework\TestListener; use PHPUnit\Framework\TestListenerDefaultImplementation; use PHPUnit\Framework\WarningTestCase; +use PHPUnit\Runner\BaseTestRunner; /** * Listener for initialization and destruction of WebDriver before and after each test. @@ -60,6 +61,10 @@ public function startTest(Test $test): void throw new \InvalidArgumentException('Test case must be descendant of Lmc\Steward\Test\AbstractTestCase'); } + if ($test->getStatus() === BaseTestRunner::STATUS_SKIPPED) { + return; + } + // Initialize NullWebDriver if self::NO_BROWSER_ANNOTATION is used on testcase class or test method $testCaseAnnotations = AnnotationsParser::getAll(new \ReflectionClass($test)); $testAnnotations = AnnotationsParser::getAll(new \ReflectionMethod($test, $test->getName(false)));