Skip to content

Commit

Permalink
Increasing test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Apr 12, 2014
1 parent b9e4cda commit c2fb55c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
10 changes: 0 additions & 10 deletions src/Jenssegers/Mongodb/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,4 @@ public function getForeignKey()
{
return $this->foreignKey;
}

/**
* Get the fully qualified "other key" for the relation.
*
* @return string
*/
public function getOtherKey()
{
return $this->otherKey;
}
}
21 changes: 21 additions & 0 deletions tests/RelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ public function testMorph()

$photo = Photo::first();
$this->assertEquals($photo->imageable->name, $user->name);

$user = User::with('photos')->find($user->_id);
$relations = $user->getRelations();
$this->assertTrue(array_key_exists('photos', $relations));
$this->assertEquals(1, $relations['photos']->count());
}

public function testEmbedsManySave()
Expand Down Expand Up @@ -579,4 +584,20 @@ public function testEmbedsManyFindOrContains()
$this->assertFalse($user->addresses()->contains('123'));
}

public function testEmbedsManyEagerLoading()
{
$user = User::create(array('name' => 'John Doe'));
$address1 = $user->addresses()->save(new Address(array('city' => 'New York')));
$address2 = $user->addresses()->save(new Address(array('city' => 'Paris')));

$user = User::find($user->id);
$relations = $user->getRelations();
$this->assertFalse(array_key_exists('addresses', $relations));

$user = User::with('addresses')->find($user->id);
$relations = $user->getRelations();
$this->assertTrue(array_key_exists('addresses', $relations));
$this->assertEquals(2, $relations['addresses']->count());
}

}
1 change: 0 additions & 1 deletion tests/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class User extends Eloquent implements UserInterface, RemindableInterface {

protected $collection = 'users';
protected $dates = array('birthday');
protected static $unguarded = true;

Expand Down

0 comments on commit c2fb55c

Please sign in to comment.