Skip to content

Commit 137af5f

Browse files
author
Alexander Obuhovich
committed
Don't automatically enable remote code coverage collection
1 parent d37c113 commit 137af5f

File tree

8 files changed

+47
-27
lines changed

8 files changed

+47
-27
lines changed

docs/remote-code-coverage.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ On Test Machine
2323
^^^^^^^^^^^^^^^
2424
This is machine, where PHPUnit tests are being executed.
2525

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

3129
.. code-block:: php
3230

library/aik099/PHPUnit/BrowserConfiguration/BrowserConfiguration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ public static function getSubscribedEvents()
147147
public function attachToTestCase(BrowserTestCase $test_case)
148148
{
149149
$this->_testCase = $test_case;
150-
$this->_testCase->setRemoteCoverageScriptUrl($this->getBaseUrl());
151150
$this->_eventDispatcher->addSubscriber($this);
152151

153152
return $this;

library/aik099/PHPUnit/BrowserTestCase.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,18 +387,17 @@ public function onTestSuiteEnded()
387387
}
388388

389389
/**
390-
* Returns remote code coverage information.
390+
* Returns remote code coverage information, when enabled.
391391
*
392392
* @return array
393-
* @throws \RuntimeException When no remote coverage script URL set.
394393
*/
395394
public function getRemoteCodeCoverageInformation()
396395
{
397-
if ( $this->_remoteCoverageScriptUrl == '' ) {
398-
throw new \RuntimeException('Remote coverage script url not set');
396+
if ( $this->_remoteCoverageScriptUrl ) {
397+
return $this->remoteCoverageHelper->get($this->_remoteCoverageScriptUrl, $this->_testId);
399398
}
400399

401-
return $this->remoteCoverageHelper->get($this->_remoteCoverageScriptUrl, $this->_testId);
400+
return array();
402401
}
403402

404403
/**

tests/aik099/PHPUnit/BrowserConfiguration/ApiBrowserConfigurationTestCase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ public function testTestEndedWithoutSession()
332332
protected function createTestCase($name)
333333
{
334334
$test_case = m::mock(self::TEST_CASE_CLASS);
335-
$test_case->shouldReceive('setRemoteCoverageScriptUrl')->once();
336335
$test_case->shouldReceive('getName')->andReturn($name);
337336
$this->browser->attachToTestCase($test_case);
338337

tests/aik099/PHPUnit/BrowserConfiguration/BrowserConfigurationTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ public function testAttachToTestCase()
183183

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

188187
$this->assertSame($browser, $browser->attachToTestCase($test_case));
189188
$this->assertSame($test_case, $browser->getTestCase());
@@ -385,7 +384,6 @@ public function testGetSessionStrategyHashBrowserSharing($session_strategy)
385384
{
386385
/* @var $test_case BrowserTestCase */
387386
$test_case = m::mock(self::TEST_CASE_CLASS);
388-
$test_case->shouldReceive('setRemoteCoverageScriptUrl')->with('')->twice();
389387

390388
$browser1 = $this->createBrowserConfiguration(array(), true);
391389
$browser1->setSessionStrategy($session_strategy)->attachToTestCase($test_case);

tests/aik099/PHPUnit/BrowserTestCaseTest.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,6 @@ public function testGetCollectCodeCoverageInformationSuccess()
250250
$this->assertTrue($test_case->getCollectCodeCoverageInformation());
251251
}
252252

253-
/**
254-
* Test description.
255-
*
256-
* @return void
257-
* @expectedException \RuntimeException
258-
*/
259-
public function testGetCollectCodeCoverageInformationFailure()
260-
{
261-
$this->getFixture()->getCollectCodeCoverageInformation();
262-
}
263-
264253
/**
265254
* Test description.
266255
*
@@ -292,17 +281,19 @@ public function testRunCreateResult()
292281
* Test description.
293282
*
294283
* @return void
295-
* @expectedException \RuntimeException
296284
*/
297285
public function testRunWithCoverageWithoutRemoteUrl()
298286
{
299287
/* @var $test_case BrowserTestCase */
300288
/* @var $session_strategy ISessionStrategy */
301-
list($test_case, $session_strategy) = $this->prepareForRun(array(), false);
289+
list($test_case, $session_strategy) = $this->prepareForRun(array());
302290
$test_case->setName('getTestId');
303291

292+
$code_coverage = m::mock('\\PHP_CodeCoverage');
293+
$code_coverage->shouldReceive('append')->with(m::mustBe(array()), $test_case)->once();
294+
304295
$result = $this->getTestResult($test_case, 1, true);
305-
$result->shouldReceive('getCodeCoverage')->once()->andReturn(m::mock('\\PHP_CodeCoverage'));
296+
$result->shouldReceive('getCodeCoverage')->once()->andReturn($code_coverage);
306297

307298
$test_id = $test_case->getTestId();
308299
$this->assertEmpty($test_id);

tests/aik099/PHPUnit/Fixture/ApiIntegrationFixture.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public function getBrowserAliases()
126126

127127
'browserName' => 'chrome',
128128
'desiredCapabilities' => array('version' => 28),
129+
'baseUrl' => 'http://www.google.com',
129130
),
130131
/*'browserstack' => array(
131132
'type' => 'browserstack',

tests/aik099/PHPUnit/Integration/DataProviderTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
class DataProviderTest extends BrowserTestCase
1818
{
1919

20+
/**
21+
* Browser list to be used in tests.
22+
*
23+
* @var array
24+
*/
25+
public static $browsers = array(
26+
array('alias' => 'saucelabs'),
27+
// array('alias' => 'browserstack'),
28+
);
29+
2030
public function sampleDataProvider()
2131
{
2232
return array(
@@ -45,4 +55,29 @@ protected function customMethod()
4555
return 5;
4656
}
4757

58+
/**
59+
* Gets browser configuration aliases.
60+
*
61+
* Allows to decouple actual test server connection details from test cases.
62+
*
63+
* @return array
64+
*/
65+
public function getBrowserAliases()
66+
{
67+
return array(
68+
'saucelabs' => array(
69+
'type' => 'saucelabs',
70+
'api_username' => getenv('SAUCE_USERNAME'),
71+
'api_key' => getenv('SAUCE_ACCESS_KEY'),
72+
73+
'browserName' => 'chrome',
74+
'desiredCapabilities' => array('version' => 28),
75+
'baseUrl' => 'http://www.google.com',
76+
),
77+
/*'browserstack' => array(
78+
'type' => 'browserstack',
79+
),*/
80+
);
81+
}
82+
4883
}

0 commit comments

Comments
 (0)