Skip to content

Commit

Permalink
Do not start browser for skipped tests (fixes #154)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Nov 5, 2018
1 parent 2a0033b commit 5920b09
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions src-tests/Console/Command/Fixtures/SkippedTests/SkippedTest.php
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

namespace Lmc\Steward\Console\Command\Fixtures\SkippedTests;

use Lmc\Steward\Test\AbstractTestCase;

class SkippedTest extends AbstractTestCase
{
public function testWhichFails(): void
{
$this->fail();
}

/**
* @depends testWhichFails
*/
public function testsWhichShouldBeSkipped(): void
{
}
}
15 changes: 15 additions & 0 deletions src-tests/Console/Command/RunCommandIntegrationTest.php
Expand Up @@ -158,4 +158,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'));
}
}
5 changes: 5 additions & 0 deletions src/Listener/WebDriverListener.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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)));
Expand Down

0 comments on commit 5920b09

Please sign in to comment.