public function removeByUserId(UserId $userId) { $members = $this->toArray(); foreach ($members as $member) { if ($userId->equals($member->userId())) { $this->remove($member); return; } } throw new CollectionElementAlreadyRemovedException(); }
public function owner(UserId $userId) { foreach ($this->owners() as $owner) { if ($userId->equals($owner->userId())) { return $owner; } } }
function it_does_not_remove_by_user_id(MemberStub $member, UserId $userId, UserId $userId2) { $member->userId()->shouldBeCalled()->willReturn($userId2); $userId->equals($userId2)->shouldBeCalled()->willReturn(false); $this->shouldThrow(CollectionElementAlreadyRemovedException::class)->duringRemoveByUserId($userId); }
function it_does_not_gets_owner(UserId $userId, UserId $userId2) { $userId2->equals($userId)->shouldBeCalled()->willReturn(false); $this->owner($userId2)->shouldReturn(null); }