Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updating MongoDB test to use mock connections for all assertions.

  • Loading branch information...
commit c28ba6dd6e8531fd628b701336f010b03ec67249 1 parent da1a481
@nateabele nateabele authored
View
12 tests/cases/data/ConnectionsTest.php
@@ -141,17 +141,15 @@ public function testGetNullAdapter() {
}
protected function _canConnect($host, $port) {
- $this->expectException();
- $this->expectException();
+ $success = false;
+ set_error_handler(function() {});
if ($conn = fsockopen($host, $port)) {
- array_pop($this->_expected);
- array_pop($this->_expected);
fclose($conn);
-
- return true;
+ $success = true;
}
- return false;
+ restore_error_handler();
+ return $success;
}
}
View
24 tests/cases/data/source/MongoDbTest.php
@@ -57,22 +57,21 @@ class MongoDbTest extends \lithium\test\Unit {
public function skip() {
$this->skipIf(!MongoDb::enabled(), 'The `MongoDb` class is not enabled.');
-
- $db = new MongoDb($this->_testConfig);
- $message = "`{$this->_testConfig['database']}` database or connection unavailable";
- $this->skipIf(!$db->isConnected(array('autoConnect' => true)), $message);
}
public function setUp() {
$model = $this->_model;
$this->db = new MongoDb($this->_testConfig);
- $this->db->server = (object) array('connected' => true);
+ $this->db->server = new MockMongoConnection();
$this->db->connection = new MockMongoConnection();
+ $this->db->server->connected = true;
$model::config(array('meta' => array('key' => '_id')));
$model::$connection = $this->db;
- $this->query = new Query(compact('model') + array('entity' => new Document(compact('model'))));
+ $this->query = new Query(compact('model') + array(
+ 'entity' => new Document(compact('model'))
+ ));
}
public function tearDown() {
@@ -93,13 +92,6 @@ public function testGoodConnectionBadDatabase() {
$db = new MongoDb(array('database' => null, 'autoConnnect' => false));
}
- public function testGoodConnectionGoodDatabase() {
- $db = new MongoDb(array('autoConnect' => false) + $this->_testConfig);
- $this->assertFalse($db->isConnected());
- $this->assertTrue($db->connect());
- $this->assertTrue($db->isConnected());
- }
-
public function testSources() {
$this->db->connection->results = array(array());
$this->assertEqual(array(), $this->db->sources());
@@ -424,11 +416,7 @@ public function testEnabled() {
}
public function testArbitraryMethodCalls() {
- $db = new MongoDb($config = $this->_testConfig);
- $result = $db->__toString();
- $this->assertTrue(strpos($result, $config['host']) !== false);
- $this->assertTrue(strpos($result, $config['port']) !== false);
- $this->assertTrue(is_array($db->listDBs()));
+ $this->assertTrue(is_array($this->db->listDBs()));
}
public function testDocumentSorting() {
View
4 tests/mocks/data/source/MockMongoConnection.php
@@ -27,6 +27,10 @@ public function &__get($property) {
return $this;
}
+ public function listDBs() {
+ return array();
+ }
+
public function insert(array &$data, array $options = array()) {
$data['_id'] = new MongoId();
return $this->_record(__FUNCTION__, compact('data', 'options'));
Please sign in to comment.
Something went wrong with that request. Please try again.