public function testDeleteTicketByKey()
 {
     $this->ticket->expects($this->any())->method('getAttachments')->will($this->returnValue(array($this->attachment())));
     $this->ticketRepository->expects($this->once())->method('getByTicketKey')->with(new TicketKey('DT', 1))->will($this->returnValue($this->ticket));
     $this->ticketRepository->expects($this->once())->method('remove')->with($this->equalTo($this->ticket));
     $this->attachmentManager->expects($this->exactly(count($this->ticket->getAttachments())))->method('deleteAttachment')->with($this->isInstanceOf('\\Diamante\\DeskBundle\\Model\\Attachment\\Attachment'));
     $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('DELETE'), $this->equalTo($this->ticket))->will($this->returnValue(true));
     $this->ticketService->deleteTicketByKey(self::DUMMY_TICKET_KEY);
 }
 /**
  * @test
  */
 public function thatCommentCreatesWithAttachments()
 {
     $author = $this->createAuthor();
     $ticket = $this->createDummyTicket();
     $this->messageReferenceRepository->expects($this->once())->method('getReferenceByMessageId')->with($this->equalTo(self::DUMMY_MESSAGE_ID))->will($this->returnValue($this->messageReference));
     $this->messageReference->expects($this->once())->method('getTicket')->will($this->returnValue($ticket));
     $this->commentFactory->expects($this->once())->method('create')->with($this->equalTo(self::DUMMY_COMMENT_CONTENT), $this->equalTo($ticket), $this->equalTo($author))->will($this->returnValue($this->comment));
     $this->attachmentManager->expects($this->once())->method('createNewAttachment')->with($this->equalTo(self::DUMMY_FILENAME), $this->equalTo(self::DUMMY_FILE_CONTENT), $this->equalTo($this->comment));
     $this->ticketRepository->expects($this->once())->method('store')->with($this->equalTo($ticket));
     $this->messageReferenceService->createCommentForTicket(self::DUMMY_COMMENT_CONTENT, (string) $author, self::DUMMY_MESSAGE_ID, $this->attachments());
     $this->assertCount(1, $ticket->getComments());
     $this->assertEquals($this->comment, $ticket->getComments()->get(0));
 }
 /**
  * @test
  */
 public function thatAttachmentRemovesFromComment()
 {
     $attachment = new Attachment(new File('some/path/file.ext'));
     $this->commentRepository->expects($this->once())->method('get')->with($this->equalTo(self::DUMMY_COMMENT_ID))->will($this->returnValue($this->comment));
     $this->comment->expects($this->once())->method('getAttachment')->with($this->equalTo(1))->will($this->returnValue($attachment));
     $this->comment->expects($this->once())->method('removeAttachment')->with($this->equalTo($attachment));
     $this->attachmentManager->expects($this->once())->method('deleteAttachment')->with($this->equalTo($attachment));
     $this->commentRepository->expects($this->once())->method('store')->with($this->equalTo($this->comment));
     $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('EDIT'), $this->equalTo($this->comment))->will($this->returnValue(true));
     $removeCommentAttachmentCommand = new RemoveCommentAttachmentCommand();
     $removeCommentAttachmentCommand->attachmentId = 1;
     $removeCommentAttachmentCommand->commentId = self::DUMMY_COMMENT_ID;
     $this->service->removeAttachmentFromComment($removeCommentAttachmentCommand);
 }