예제 #1
0
 public function testStaticFindOneReturnsModelInstance()
 {
     // the return value from the find
     $usersData = $this->getUserData();
     // mock connection methods
     $this->connectionMock->expects($this->once())->method('findOne')->with('users', array('email' => '*****@*****.**'))->willReturn($usersData);
     $user = new UserUnit();
     $user->load(array('email' => '*****@*****.**'));
     // assertions
     $this->assertEquals($user->name, $usersData['name']);
 }
예제 #2
0
 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));
 }
예제 #3
0
 public function testStaticFindOneReturnsModelInstance()
 {
     $collectionName = 'users';
     $query = array('email' => '*****@*****.**');
     $options = array();
     // the return value from the find
     $usersData = $this->getUserData();
     // mock connection methods
     $this->connectionMock->expects($this->once())->method('findOne')->with($collectionName, $query, $options)->willReturn($usersData);
     $result = UserUnit::findOne($query, $options);
     // assertions
     $this->assertTrue($result instanceof UserUnit);
     $this->assertEquals($result->name, $usersData['name']);
 }
예제 #4
0
 /**
  * @expectedException MartynBiz\Mongo\Exception\MissingId
  */
 public function testPushWhenIdMissingThrowException()
 {
     $user = new UserUnit();
     // $user->_id = new \MongoId();
     $this->connectionMock->expects($this->never())->method('update');
     $user->push(array('photo_ids' => 1), array('each' => false));
 }
예제 #5
0
 public function testToArrayDeep()
 {
     $louise = new UserUnit($this->getUserData(array('_id' => new MongoId('51b14c2de8e185801f000001'), 'name' => 'Louise', 'email' => '*****@*****.**')));
     $neil = new UserUnit($this->getUserData(array('_id' => new MongoId('51b14c2de8e185801f000001'), 'name' => 'Neil', 'email' => '*****@*****.**', 'friend' => $louise)));
     $martyn = new UserUnit($this->getUserData(array('friend' => $neil)));
     $this->connectionMock->method('findOne')->willReturn(array('name' => 'Neil'));
     $toArray = $martyn->toArray(1);
     // assertions
     $this->assertEquals('...', $toArray['friend']['friend']);
 }
예제 #6
0
 public function testToArrayWithArray()
 {
     $id = new \MongoId('51b14c2de8e185801f000000');
     $dbref = \MongoDBRef::create('users', '51b14c2de8e185801f000001');
     $user = new UserUnit(array('name' => 'Martyn'));
     $article = new ArticleUnit(array('title' => 'My article'));
     $values = array('friend' => array('Monty', $id, $dbref, $user), 'article' => $article, 'articles' => array($article));
     $this->connectionMock->method('findOne')->willReturn(array('name' => 'Neil'));
     $user = new UserUnit($values);
     $toArray = $user->toArray(2);
     // assertions
     $this->assertEquals('Monty', $toArray['friend'][0]);
     $this->assertEquals('51b14c2de8e185801f000000', $toArray['friend'][1]);
     $this->assertEquals('Neil', $toArray['friend'][2]['name']);
     $this->assertEquals('Martyn', $toArray['friend'][3]['name']);
     $this->assertEquals('My article', $toArray['article']['title']);
     $this->assertEquals('My article', $toArray['articles'][0]['title']);
 }