ticketGateway = $this->createMock(TicketGateway::class); $this->userToTicketChecker = $this->createMock(UserToTicketChecker::class); $this->heskSettings = array('email_view_ticket' => 0); $this->ticketRetriever = new TicketRetriever($this->ticketGateway, $this->userToTicketChecker); } function testItGetsTheTicketByTrackingId() { //-- Arrange $ticket = new Ticket(); $trackingId = '12345'; $this->ticketGateway->method('getTicketByTrackingId')->with($trackingId, $this->heskSettings)->willReturn($ticket); //-- Act $actual = $this->ticketRetriever->getTicketByTrackingIdAndEmail($trackingId, null, $this->heskSettings); //-- Assert self::assertThat($actual, self::equalTo($ticket)); } function testItGetsTheParentTicketIfTheUserEntersInAMergedTicketId() { //-- Arrange $ticket = new Ticket(); $trackingId = '12345'; $this->ticketGateway->method('getTicketByTrackingId')->willReturn(null); $this->ticketGateway->method('getTicketByMergedTrackingId')->with($trackingId, $this->heskSettings)->willReturn($ticket); //-- Act $actual = $this->ticketRetriever->getTicketByTrackingIdAndEmail($trackingId, null, $this->heskSettings); //-- Assert self::assertThat($actual, self::equalTo($ticket)); } function testItChecksTheTicketsEmailIfThePageRequiresIt() { //-- Arrange $ticket = new Ticket(); $email = 'email@example.com'; $ticket->email = array('email2@example.com;email3@example.com,email4@example.com'); $trackingId = '12345'; $this->heskSettings['email_view_ticket'] = 1; $this->ticketGateway->method('getTicketByTrackingId')->with($trackingId, $this->heskSettings)->willReturn($ticket); //-- Assert $this->expectException(\Exception::class); $this->expectExceptionMessage("Email 'email@example.com' entered in for ticket '12345' does not match!"); //-- Act $this->ticketRetriever->getTicketByTrackingIdAndEmail($trackingId, $email, $this->heskSettings); } function testItCanHandleTicketsWithMultipleEmails() { //-- Arrange $ticket = new Ticket(); $email = 'email2@example.com'; $ticket->email = array('email2@example.com','email3@example.com','email4@example.com'); $trackingId = '12345'; $this->heskSettings['email_view_ticket'] = 1; $this->ticketGateway->method('getTicketByTrackingId')->with($trackingId, $this->heskSettings)->willReturn($ticket); //-- Act $actual = $this->ticketRetriever->getTicketByTrackingIdAndEmail($trackingId, $email, $this->heskSettings); //-- Assert self::assertThat($actual, self::equalTo($ticket)); } //-- TODO Validation tests }