Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't enable remote code coverage without a collection URL #125

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions library/aik099/PHPUnit/BrowserTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ protected function tearDownTest()
*/
public function getCollectCodeCoverageInformation()
{
if ( !$this->_remoteCoverageScriptUrl ) {
return false;
}

$result = $this->getTestResultObject();

if ( !is_object($result) ) {
Expand Down
37 changes: 23 additions & 14 deletions tests/aik099/PHPUnit/BrowserTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ protected function getBrowser($times)
}

/**
* Test description.
* @param string $remote_coverage_script_url Remote coverage script URL.
*
* @return void
* @dataProvider getCollectCodeCoverageInformationSuccessDataProvider
*/
public function testGetCollectCodeCoverageInformationSuccess()
public function testGetCollectCodeCoverageInformationSuccess($remote_coverage_script_url)
{
$test_case = $this->getFixture();

Expand All @@ -298,7 +298,22 @@ public function testGetCollectCodeCoverageInformationSuccess()
$test_result->setCodeCoverage($code_coverage);
$test_case->setTestResultObject($test_result);

$this->assertTrue($test_case->getCollectCodeCoverageInformation());
// Failed.
if ( $remote_coverage_script_url ) {
$test_case->setRemoteCoverageScriptUrl($remote_coverage_script_url);
$this->assertTrue($test_case->getCollectCodeCoverageInformation());
}
else {
$this->assertFalse($test_case->getCollectCodeCoverageInformation());
}
}

public function getCollectCodeCoverageInformationSuccessDataProvider()
{
return array(
'with remote coverage url' => array('http://localhost/'),
'without remote coverage url' => array(''),
);
}

/**
Expand Down Expand Up @@ -360,18 +375,12 @@ public function testRunWithCoverageWithoutRemoteUrl()
));
$result->setCodeCoverage($code_coverage);

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

$browser = $test_case->getBrowser();
$browser->shouldReceive('getBaseUrl')->once()->andReturn('A');
$browser->shouldReceive('getBaseUrl')->never();

$session = m::mock(Session::class);
$session->shouldReceive('visit')->with('A')->once();
$session->shouldReceive('setCookie')->with(RemoteCoverageTool::TEST_ID_VARIABLE, null)->once();
$session->shouldReceive('setCookie')->with(RemoteCoverageTool::TEST_ID_VARIABLE, m::not(''))->once();

$session_strategy->shouldReceive('session')->once()->andReturn($session);
$session_strategy->shouldReceive('session')->never();

$test_case->run($result);

Expand Down Expand Up @@ -401,7 +410,7 @@ public function testRunWithCoverageWithoutRemoteUrl()
$this->assertEquals($expected_coverage, $actual_coverage);
}

$this->assertNotEmpty($test_case->getTestId());
$this->assertEmpty($test_case->getTestId());
}

/**
Expand Down
9 changes: 0 additions & 9 deletions tests/aik099/PHPUnit/Fixture/ApiIntegrationFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,6 @@ public function verifyRemoteAPICalls()
}
}

/**
* @inheritDoc
*/
public function getCollectCodeCoverageInformation()
{
// FIXME: Workaround for https://github.com/minkphp/phpunit-mink/issues/35 bug.
return false;
}

/**
* Test description.
*
Expand Down
12 changes: 0 additions & 12 deletions tests/aik099/PHPUnit/Integration/BrowserStackAwareTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ protected function setUpTest()
}
}

/**
* Whatever or not code coverage information should be gathered.
*
* @return boolean
* @throws \RuntimeException When used before test is started.
*/
public function getCollectCodeCoverageInformation()
{
// FIXME: Workaround for https://github.com/minkphp/phpunit-mink/issues/35 bug.
return false;
}

/**
* Gets browser configuration aliases.
*
Expand Down
Loading