setRequestMethod('GET'); $this->setRequestUri('/v3/domains?limit=100&skip=0'); $this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' { "total_count": 1, "items": [ { "created_at": "Wed, 10 Jul 2013 19:26:52 GMT", "smtp_login": "postmaster@samples.mailgun.org", "name": "samples.mailgun.org", "smtp_password": "4rtqo4p6rrx9", "wildcard": true, "spam_action": "disabled", "state": "active" } ] } JSON )); $api = $this->getApiInstance(); /** @var IndexResponse $response */ $response = $api->index(); $this->assertInstanceOf(IndexResponse::class, $response); $this->assertEquals(1, $response->getTotalCount()); $this->assertEquals('samples.mailgun.org', $response->getDomains()[0]->getName()); } public function testShow() { $this->setRequestMethod('GET'); $this->setRequestUri('/v3/domains/example.com'); $this->setHydrateClass(ShowResponse::class); $api = $this->getApiInstance(); $api->show('example.com'); } public function testCreate() { $this->setRequestMethod('POST'); $this->setRequestUri('/v3/domains'); $this->setRequestBody([ 'name' => 'example.com', 'web_scheme' => 'http', 'dkim_key_size' => '1024', ]); $this->setHydrateClass(CreateResponse::class); $api = $this->getApiInstance(); $api->create('example.com'); } public function testCreateWithPassword() { $this->setRequestMethod('POST'); $this->setRequestUri('/v3/domains'); $this->setRequestBody([ 'name' => 'example.com', 'smtp_password' => 'foo', 'web_scheme' => 'http', 'dkim_key_size' => '1024', ]); $this->setHydrateClass(CreateResponse::class); $api = $this->getApiInstance(); $api->create('example.com', 'foo'); } public function testCreateWithPoolId() { $this->setRequestMethod('POST'); $this->setRequestUri('/v3/domains'); $this->setRequestBody([ 'name' => 'example.com', 'smtp_password' => 'foo', 'pool_id' => '123', 'web_scheme' => 'http', 'dkim_key_size' => '1024', ]); $this->setHydrateClass(CreateResponse::class); $api = $this->getApiInstance(); $api->create('example.com', 'foo', null, null, null, null, '123'); } public function testCreateWithPasswordSpamAction() { $this->setRequestMethod('POST'); $this->setRequestUri('/v3/domains'); $this->setRequestBody([ 'name' => 'example.com', 'smtp_password' => 'foo', 'spam_action' => 'bar', 'web_scheme' => 'http', 'dkim_key_size' => '1024', ]); $this->setHydrateClass(CreateResponse::class); $api = $this->getApiInstance(); $api->create('example.com', 'foo', 'bar'); } public function testCreateWithPasswordSpamActionWildcard() { $this->setRequestMethod('POST'); $this->setRequestUri('/v3/domains'); $this->setRequestBody([ 'name' => 'example.com', 'smtp_password' => 'foo', 'spam_action' => 'bar', 'wildcard' => 'true', 'web_scheme' => 'http', 'dkim_key_size' => '1024', ]); $this->setHydrateClass(CreateResponse::class); $api = $this->getApiInstance(); $api->create('example.com', 'foo', 'bar', true); } public function testCreateWithPasswordForceDkimAuthority() { $this->setRequestMethod('POST'); $this->setRequestUri('/v3/domains'); $this->setRequestBody([ 'name' => 'example.com', 'smtp_password' => 'foo', 'force_dkim_authority' => 'true', 'web_scheme' => 'http', 'dkim_key_size' => '1024', ]); $this->setHydrateClass(CreateResponse::class); $api = $this->getApiInstance(); $api->create('example.com', 'foo', null, null, true); } public function testCreateWithPasswordSpamActionWildcardForceDkimAuthority() { $this->setRequestMethod('POST'); $this->setRequestUri('/v3/domains'); $this->setRequestBody([ 'name' => 'example.com', 'smtp_password' => 'foo', 'spam_action' => 'bar', 'wildcard' => 'true', 'force_dkim_authority' => 'true', 'web_scheme' => 'http', 'dkim_key_size' => '1024', ]); $this->setHydrateClass(CreateResponse::class); $api = $this->getApiInstance(); $api->create('example.com', 'foo', 'bar', true, true); } public function testDelete() { $this->setRequestMethod('DELETE'); $this->setRequestUri('/v3/domains/example.com'); $this->setHydrateClass(DeleteResponse::class); $api = $this->getApiInstance(); $api->delete('example.com'); } public function testCreateCredential() { $this->setRequestMethod('POST'); $this->setRequestUri('/v3/domains/example.com/credentials'); $this->setRequestBody([ 'login' => 'foo', 'password' => 'barbar', ]); $this->setHydrateClass(CreateCredentialResponse::class); $api = $this->getApiInstance(); $api->createCredential('example.com', 'foo', 'barbar'); } public function testUpdateCredential() { $this->setRequestMethod('PUT'); $this->setRequestUri('/v3/domains/example.com/credentials/foo'); $this->setRequestBody([ 'password' => 'barbar', ]); $this->setHydrateClass(UpdateCredentialResponse::class); $api = $this->getApiInstance(); $api->updateCredential('example.com', 'foo', 'barbar'); } public function testDeleteCredential() { $this->setRequestMethod('DELETE'); $this->setRequestUri('/v3/domains/example.com/credentials/foo'); $this->setHydrateClass(DeleteCredentialResponse::class); $api = $this->getApiInstance(); $api->deleteCredential('example.com', 'foo', 'barbar'); } public function testConnection() { $this->setRequestMethod('GET'); $this->setRequestUri('/v3/domains/example.com/connection'); $this->setHydrateClass(ConnectionResponse::class); $api = $this->getApiInstance(); $api->connection('example.com'); } public function testUpdateConnection() { $this->setRequestMethod('PUT'); $this->setRequestUri('/v3/domains/example.com/connection'); $this->setRequestBody([ 'require_tls' => 'true', 'skip_verification' => 'false', ]); $this->setHydrateClass(UpdateConnectionResponse::class); $api = $this->getApiInstance(); $api->updateConnection('example.com', true, false); } public function testVerify() { $this->setRequestMethod('PUT'); $this->setRequestUri('/v3/domains/example.com/verify'); $this->setHydrateClass(VerifyResponse::class); $api = $this->getApiInstance(); $api->verify('example.com'); } public function testCreateWithIps() { $this->setRequestMethod('POST'); $this->setRequestUri('/v3/domains'); $this->setRequestBody([ 'name' => 'example.com', 'smtp_password' => 'foo', 'ips' => '127.0.0.1,127.0.0.2', 'web_scheme' => 'http', 'dkim_key_size' => '1024', ]); $this->setHydrateClass(CreateResponse::class); $api = $this->getApiInstance(); $api->create('example.com', 'foo', null, null, null, ['127.0.0.1', '127.0.0.2']); } public function testCreateWithDkim() { $this->setRequestMethod('POST'); $this->setRequestUri('/v3/domains'); $this->setRequestBody([ 'name' => 'example.com', 'smtp_password' => 'foo', 'web_scheme' => 'http', 'dkim_key_size' => '2048', ]); $this->setHydrateClass(CreateResponse::class); $api = $this->getApiInstance(); $api->create('example.com', 'foo', null, null, null, null, null, 'http', '2048'); } public function testCreateWithWebSchema() { $this->setRequestMethod('POST'); $this->setRequestUri('/v3/domains'); $this->setRequestBody([ 'name' => 'example.com', 'smtp_password' => 'foo', 'web_scheme' => 'https', 'dkim_key_size' => '1024', ]); $this->setHydrateClass(CreateResponse::class); $api = $this->getApiInstance(); $api->create('example.com', 'foo', null, null, null, null, null, 'https'); } public function testTracking() { $this->setRequestMethod('GET'); $this->setRequestUri('/v3/domains/example.com/tracking'); $this->setHydrateClass(TrackingResponse::class); /** * @var Domain */ $api = $this->getApiInstance(); $api->tracking('example.com'); } public function updateClickTrackingDataProvider(): array { return [ ['yes'], ['no'], ['htmlonly'], ]; } /** * @dataProvider updateClickTrackingDataProvider */ public function testUpdateClickTracking(string $active) { $this->setRequestMethod('PUT'); $this->setRequestUri('/v3/domains/example.com/tracking/click'); $this->setRequestBody([ 'active' => $active, ]); $this->setHydrateClass(UpdateClickTrackingResponse::class); /** * @var Domain */ $api = $this->getApiInstance(); $api->updateClickTracking('example.com', $active); } public function testUpdateClickTrackingException() { $this->expectException(InvalidArgumentException::class); /** * @var Domain */ $api = $this->getApiInstance(); $api->updateClickTracking('example.com', 'non-valid-active-param'); } public function updateOpenTrackingDataProvider(): array { return [ ['yes'], ['no'], ]; } /** * @dataProvider updateOpenTrackingDataProvider */ public function testUpdateOpenTracking(string $active) { $this->setRequestMethod('PUT'); $this->setRequestUri('/v3/domains/example.com/tracking/open'); $this->setRequestBody([ 'active' => $active, ]); $this->setHydrateClass(UpdateOpenTrackingResponse::class); /** * @var Domain */ $api = $this->getApiInstance(); $api->updateOpenTracking('example.com', $active); } public function testUpdateOpenTrackingException() { $this->expectException(InvalidArgumentException::class); /** * @var Domain */ $api = $this->getApiInstance(); $api->updateOpenTracking('example.com', 'non-valid-active-param'); } public function unsubscribeDataProvider(): array { return [ ['true', 'Test', 'Test1'], ['false', 'Test', 'Test2'], ]; } /** * @dataProvider unsubscribeDataProvider */ public function testUpdateUnsubscribeTracking(string $active, string $htmlFooter, string $textFooter) { $this->setRequestMethod('PUT'); $this->setRequestUri('/v3/domains/example.com/tracking/unsubscribe'); $this->setRequestBody([ 'active' => $active, 'html_footer' => $htmlFooter, 'text_footer' => $textFooter, ]); $this->setHydrateClass(UpdateUnsubscribeTrackingResponse::class); /** * @var Domain */ $api = $this->getApiInstance(); $api->updateUnsubscribeTracking('example.com', $active, $htmlFooter, $textFooter); } public function testUpdateUnsubscribeTrackingException() { $this->expectException(InvalidArgumentException::class); /** * @var Domain */ $api = $this->getApiInstance(); $api->updateUnsubscribeTracking('example.com', 'non-valid-active-param', 'html-footer', 'text-footer'); } }