public function testFindWithMongoInstanceQueriesWithDBRef() { // =========================== // set up $friend and $user with _ids (required for dbref) $friendData = $this->getUserData(array('name' => 'Neil McInnes', 'first_name' => 'Neil', 'last_name' => 'McInnes', 'email' => '*****@*****.**')); $friend = new UserUnit($friendData); $friend->_id = $friendData['_id']; $userData = $this->getUserData(array('friend' => $friend->getDBRef())); $user = new UserUnit($userData); $user->_id = $userData['_id']; // ======================= // mock connection methods $this->connectionMock->expects($this->once())->method('findOne')->with('users', array('friend' => $friend->getDBRef()), array())->willReturn($user); $result = $this->user->findOne(array('friend' => $friend)); }
public function testPushWithMongoIteratorValueConvertsToPushUpdateWithDBRef() { // the return value from the find $user = new UserUnit(); $user->_id = new \MongoId(); $friend = new UserUnit(); $friend->_id = new \MongoId(); $friends = new MongoIterator(array($friend)); $this->connectionMock->expects($this->at(0))->method('update')->with('users', array('_id' => $user->_id), array('$push' => array('friends' => array('$each' => array($friend->getDBRef())))), array()); $this->connectionMock->expects($this->at(1))->method('update')->with('users', array('_id' => $user->_id), array('$set' => array('updated_at' => new \MongoDate(time()))), array()); // attach $user->push(array('friends' => $friends)); }
public function testGetDBRefReturnsValidRef() { $userData = $this->getUserData(); $user = new UserUnit($userData); $user->_id = $userData['_id']; // not on whitelist $dbref = $user->getDBRef(); $this->assertTrue(MongoDBRef::isRef($dbref)); }