Skip to content

Commit

Permalink
Don't automatically enable remote code coverage collection
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Obuhovich committed Nov 27, 2014
1 parent d37c113 commit 137af5f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 27 deletions.
6 changes: 2 additions & 4 deletions docs/remote-code-coverage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ On Test Machine
^^^^^^^^^^^^^^^
This is machine, where PHPUnit tests are being executed.

By default the ``baseUrl`` setting from browser configuration is used as the
"remote code coverage information url". However if a need exists to set alternative url on
per-test basis, then place following code in the ``setUp`` method of the test case class,
that extends ``BrowserTestCase`` class:
Following code needs to be placed in the ``setUp`` method of the test case class (that extends ``BrowserTestCase``
class) to enable remote coverage information collection:

.. code-block:: php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ public static function getSubscribedEvents()
public function attachToTestCase(BrowserTestCase $test_case)
{
$this->_testCase = $test_case;
$this->_testCase->setRemoteCoverageScriptUrl($this->getBaseUrl());
$this->_eventDispatcher->addSubscriber($this);

return $this;
Expand Down
9 changes: 4 additions & 5 deletions library/aik099/PHPUnit/BrowserTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,17 @@ public function onTestSuiteEnded()
}

/**
* Returns remote code coverage information.
* Returns remote code coverage information, when enabled.
*
* @return array
* @throws \RuntimeException When no remote coverage script URL set.
*/
public function getRemoteCodeCoverageInformation()
{
if ( $this->_remoteCoverageScriptUrl == '' ) {
throw new \RuntimeException('Remote coverage script url not set');
if ( $this->_remoteCoverageScriptUrl ) {
return $this->remoteCoverageHelper->get($this->_remoteCoverageScriptUrl, $this->_testId);
}

return $this->remoteCoverageHelper->get($this->_remoteCoverageScriptUrl, $this->_testId);
return array();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ public function testTestEndedWithoutSession()
protected function createTestCase($name)
{
$test_case = m::mock(self::TEST_CASE_CLASS);
$test_case->shouldReceive('setRemoteCoverageScriptUrl')->once();
$test_case->shouldReceive('getName')->andReturn($name);
$this->browser->attachToTestCase($test_case);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public function testAttachToTestCase()

/* @var $test_case BrowserTestCase */
$test_case = m::mock(self::TEST_CASE_CLASS);
$test_case->shouldReceive('setRemoteCoverageScriptUrl')->with('')->once();

$this->assertSame($browser, $browser->attachToTestCase($test_case));
$this->assertSame($test_case, $browser->getTestCase());
Expand Down Expand Up @@ -385,7 +384,6 @@ public function testGetSessionStrategyHashBrowserSharing($session_strategy)
{
/* @var $test_case BrowserTestCase */
$test_case = m::mock(self::TEST_CASE_CLASS);
$test_case->shouldReceive('setRemoteCoverageScriptUrl')->with('')->twice();

$browser1 = $this->createBrowserConfiguration(array(), true);
$browser1->setSessionStrategy($session_strategy)->attachToTestCase($test_case);
Expand Down
19 changes: 5 additions & 14 deletions tests/aik099/PHPUnit/BrowserTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,6 @@ public function testGetCollectCodeCoverageInformationSuccess()
$this->assertTrue($test_case->getCollectCodeCoverageInformation());
}

/**
* Test description.
*
* @return void
* @expectedException \RuntimeException
*/
public function testGetCollectCodeCoverageInformationFailure()
{
$this->getFixture()->getCollectCodeCoverageInformation();
}

/**
* Test description.
*
Expand Down Expand Up @@ -292,17 +281,19 @@ public function testRunCreateResult()
* Test description.
*
* @return void
* @expectedException \RuntimeException
*/
public function testRunWithCoverageWithoutRemoteUrl()
{
/* @var $test_case BrowserTestCase */
/* @var $session_strategy ISessionStrategy */
list($test_case, $session_strategy) = $this->prepareForRun(array(), false);
list($test_case, $session_strategy) = $this->prepareForRun(array());
$test_case->setName('getTestId');

$code_coverage = m::mock('\\PHP_CodeCoverage');
$code_coverage->shouldReceive('append')->with(m::mustBe(array()), $test_case)->once();

$result = $this->getTestResult($test_case, 1, true);
$result->shouldReceive('getCodeCoverage')->once()->andReturn(m::mock('\\PHP_CodeCoverage'));
$result->shouldReceive('getCodeCoverage')->once()->andReturn($code_coverage);

$test_id = $test_case->getTestId();
$this->assertEmpty($test_id);
Expand Down
1 change: 1 addition & 0 deletions tests/aik099/PHPUnit/Fixture/ApiIntegrationFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public function getBrowserAliases()

'browserName' => 'chrome',
'desiredCapabilities' => array('version' => 28),
'baseUrl' => 'http://www.google.com',
),
/*'browserstack' => array(
'type' => 'browserstack',
Expand Down
35 changes: 35 additions & 0 deletions tests/aik099/PHPUnit/Integration/DataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
class DataProviderTest extends BrowserTestCase
{

/**
* Browser list to be used in tests.
*
* @var array
*/
public static $browsers = array(
array('alias' => 'saucelabs'),
// array('alias' => 'browserstack'),
);

public function sampleDataProvider()
{
return array(
Expand Down Expand Up @@ -45,4 +55,29 @@ protected function customMethod()
return 5;
}

/**
* Gets browser configuration aliases.
*
* Allows to decouple actual test server connection details from test cases.
*
* @return array
*/
public function getBrowserAliases()
{
return array(
'saucelabs' => array(
'type' => 'saucelabs',
'api_username' => getenv('SAUCE_USERNAME'),
'api_key' => getenv('SAUCE_ACCESS_KEY'),

'browserName' => 'chrome',
'desiredCapabilities' => array('version' => 28),
'baseUrl' => 'http://www.google.com',
),
/*'browserstack' => array(
'type' => 'browserstack',
),*/
);
}

}

0 comments on commit 137af5f

Please sign in to comment.