Ejemplo n.º 1
0
 public function testUserRelation()
 {
     $userPlace = new UserPlace();
     $user = new User();
     $place = new Place();
     $this->assertCount(0, $user->getUserPlaces(), 'collection is initialized on creation');
     $this->assertCount(0, $place->getUserPlaces(), 'collection is initialized on creation');
     $this->assertCount(0, $place->getUsers(), 'collection is initialized on creation');
     $userPlace->setUser($user);
     $userPlace->setPlace($place);
     $this->assertCount(1, $user->getUserPlaces(), 'user must be notified when userPlace is added');
     $this->assertSame($userPlace, $user->getUserPlaces()->first(), 'original userPlace can be retrieved from user');
     $this->assertCount(1, $place->getUserPlaces(), 'place must be notified when userPlace is added');
     $this->assertSame($userPlace, $place->getUserPlaces()->first(), 'original userPlace can be retrieved from place');
     $this->assertCount(1, $place->getUsers(), 'the user must now be the only one directly accessible');
     $this->assertSame($user, $place->getUsers()->first(), 'the user must be directly accessible');
 }