diff --git a/docs/remote-code-coverage.rst b/docs/remote-code-coverage.rst index 62dcd63..9a12e81 100644 --- a/docs/remote-code-coverage.rst +++ b/docs/remote-code-coverage.rst @@ -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 diff --git a/library/aik099/PHPUnit/BrowserConfiguration/BrowserConfiguration.php b/library/aik099/PHPUnit/BrowserConfiguration/BrowserConfiguration.php index 3fdd2f1..815a612 100644 --- a/library/aik099/PHPUnit/BrowserConfiguration/BrowserConfiguration.php +++ b/library/aik099/PHPUnit/BrowserConfiguration/BrowserConfiguration.php @@ -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; diff --git a/library/aik099/PHPUnit/BrowserTestCase.php b/library/aik099/PHPUnit/BrowserTestCase.php index dd85e09..2c77393 100644 --- a/library/aik099/PHPUnit/BrowserTestCase.php +++ b/library/aik099/PHPUnit/BrowserTestCase.php @@ -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(); } /** diff --git a/tests/aik099/PHPUnit/BrowserConfiguration/ApiBrowserConfigurationTestCase.php b/tests/aik099/PHPUnit/BrowserConfiguration/ApiBrowserConfigurationTestCase.php index 94a6563..b512ba5 100644 --- a/tests/aik099/PHPUnit/BrowserConfiguration/ApiBrowserConfigurationTestCase.php +++ b/tests/aik099/PHPUnit/BrowserConfiguration/ApiBrowserConfigurationTestCase.php @@ -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); diff --git a/tests/aik099/PHPUnit/BrowserConfiguration/BrowserConfigurationTest.php b/tests/aik099/PHPUnit/BrowserConfiguration/BrowserConfigurationTest.php index 9bba090..e5f729d 100644 --- a/tests/aik099/PHPUnit/BrowserConfiguration/BrowserConfigurationTest.php +++ b/tests/aik099/PHPUnit/BrowserConfiguration/BrowserConfigurationTest.php @@ -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()); @@ -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); diff --git a/tests/aik099/PHPUnit/BrowserTestCaseTest.php b/tests/aik099/PHPUnit/BrowserTestCaseTest.php index ea57179..2cb98b7 100644 --- a/tests/aik099/PHPUnit/BrowserTestCaseTest.php +++ b/tests/aik099/PHPUnit/BrowserTestCaseTest.php @@ -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. * @@ -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); diff --git a/tests/aik099/PHPUnit/Fixture/ApiIntegrationFixture.php b/tests/aik099/PHPUnit/Fixture/ApiIntegrationFixture.php index ab58b80..39d9640 100644 --- a/tests/aik099/PHPUnit/Fixture/ApiIntegrationFixture.php +++ b/tests/aik099/PHPUnit/Fixture/ApiIntegrationFixture.php @@ -126,6 +126,7 @@ public function getBrowserAliases() 'browserName' => 'chrome', 'desiredCapabilities' => array('version' => 28), + 'baseUrl' => 'http://www.google.com', ), /*'browserstack' => array( 'type' => 'browserstack', diff --git a/tests/aik099/PHPUnit/Integration/DataProviderTest.php b/tests/aik099/PHPUnit/Integration/DataProviderTest.php index 18c98ec..c8891cc 100644 --- a/tests/aik099/PHPUnit/Integration/DataProviderTest.php +++ b/tests/aik099/PHPUnit/Integration/DataProviderTest.php @@ -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( @@ -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', + ),*/ + ); + } + }