public function addPost(Post $post) { if ($post->getAuthor() !== $this) { throw new DomainException('Author is not allowed'); } if ($this->hasPost($post)) { throw new DomainException('Post already added'); } $this->posts->add($post); }
/** * @return array */ public function postSetDataProvider() { $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $meta = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); $existing = (object) ['$existing' => true]; $removed = (object) ['$removed' => true]; $added = (object) ['$added' => true]; $collectionWithElements = new ArrayCollection([$added]); $cleanCollection = new PersistentCollection($em, $meta, new ArrayCollection()); $dirtyCollection = new PersistentCollection($em, $meta, new ArrayCollection([$existing, $removed])); $dirtyCollection->takeSnapshot(); $dirtyCollection->removeElement($removed); $dirtyCollection->add($added); return ['Initialization with empty value should not be broken' => ['$data' => null, '$expectedAddedData' => [], '$expectedRemovedData' => []], 'Empty collection given should set nothing' => ['$data' => new ArrayCollection(), '$expectedAddedData' => [], '$expectedRemovedData' => []], 'Array collection with elements given, should be set to added' => ['$data' => $collectionWithElements, '$expectedAddedData' => [$added], '$expectedRemovedData' => []], 'Clean persistent collection given, should set nothing' => ['$data' => $cleanCollection, '$expectedAddedData' => [], '$expectedRemovedData' => []], 'Persistent collection given, should set from diffs' => ['$data' => $dirtyCollection, '$expectedAddedData' => [$added], '$expectedRemovedData' => [$removed]]]; }
public function addPermissions(Collection $permissions) { foreach ($permissions as $permission) { $this->permissions->add($permission); } }
/** * @param TournamentPlayer $tournament * @return User */ public function addTournament(TournamentPlayer $tournament) : User { $this->tournaments->add($tournament); }
/** * Add a child. * * @param RoleInterface|string $child * @return RoleInterface */ public function addChild($child) { $this->children->add($child); return $this; }