public function testSaveConvertsMongoIteratorObjectToArrayOfDBRefs() { // the return value from the find $tagsData = array($this->getTagData(), $this->getTagData(array('name' => 'Art', 'slug' => 'art'))); // mock method to return mock collection $this->connectionMock->expects($this->once())->method('find')->with('tags', array(), array())->willReturn($tagsData); $this->connectionMock->expects($this->once())->method('insert')->with('articles', array('tags' => array(\MongoDBRef::create('tags', $tagsData[0]['_id']), \MongoDBRef::create('tags', $tagsData[1]['_id'])), 'created_at' => new \MongoDate(time())))->willReturn($tagsData); // first, fetch the tags $tags = TagUnit::find(); // next, set the article's tags property and save // when saving, an array of dbrefs should be given $article = new ArticleUnit(); $article->tags = $tags; $article->save(); }
public function testPushWithArrayValueAndHasMongoIdConvertsToPushUpdate() { // the return value from the find $article = ArticleUnit::findOne(); // attach $article->push(array('photo_ids' => array(1, 2, 3))); $this->assertTrue(isset($article->photo_ids)); $this->assertEquals(3, count($article->photo_ids)); }