Skip to content
This repository has been archived by the owner on Feb 4, 2018. It is now read-only.

Commit

Permalink
# Mark external tests as skipped when the network is not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelpichler committed Jun 3, 2010
1 parent 4b09542 commit e677d6e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 30 deletions.
20 changes: 10 additions & 10 deletions tests/Tasks/CheckoutTaskTest.php
Expand Up @@ -69,6 +69,16 @@ class phpucCheckoutTaskTest extends phpucAbstractTaskTest
*/
protected function setUp()
{
$socket = @fsockopen( 'xplib.de', 80, $errno, $errstr, 1);
if ( is_resource( $socket ) )
{
fclose( $socket );
}
else
{
$this->markTestSkipped( 'Cannot connect to pserver.' );
}

$this->cwd = getcwd();

parent::setUp();
Expand Down Expand Up @@ -118,16 +128,6 @@ public function testSubversionCheckout()
*/
public function testCvsCheckout()
{
$socket = @fsockopen( 'xplib.de', 2401, $errno, $errstr, 1);
if ( is_resource( $socket ) )
{
fclose( $socket );
}
else
{
$this->markTestSkipped( 'Cannot connect to pserver.' );
}

$this->prepareArgv(
array(
'project',
Expand Down
30 changes: 24 additions & 6 deletions tests/VersionControl/AbstractCheckoutTest.php
Expand Up @@ -65,16 +65,12 @@ abstract class phpucAbstractCheckoutTest extends phpucAbstractTest
* property.
*
* @return void
* @expectedException OutOfRangeException
*/
public function testGetterUnknownPropertyFail()
{
$this->setExpectedException(
'OutOfRangeException',
'Unknown or writonly property $phpuc.'
);

$checkout = $this->createCheckout();
echo $checkout->phpuc;
$property = $checkout->phpuc;
}

/**
Expand All @@ -93,6 +89,28 @@ public function testSetterUnknownPropertyFail()
$checkout = $this->createCheckout();
$checkout->phpuc = true;
}

/**
* Marks a test case as skipped when the remote host is not available.
*
* @param string $remote The remote host name + port.
*
* @return void
*/
protected function markTestSkippedWhenRemoteHostNotAvailable( $remote )
{
$url = parse_url( $remote );

$socket = @fsockopen( $url['host'], $url['port'], $errno, $errstr, 1);
if ( is_resource( $socket ) )
{
fclose( $socket );
}
else
{
$this->markTestSkipped( 'Cannot connect to host ' . $remote . '.' );
}
}

/**
* Test factory method.
Expand Down
10 changes: 1 addition & 9 deletions tests/VersionControl/CvsCheckoutTest.php
Expand Up @@ -104,15 +104,7 @@ protected function tearDown()
*/
public function testPServerCheckout()
{
$socket = @fsockopen( 'xplib.de', 2401, $errno, $errstr, 1);
if ( is_resource( $socket ) )
{
fclose( $socket );
}
else
{
$this->markTestSkipped( 'Cannot connect to pserver.' );
}
$this->markTestSkippedWhenRemoteHostNotAvailable( 'xplib.de:2401' );

$destination = PHPUC_TEST_DIR . '/source';
$checkFile1 = $destination . '/pdepend.php';
Expand Down
2 changes: 2 additions & 0 deletions tests/VersionControl/GitCheckoutTest.php
Expand Up @@ -104,6 +104,8 @@ protected function tearDown()
*/
public function testGitCheckoutNoLogin()
{
$this->markTestSkippedWhenRemoteHostNotAvailable( 'github.com:80' );

$checkFile = PHPUC_TEST_DIR . '/source/src/PhpUnderControl.php';

$this->assertFileNotExists( $checkFile );
Expand Down
11 changes: 6 additions & 5 deletions tests/VersionControl/SubversionCheckoutTest.php
Expand Up @@ -77,11 +77,6 @@ protected function setUp()
{
parent::setUp();

if ( @file_get_contents( 'http://phpundercontrol.org' ) === false )
{
$this->markTestSkipped( 'Cannot connect to external host.' );
}

phpucFileUtil::setOS();
phpucFileUtil::setPaths();

Expand Down Expand Up @@ -109,6 +104,8 @@ protected function tearDown()
*/
public function testSvnCheckoutNoLogin()
{
$this->markTestSkippedWhenRemoteHostNotAvailable( 'xplib.de:80' );

$destination = PHPUC_TEST_DIR . '/source';
$checkFile1 = $destination . '/pdepend.php';
$checkFile2 = $destination . '/PHP/Depend.php';
Expand Down Expand Up @@ -146,6 +143,8 @@ public function testSvnCheckoutInvalidUrlFail()
*/
public function testSvnCheckoutWithLogin()
{
$this->markTestSkippedWhenRemoteHostNotAvailable( 'xplib.de:80' );

$destination = PHPUC_TEST_DIR . '/source';
$checkFile1 = $destination . '/Commands/AbstractCommand.php';
$checkFile2 = $destination . '/Commands/InstallCommand.php';
Expand Down Expand Up @@ -203,6 +202,8 @@ public function testSvnCheckoutWithInvalidPasswordFail()
*/
public function testHttpCheckout()
{
$this->markTestSkippedWhenRemoteHostNotAvailable( 'xplib.de:80' );

$destination = PHPUC_TEST_DIR . '/source';
$checkFile1 = $destination . '/pdepend.php';
$checkFile2 = $destination . '/PHP/Depend.php';
Expand Down

0 comments on commit e677d6e

Please sign in to comment.