38 $this->config = $this->getMockBuilder(Config::class)
39 ->disableOriginalConstructor()
42 $this->decoder = $this->getMockBuilder(DecoderInterface::class)
43 ->getMockForAbstractClass();
62 $this->config->expects($this->exactly($callConfigCount))
64 ->willReturn(
'GpFZZnxGgIxuI8BazSm3v6eGK');
66 $this->decoder->expects($this->once())
69 ->willReturn([
'status' =>
"DISMISSED",
'orderId' =>
'19418']);
71 $webhookRequest = $this->createWebhookRequest($body, $topic, $hash);
74 $this->model->validate($webhookRequest)
87 'body' =>
'{ status: "DISMISSED", orderId: "19418" }',
88 'topic' =>
'cases/creation',
89 'hash' =>
'KWR8Bzu3tinEpDviw1opWSMJGFqfpA79nNGp0TEYM6Q=',
90 'callConfigCount' => 1
93 'body' =>
'{ status: "DISMISSED", orderId: "19418" }',
94 'topic' =>
'cases/test',
95 'hash' =>
'6npAahliNbzYo/Qi4+g+JeqPhLFgg19sIbuxDLmvobw=',
96 'callConfigCount' => 0
109 $body =
'{ status: "DISMISSED", orderId: "19418" }';
110 $hash =
'KWR8Bzu3tinEpDviw1opWSMJGFqfpA79nNGp0TEYM6Q=';
112 $this->config->expects($this->never())
113 ->method(
'getApiKey');
115 $this->decoder->expects($this->never())
118 $webhookRequest = $this->createWebhookRequest($body, $topic, $hash);
121 $this->model->validate($webhookRequest),
122 'Negative webhook event topic value validation fails' 132 [
'wrong topic' =>
'bla-bla-topic'],
133 [
'empty topic' =>
'']
145 $topic =
'cases/creation';
146 $hash =
'KWR8Bzu3tinEpDviw1opWSMJGFqfpA79nNGp0TEYM6Q=';
147 $webhookRequest = $this->createWebhookRequest($body, $topic, $hash);
149 $this->config->expects($this->never())
150 ->method(
'getApiKey');
153 $this->decoder->expects($this->once())
158 $this->decoder->expects($this->once())
161 ->willThrowException(
new \Exception(
'Error'));
165 $this->model->validate($webhookRequest),
166 'Negative webhook request body validation fails' 176 [
'Empty request body' =>
''],
177 [
'Bad request body' =>
'{ bad data}']
186 $topic =
'cases/creation';
187 $body =
'{ status: "DISMISSED", orderId: "19418" }';
188 $hash =
'wrong hash';
189 $webhookRequest = $this->createWebhookRequest($body, $topic, $hash);
191 $this->config->expects($this->once())
192 ->method(
'getApiKey')
193 ->willReturn(
'GpFZZnxGgIxuI8BazSm3v6eGK');
195 $this->decoder->expects($this->once())
198 ->willReturn([
'status' =>
"DISMISSED",
'orderId' =>
'19418']);
201 $this->model->validate($webhookRequest),
202 'Negative webhook hash validation fails' 214 private function createWebhookRequest($body, $topic, $hash)
216 $webhookRequest = $this->getMockBuilder(WebhookRequest::class)
217 ->disableOriginalConstructor()
219 $webhookRequest->expects($this->once())
222 $webhookRequest->expects($this->once())
223 ->method(
'getEventTopic')
224 ->willReturn($topic);
225 $webhookRequest->expects($this->once())
229 return $webhookRequest;
validateSuccessDataProvider()
testValidationBodyFails($body)
testValidationHashFails()
validationBodyFailsDataProvider()
testValidateSuccess($body, $topic, $hash, $callConfigCount)
testValidationTopicFails($topic)
validationTopicFailsDataProvider()