Ejemplo n.º 1
0
    public function testCreateSendsValidXml()
    {
        $mock = $this->getMock('CodebaseHq\\Api', array('api', 'getProject'));
        $mock->expects($this->once())->method('getProject')->will($this->returnValue('project'));
        $mock->expects($this->once())->method('api')->with('/project/tickets/199/notes', 'POST', '<ticket-note>
    <content>Lorem Ipsum</content>
    <time-added></time-added>
    <changes></changes>
</ticket-note>')->will($this->returnValue('<ticket-note>
    <content>Lorem Ipsum</content>
    <time-added></time-added>
    <changes></changes>
</ticket-note>'));
        $repo = new TicketNoteRepo($mock);
        $ticket = new Entity\Ticket();
        $ticket->setId(199);
        $repo->create($ticket, 'Lorem Ipsum');
    }
Ejemplo n.º 2
0
 /**
  * @param int|TicketEntity $ticket
  * @param string $content
  * @param array $changes
  * @param string $timeAdded
  * @return \CodebaseHq\Entity\TicketNote
  */
 public function create($ticket, $content = '', $changes = array(), $timeAdded = '')
 {
     if ($ticket instanceof TicketEntity) {
         $ticketId = $ticket->getId();
     } else {
         $ticketId = $ticket;
     }
     $xml = "<ticket-note>\n    <content>{$content}</content>\n    <time-added>{$timeAdded}</time-added>\n    <changes>";
     foreach ($changes as $change => $value) {
         $xml .= "<{$change}>{$value}</{$change}>";
     }
     $xml .= "</changes>\n</ticket-note>";
     $project = $this->api->getProject();
     $xmlElement = new SimpleXMLElement($this->api->api("/{$project}/tickets/{$ticketId}/notes", 'POST', $xml));
     $hydrator = new TicketNoteHydrator();
     $ticket = new TicketNoteEntity();
     $hydrator->hydrateXml($xmlElement, $ticket);
     return $ticket;
 }
Ejemplo n.º 3
0
 public function hydrateXml(SimpleXMLElement $xml, Entity\Ticket $object)
 {
     $object->setId((int) $xml->{'ticket-id'});
     $object->setSummary((string) $xml->{'summary'});
     $object->setTicketType((string) $xml->{'ticket-type'});
     $object->setReporterId((int) $xml->{'reporter-id'});
     $object->setReporter((string) $xml->{'reporter'});
     $object->setAssigneeId((int) $xml->{'assignee-id'});
     $object->setAssignee((string) $xml->{'assignee'});
     $object->setUpdatedAt(new DateTime((string) $xml->{'updated-at'}));
     $object->setCreatedAt(new DateTime((string) $xml->{'created-at'}));
     $object->setProjectId((int) $xml->{'project-id'});
     $object->setTags((string) $xml->{'tags'});
     $object->setEstimatedTime((int) $xml->{'estimated-time'});
     if ($xml->category) {
         $categoryHydrator = new CategoryHydrator();
         $category = new Entity\Category();
         $categoryHydrator->hydrateXml($xml->category, $category);
         $object->setCategory($category);
     }
     if ($xml->status) {
         $statusHydrator = new StatusHydrator();
         $category = new Entity\Status();
         $statusHydrator->hydrateXml($xml->status, $category);
         $object->setStatus($category);
     }
     if ($xml->priority) {
         $statusHydrator = new PriorityHydrator();
         $category = new Entity\Priority();
         $statusHydrator->hydrateXml($xml->priority, $category);
         $object->setPriority($category);
     }
 }