getAcceptedContentType()); } public function testCreatePositive() { $body = [ 'events' => [ [ 'eventId' => '52a3de8dd0f270fd193f9f4bff05232f', 'status' => 'accepted' ] ] ]; $factory = new JsonWebhookResponseFactory(); $jsonValidatorMock = $this->createMock(JsonValidator::class); $jsonValidatorMock->expects($this->once()) ->method('validate') ->willReturn(null) ->with($this->callback(function ($body) { $event = reset($body->events); return $event->eventId === '52a3de8dd0f270fd193f9f4bff05232f' && $event->status === 'accepted'; })); $factory->setServiceLocator($this->getServiceLocatorMock([ JsonValidator::class => $jsonValidatorMock ])); $response = new Response( 200, [ 'Content-Type' => $factory->getAcceptedContentType() ], json_encode($body) ); $parsedResponse = $factory->create($response); $this->assertTrue($parsedResponse->isDelivered('52a3de8dd0f270fd193f9f4bff05232f')); $this->assertCount(1, $parsedResponse->getStatuses()); $this->assertSame('accepted', $parsedResponse->getStatus('52a3de8dd0f270fd193f9f4bff05232f')); $this->assertNull($parsedResponse->getParseError()); } public function testCreateInvalidContentType() { $factory = new JsonWebhookResponseFactory(); $response = new Response( 200, [ 'Content-Type' => 'application/xml' ], '' ); $parsedResponse = $factory->create($response); $this->assertNotNull($parsedResponse->getParseError()); $this->assertCount(0, $parsedResponse->getStatuses()); } public function testCreateInvalidData() { $factory = new JsonWebhookResponseFactory(); $jsonValidatorMock = $this->createMock(JsonValidator::class); $jsonValidatorMock->expects($this->once()) ->method('validate') ->with(['ab']) ->willThrowException(new InvalidJsonException('Err', 0, ['err1'])); $factory->setServiceLocator($this->getServiceLocatorMock([ JsonValidator::class => $jsonValidatorMock ])); $response = new Response( 200, [ 'Content-Type' => $factory->getAcceptedContentType() ], '["ab"]' ); $parsedResponse = $factory->create($response); $this->assertNotNull($parsedResponse->getParseError()); $this->assertCount(0, $parsedResponse->getStatuses()); } }