/** * @test */ public function thatTicketCreatesWithDefaultStatusAndAttachments() { $branchId = 1; $reporterId = 2; $assigneeId = 3; $status = Status::NEW_ONE; $priority = Priority::PRIORITY_LOW; $source = Source::PHONE; $number = new TicketSequenceNumber(null); $reporter = $this->createReporter($reporterId); $ticket = new Ticket(UniqueId::generate(), $number, self::SUBJECT, self::DESCRIPTION, $this->createBranch(), $reporter, $this->createAssignee(), new Source($source), new Priority($priority), new Status($status)); $this->ticketBuilder->expects($this->once())->method('setSubject')->with(self::SUBJECT)->will($this->returnValue($this->ticketBuilder)); $this->ticketBuilder->expects($this->once())->method('setDescription')->with(self::DESCRIPTION)->will($this->returnValue($this->ticketBuilder)); $this->ticketBuilder->expects($this->once())->method('setBranchId')->with($branchId)->will($this->returnValue($this->ticketBuilder)); $this->ticketBuilder->expects($this->once())->method('setReporter')->with((string) $reporter)->will($this->returnValue($this->ticketBuilder)); $this->ticketBuilder->expects($this->once())->method('setAssignee')->with($assigneeId)->will($this->returnValue($this->ticketBuilder)); $this->ticketBuilder->expects($this->once())->method('setSource')->with($source)->will($this->returnValue($this->ticketBuilder)); $this->ticketBuilder->expects($this->once())->method('setPriority')->with($priority)->will($this->returnValue($this->ticketBuilder)); $this->ticketBuilder->expects($this->once())->method('setStatus')->with(null)->will($this->returnValue($this->ticketBuilder)); $this->ticketBuilder->expects($this->once())->method('build')->will($this->returnValue($ticket)); $attachmentInputs = $this->attachmentInputs(); $this->attachmentManager->expects($this->exactly(count($attachmentInputs)))->method('createNewAttachment')->with($this->isType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING), $this->isType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING), $this->equalTo($ticket)); $this->doctrineRegistry->expects($this->any())->method('getManager')->will($this->returnValue($this->em)); $this->em->expects($this->once())->method('persist')->with($this->equalTo($ticket)); $this->em->expects($this->once())->method('flush'); $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('CREATE'), $this->equalTo('Entity:DiamanteDeskBundle:Ticket'))->will($this->returnValue(true)); $command = new CreateTicketCommand(); $command->branch = $branchId; $command->subject = self::SUBJECT; $command->description = self::DESCRIPTION; $command->reporter = (string) $reporter; $command->assignee = $assigneeId; $command->priority = $priority; $command->source = $source; $command->status = null; $command->attachmentsInput = $attachmentInputs; $this->ticketService->createTicket($command); }
/** * Create Ticket * * @ApiDoc( * description="Create ticket", * uri="/tickets.{_format}", * method="POST", * resource=true, * statusCodes={ * 201="Returned when successful", * 403="Returned when the user is not authorized to create ticket" * } * ) * * @param CreateTicketCommand $command * @return \Diamante\DeskBundle\Model\Ticket\Ticket */ public function createTicket(CreateTicketCommand $command) { if (0 === $command->branch) { $command->branch = (int) $this->configManager->get('diamante_email_processing.default_branch'); } if (empty($command->assignee)) { $branch = $this->branchRepository->get((int) $command->branch); if ($branch) { $command->assignee = $branch->getDefaultAssigneeId(); } } $this->prepareAttachmentInput($command); return parent::createTicket($command); }
/** * Create Ticket * * @ApiDoc( * description="Create ticket", * uri="/tickets.{_format}", * method="POST", * resource=true, * statusCodes={ * 201="Returned when successful", * 403="Returned when the user is not authorized to create ticket" * } * ) * * @param CreateTicketCommand $command * @return \Diamante\DeskBundle\Model\Ticket\Ticket */ public function createTicket(CreateTicketCommand $command) { if (empty($command->assignee)) { $branch = $this->branchRepository->get((int) $command->branch); if ($branch) { $command->assignee = $branch->getDefaultAssigneeId(); } } $this->prepareAttachmentInput($command); return parent::createTicket($command); }