public function testCallbackPerformsDeleteQuery() { $fileId = (string) new \MongoId(); $entity = new Attachment(); $entity->setId($fileId); $q = $this->getMockBuilder(Query::class)->disableOriginalConstructor()->setMethods(['execute'])->getMock(); $q->expects($this->once())->method('execute'); $qb = $this->getMockBuilder(Builder::class)->disableOriginalConstructor()->setMethods(['update', 'multiple', 'field', 'equals', 'pull', 'getQuery'])->getMock(); $qb->expects($this->once())->method('update')->will($this->returnSelf()); $qb->expects($this->once())->method('multiple')->with(true)->will($this->returnSelf()); $qb->expects($this->once())->method('field')->with('attachments')->will($this->returnSelf()); $qb->expects($this->once())->method('equals')->with($fileId)->will($this->returnSelf()); $qb->expects($this->once())->method('pull')->with($fileId)->will($this->returnSelf()); $qb->expects($this->once())->method('getQuery')->willReturn($q); $dm = $this->getMockBuilder(DocumentManager::class)->disableOriginalConstructor()->setMethods(['createQueryBuilder'])->getMock(); $dm->expects($this->once())->method('createQueryBuilder')->with('Cv\\Entity\\Cv')->willReturn($qb); $args = $this->getMockBuilder(LifecycleEventArgs::class)->disableOriginalConstructor()->setMethods(['getDocument', 'getDocumentManager'])->getMock(); $args->expects($this->once())->method('getDocument')->willReturn($entity); $args->expects($this->once())->method('getDocumentManager')->willReturn($dm); $this->target->postRemoveEntity($args); }
private function setupSetterGetterTarget() { $target = new Attachment(); $target->setId('test')->setName('name'); return $target; }