Skip to content
Permalink
Browse files

Attempt to fix failures in travisci.

Network tests have recently started failing, make those skip conditions
instead. Convert SocketExceptions in Xml::build() into XmlExceptions.
This is the documented behavior so we should try to honour that.
  • Loading branch information...
markstory committed Feb 20, 2013
1 parent fd7158c commit 341c0d17f0f3d5bd7488edb9c8153d276d520831
Showing with 50 additions and 28 deletions.
  1. +42 −24 lib/Cake/Test/Case/Network/CakeSocketTest.php
  2. +8 −4 lib/Cake/Utility/Xml.php
@@ -87,16 +87,22 @@ public function testSocketConnection() {
$this->assertFalse($this->Socket->connected);
$this->Socket->disconnect();
$this->assertFalse($this->Socket->connected);
$this->Socket->connect();
$this->assertTrue($this->Socket->connected);
$this->Socket->connect();
$this->assertTrue($this->Socket->connected);
$this->Socket->disconnect();
$config = array('persistent' => true);
$this->Socket = new CakeSocket($config);
$this->Socket->connect();
$this->assertTrue($this->Socket->connected);
try {
$this->Socket->connect();
$this->assertTrue($this->Socket->connected);
$this->Socket->connect();
$this->assertTrue($this->Socket->connected);
$this->Socket->disconnect();
$config = array('persistent' => true);
$this->Socket = new CakeSocket($config);
$this->Socket->connect();
$this->assertTrue($this->Socket->connected);
} catch (SocketException $e) {
$connectionRefused = stripos($e->getMessage(), 'Connection refused') !== false;
$this->skipIf($connectionRefused, 'Cannot test network, skipping.');
throw $e;
}
}
/**
@@ -129,19 +135,25 @@ public function testInvalidConnection($data) {
* @return void
*/
public function testSocketHost() {
$this->Socket = new CakeSocket();
$this->Socket->connect();
$this->assertEquals('127.0.0.1', $this->Socket->address());
$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host());
$this->assertEquals(null, $this->Socket->lastError());
$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses()));
$this->Socket = new CakeSocket(array('host' => '127.0.0.1'));
$this->Socket->connect();
$this->assertEquals('127.0.0.1', $this->Socket->address());
$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host());
$this->assertEquals(null, $this->Socket->lastError());
$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses()));
try {
$this->Socket = new CakeSocket();
$this->Socket->connect();
$this->assertEquals('127.0.0.1', $this->Socket->address());
$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host());
$this->assertEquals(null, $this->Socket->lastError());
$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses()));
$this->Socket = new CakeSocket(array('host' => '127.0.0.1'));
$this->Socket->connect();
$this->assertEquals('127.0.0.1', $this->Socket->address());
$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host());
$this->assertEquals(null, $this->Socket->lastError());
$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses()));
} catch (SocketException $e) {
$connectionRefused = stripos($e->getMessage(), 'Connection refused') !== false;
$this->skipIf($connectionRefused, 'Cannot test network, skipping.');
throw $e;
}
}
/**
@@ -256,7 +268,13 @@ protected function _connectSocketToSslTls() {
$this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.');
$configSslTls = array('host' => 'smtp.gmail.com', 'port' => 465, 'timeout' => 5);
$this->Socket = new CakeSocket($configSslTls);
$this->Socket->connect();
try {
$this->Socket->connect();
} catch (SocketException $e) {
$connectionRefused = stripos($e->getMessage(), 'Connection refused') !== false;
$this->skipIf($connectionRefused, 'Cannot test network, skipping.');
throw $e;
}
}
/**
@@ -102,12 +102,16 @@ public static function build($input, $options = array()) {
} elseif (file_exists($input)) {
return self::_loadXml(file_get_contents($input), $options);
} elseif (strpos($input, 'http://') === 0 || strpos($input, 'https://') === 0) {
$socket = new HttpSocket(array('request' => array('redirect' => 10)));
$response = $socket->get($input);
if (!$response->isOk()) {
try {
$socket = new HttpSocket(array('request' => array('redirect' => 10)));
$response = $socket->get($input);
if (!$response->isOk()) {
throw new XmlException(__d('cake_dev', 'XML cannot be read.'));
}
return self::_loadXml($response->body, $options);
} catch (SocketException $e) {
throw new XmlException(__d('cake_dev', 'XML cannot be read.'));
}
return self::_loadXml($response->body, $options);
} elseif (!is_string($input)) {
throw new XmlException(__d('cake_dev', 'Invalid input.'));
}

0 comments on commit 341c0d1

Please sign in to comment.
You can’t perform that action at this time.