assertSame('application/json', $factory->getContentType()); } public function testCreatePayloadSchema() { $factory = new JsonWebhookPayloadFactory(); /** @noinspection PhpUnhandledExceptionInspection */ $payload = $factory->createPayload('TestEvent', '52a3de8dd0f270fd193f9f4bff05232f', 1237435, ['d' => 4]); $payloadObject = json_decode($payload, false); $validator = new Validator(); $validator->validate($payloadObject, (object)[ '$ref' => 'file://' . realpath(__DIR__ . '/webhookRequestSchema.json') ]); if (!$validator->isValid()) { $validationErrors = []; foreach ($validator->getErrors() as $error) { $validationErrors[] = sprintf('[%s] %s', $error['property'], $error['message']); } $this->fail(implode(PHP_EOL, $validationErrors)); } $this->assertTrue(true); } public function testCreatePayloadData() { $factory = new JsonWebhookPayloadFactory(); /** @noinspection PhpUnhandledExceptionInspection */ $payload = $factory->createPayload('TestEvent', '52a3de8dd0f270fd193f9f4bff05232f', 1237435, ['d' => 4]); $payloadObject = json_decode($payload, true); $sourceUrl = defined('ROOT_URL') ? ROOT_URL : gethostname(); self::assertSame($sourceUrl, $payloadObject[JsonWebhookPayloadFactory::SOURCE]); $events = $payloadObject[JsonWebhookPayloadFactory::EVENTS]; $this->assertCount(1, $events); $event = reset($events); self::assertSame('TestEvent', $event[JsonWebhookPayloadFactory::EVENT_NAME]); self::assertSame('52a3de8dd0f270fd193f9f4bff05232f', $event[JsonWebhookPayloadFactory::EVENT_ID]); self::assertSame(1237435, $event[JsonWebhookPayloadFactory::TRIGGERED_TIMESTAMP]); self::assertSame(['d' => 4], $event[JsonWebhookPayloadFactory::EVENT_DATA]); } }