Permalink
Browse files

Change the assertions used for testing the success response of a query.

The change is necesarry to test the new defauls returned from
MongoCollections now that acknowledge writes is the new default.

Add a assertArrayHasKeyValue to do this, to make sure that 'ok' => 1.0
is set.
  • Loading branch information...
1 parent 681d51c commit 56a68f6200474ac274e53e61cb9fa4ea5319d620 @henrikbjorn henrikbjorn committed with jmikola Nov 29, 2012
@@ -391,7 +391,7 @@ public function testSave()
$coll = $this->getTestCollection($mockConnection, $mongoCollection, $mockDatabase);
$document = array();
$result = $coll->save($document, array());
- $this->assertEquals(true, $result);
+ $this->assertArrayHasKeyValue(array('ok' => 1.0), $result);
@jmikola
jmikola Jan 17, 2013 Member

This was never required because MongoCollection is mocked. Also, it was oddly passing even though $result was true.

}
public function testValidate()
@@ -459,6 +459,14 @@ private function getTestCollection(Connection $connection, MongoCollection $mong
$collection->setMongoCollection($mongoCollection);
return $collection;
}
+
+ private function assertArrayHasKeyValue($expected, $array, $message = '')
+ {
+ foreach ((array) $expected as $key => $value) {
+ $this->assertArrayHasKey($key, $expected, $message);
+ $this->assertEquals($value, $expected[$key], $message);
+ }
+ }
}
class TestLoggableCollectionStub extends LoggableCollection
@@ -190,7 +190,7 @@ public function testInsertQuery()
);
$this->assertEquals($expected, $qb->getNewObj());
$this->assertEquals(Query::TYPE_INSERT, $qb->getType());
- $this->assertTrue($qb->getQuery()->execute());
+ $this->assertArrayHasKeyValue(array('ok' => 1.0), $qb->getQuery()->execute());
}
public function testUpdateQuery()
@@ -209,7 +209,7 @@ public function testUpdateQuery()
$query = $qb->getQuery();
$this->assertEquals(Query::TYPE_UPDATE, $query->getType());
- $this->assertTrue($query->execute());
+ $this->assertArrayHasKeyValue(array('ok' => 1.0), $query->execute());
}
public function testRemoveQuery()
@@ -219,7 +219,7 @@ public function testRemoveQuery()
->field('username')->equals('jwage');
$this->assertEquals(Query::TYPE_REMOVE, $qb->getType());
- $this->assertTrue($qb->getQuery()->execute());
+ $this->assertArrayHasKeyValue(array('ok' => 1.0), $qb->getQuery()->execute());
}
/**
@@ -518,4 +518,12 @@ private function getTestQueryBuilder()
{
return $this->conn->selectCollection('db', 'users')->createQueryBuilder();
}
-}
+
+ private function assertArrayHasKeyValue($expected, $array, $message = '')
+ {
+ foreach ((array) $expected as $key => $value) {
+ $this->assertArrayHasKey($key, $expected, $message);
+ $this->assertEquals($value, $expected[$key], $message);
+ }
+ }
+}

0 comments on commit 56a68f6

Please sign in to comment.