From dc0c8a351b3747d659b2fb38194976cf82dd5788 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Mon, 13 Feb 2017 12:52:43 -0500 Subject: [PATCH] I think I finished the ticket creator --- api/BusinessLogic/Tickets/TicketCreator.php | 5 ++-- .../Tickets/TicketGatewayGeneratedFields.php | 15 ++++++++++++ api/DataAccess/Tickets/TicketGateway.php | 14 +++++++++-- .../CreateTicketForCustomerTest.php | 23 ++++++++++++++++++- 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 api/BusinessLogic/Tickets/TicketGatewayGeneratedFields.php diff --git a/api/BusinessLogic/Tickets/TicketCreator.php b/api/BusinessLogic/Tickets/TicketCreator.php index 3aac73fc..4897a8f4 100644 --- a/api/BusinessLogic/Tickets/TicketCreator.php +++ b/api/BusinessLogic/Tickets/TicketCreator.php @@ -74,9 +74,10 @@ class TicketCreator { $ticket->userAgent = $ticketRequest->userAgent; $ticket->screenResolution = $ticketRequest->screenResolution; - $ticket = $this->ticketGateway->createTicket($ticket, $heskSettings); + $ticketGatewayGeneratedFields = $this->ticketGateway->createTicket($ticket, $heskSettings); - //-- TODO get SQL-generated fields + $ticket->dateCreated = $ticketGatewayGeneratedFields->dateCreated; + $ticket->lastChanged = $ticketGatewayGeneratedFields->dateModified; return $ticket; } diff --git a/api/BusinessLogic/Tickets/TicketGatewayGeneratedFields.php b/api/BusinessLogic/Tickets/TicketGatewayGeneratedFields.php new file mode 100644 index 00000000..00d9521b --- /dev/null +++ b/api/BusinessLogic/Tickets/TicketGatewayGeneratedFields.php @@ -0,0 +1,15 @@ +dateCreated = $row['dt']; + $generatedFields->dateModified = $row['lastchange']; + + return $generatedFields; } } \ No newline at end of file diff --git a/api/Tests/BusinessLogic/Tickets/TicketCreatorTests/CreateTicketForCustomerTest.php b/api/Tests/BusinessLogic/Tickets/TicketCreatorTests/CreateTicketForCustomerTest.php index 8b54b62e..46f16dd2 100644 --- a/api/Tests/BusinessLogic/Tickets/TicketCreatorTests/CreateTicketForCustomerTest.php +++ b/api/Tests/BusinessLogic/Tickets/TicketCreatorTests/CreateTicketForCustomerTest.php @@ -14,6 +14,7 @@ use BusinessLogic\Tickets\Autoassigner; use BusinessLogic\Tickets\CreateTicketByCustomerModel; use BusinessLogic\Tickets\NewTicketValidator; use BusinessLogic\Tickets\TicketCreator; +use BusinessLogic\Tickets\TicketGatewayGeneratedFields; use BusinessLogic\Tickets\TrackingIdGenerator; use BusinessLogic\ValidationModel; use Core\Constants\Priority; @@ -67,6 +68,11 @@ class CreateTicketTest extends TestCase { */ private $userContext; + /** + * @var $ticketGatewayGeneratedFields TicketGatewayGeneratedFields + */ + private $ticketGatewayGeneratedFields; + protected function setUp() { $this->ticketGateway = $this->createMock(TicketGateway::class); $this->newTicketValidator = $this->createMock(NewTicketValidator::class); @@ -97,7 +103,8 @@ class CreateTicketTest extends TestCase { $this->newTicketValidator->method('validateNewTicketForCustomer')->willReturn(new ValidationModel()); $this->trackingIdGenerator->method('generateTrackingId')->willReturn('123-456-7890'); $this->autoassigner->method('getNextUserForTicket')->willReturn(1); - $this->ticketGateway->method('createTicket')->will($this->returnArgument(0)); + $this->ticketGatewayGeneratedFields = new TicketGatewayGeneratedFields(); + $this->ticketGateway->method('createTicket')->willReturn($this->ticketGatewayGeneratedFields); } function testItSavesTheTicketToTheDatabase() { @@ -169,4 +176,18 @@ class CreateTicketTest extends TestCase { self::assertThat($ticket->userAgent, self::equalTo($this->ticketRequest->userAgent)); self::assertThat($ticket->screenResolution, self::equalTo($this->ticketRequest->screenResolution)); } + + function testItReturnsTheGeneratedPropertiesOnTheTicket() { + //-- Arrange + $this->ticketGatewayGeneratedFields->dateCreated = 'date created'; + $this->ticketGatewayGeneratedFields->dateModified = 'date modified'; + + + //-- Act + $ticket = $this->ticketCreator->createTicketByCustomer($this->ticketRequest, $this->heskSettings, $this->modsForHeskSettings, $this->userContext); + + //-- Assert + self::assertThat($ticket->dateCreated, self::equalTo($this->ticketGatewayGeneratedFields->dateCreated)); + self::assertThat($ticket->lastChanged, self::equalTo($this->ticketGatewayGeneratedFields->dateModified)); + } }