'idd', WebhookTaskParams::TRIGGERED_TIMESTAMP => 1233245, WebhookTaskParams::WEBHOOK_CONFIG_ID => 'wh1', WebhookTaskParams::EVENT_NAME => 'EventName', WebhookTaskParams::EVENT_DATA => ['d' => 4], WebhookTaskParams::RETRY_MAX => 5, WebhookTaskParams::RETRY_COUNT => 1 ]; $params = $factory->createFromArray($params); $this->assertInstanceOf(WebhookTaskParams::class, $params); $this->assertSame('idd', $params->getEventId()); $this->assertSame(1233245, $params->getTriggeredTimestamp()); $this->assertSame('EventName', $params->getEventName()); $this->assertSame('wh1', $params->getWebhookConfigId()); $this->assertSame(['d' => 4], $params->getEventData()); $this->assertSame(5, $params->getRetryMax()); } public function testCreateFromArrayMissedKeys() { $factory = new WebhookTaskParamsFactory(); $params = [ WebhookTaskParams::EVENT_ID => 'idd', WebhookTaskParams::TRIGGERED_TIMESTAMP => 1233245, WebhookTaskParams::WEBHOOK_CONFIG_ID => 'wh1', WebhookTaskParams::EVENT_NAME => 'EventName', WebhookTaskParams::EVENT_DATA => ['d' => 4] ]; foreach ($params as $key => $value) { $modifiedParams = $params; unset($modifiedParams[$key]); try { $factory->createFromArray($modifiedParams); } catch (\InvalidArgumentException $exception) { $this->assertStringContainsString($key, $exception->getMessage()); continue; } $this->fail("No exception for missed '$key' key in params"); } } public function testCreateFromArrayInvalidTypes() { $factory = new WebhookTaskParamsFactory(); $params = [ WebhookTaskParams::EVENT_ID => 42245, WebhookTaskParams::TRIGGERED_TIMESTAMP => '1233245', WebhookTaskParams::WEBHOOK_CONFIG_ID => 'wh1', WebhookTaskParams::EVENT_NAME => 'EventName', WebhookTaskParams::EVENT_DATA => ['d' => 4] ]; $this->expectException(\InvalidArgumentException::class); try { $factory->createFromArray($params); } catch (\InvalidArgumentException $exception) { $this->assertStringContainsString(WebhookTaskParams::EVENT_ID, $exception->getMessage()); $this->assertStringContainsString(WebhookTaskParams::TRIGGERED_TIMESTAMP, $exception->getMessage()); throw $exception; } } }