public function testCreatorShouldBeGivenRights() { $place1 = new Place(); $this->assertEmpty($place1->getUsers(), 'new place without current user should have no users'); $user = new User(); User::setCurrentUser($user); $place2 = new Place(); $this->assertCount(1, $place2->getUsers(), 'new place with current user should have a user'); $this->assertSame($user, $place2->getUsers()[0], 'new place with current user should have a user'); }
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'); }