mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-25 22:36:06 +03:00
Added factory methods (#304)
* Added factory methods * Removed urelated code * Update test code
This commit is contained in:
parent
84a5c5dd4a
commit
1bfd40721e
@ -92,6 +92,35 @@ class Mailgun
|
|||||||
$this->hydrator = $hydrator ?: new ModelHydrator();
|
$this->hydrator = $hydrator ?: new ModelHydrator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param HttpClientConfigurator $httpClientConfigurator
|
||||||
|
* @param Hydrator|null $hydrator
|
||||||
|
* @param RequestBuilder|null $requestBuilder
|
||||||
|
*
|
||||||
|
* @return Mailgun
|
||||||
|
*/
|
||||||
|
public static function configure(
|
||||||
|
HttpClientConfigurator $httpClientConfigurator,
|
||||||
|
Hydrator $hydrator = null,
|
||||||
|
RequestBuilder $requestBuilder = null
|
||||||
|
) {
|
||||||
|
$httpClient = $httpClientConfigurator->createConfiguredClient();
|
||||||
|
|
||||||
|
return new self($httpClient, $hydrator, $requestBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $apiKey
|
||||||
|
*
|
||||||
|
* @return Mailgun
|
||||||
|
*/
|
||||||
|
public static function create($apiKey)
|
||||||
|
{
|
||||||
|
$httpClientConfigurator = (new HttpClientConfigurator())->setApiKey($apiKey);
|
||||||
|
|
||||||
|
return self::configure($httpClientConfigurator);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function allows the sending of a fully formed message OR a custom
|
* This function allows the sending of a fully formed message OR a custom
|
||||||
* MIME string. If sending MIME, the string must be passed in to the 3rd
|
* MIME string. If sending MIME, the string must be passed in to the 3rd
|
||||||
|
@ -44,7 +44,7 @@ class FileFromMemoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
['filePath' => './tests/TestAssets/text_file.txt', 'remoteName' => 'text_file.txt'],
|
['filePath' => './tests/TestAssets/text_file.txt', 'remoteName' => 'text_file.txt'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$mailgun = MockedMailgun::create($this, 'POST', 'domain/messages', [], $fileValidator);
|
$mailgun = MockedMailgun::createMock($this, 'POST', 'domain/messages', [], $fileValidator);
|
||||||
|
|
||||||
$mailgun->sendMessage('domain', [
|
$mailgun->sendMessage('domain', [
|
||||||
'from' => 'bob@example.com',
|
'from' => 'bob@example.com',
|
||||||
|
@ -36,7 +36,7 @@ class InlineFileTest extends \PHPUnit_Framework_TestCase
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Create the mocked mailgun client. We use $this->assertEquals on $method, $uri and $body parameters.
|
// Create the mocked mailgun client. We use $this->assertEquals on $method, $uri and $body parameters.
|
||||||
$mailgun = MockedMailgun::create($this, 'POST', 'domain/messages', [], $fileValidator);
|
$mailgun = MockedMailgun::createMock($this, 'POST', 'domain/messages', [], $fileValidator);
|
||||||
|
|
||||||
$builder = $mailgun->MessageBuilder();
|
$builder = $mailgun->MessageBuilder();
|
||||||
$builder->setFromAddress('bob@example.com');
|
$builder->setFromAddress('bob@example.com');
|
||||||
|
@ -44,7 +44,7 @@ final class MockedMailgun extends Mailgun
|
|||||||
* @param \Closure|array $filesValidator
|
* @param \Closure|array $filesValidator
|
||||||
* @param \Closure|array $headersValidator
|
* @param \Closure|array $headersValidator
|
||||||
*/
|
*/
|
||||||
public static function create(
|
public static function createMock(
|
||||||
\PHPUnit_Framework_TestCase $testCase,
|
\PHPUnit_Framework_TestCase $testCase,
|
||||||
$methodValidator,
|
$methodValidator,
|
||||||
$uriValidator,
|
$uriValidator,
|
||||||
|
@ -28,7 +28,7 @@ class NoSamePostNameTest extends \PHPUnit_Framework_TestCase
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Create the mocked mailgun client. We use $this->assertEquals on $method, $uri and $body parameters.
|
// Create the mocked mailgun client. We use $this->assertEquals on $method, $uri and $body parameters.
|
||||||
$mailgun = MockedMailgun::create($this, 'POST', 'domain/messages', [], $fileValidator);
|
$mailgun = MockedMailgun::createMock($this, 'POST', 'domain/messages', [], $fileValidator);
|
||||||
|
|
||||||
$builder = $mailgun->MessageBuilder();
|
$builder = $mailgun->MessageBuilder();
|
||||||
$builder->setFromAddress('bob@example.com');
|
$builder->setFromAddress('bob@example.com');
|
||||||
|
@ -27,7 +27,7 @@ class SendMessageTest extends \PHPUnit_Framework_TestCase
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Create the mocked mailgun client. We use $this->assertEquals on $method, $uri and $body parameters.
|
// Create the mocked mailgun client. We use $this->assertEquals on $method, $uri and $body parameters.
|
||||||
$mailgun = MockedMailgun::create($this, 'POST', 'domain/messages', [], $fileValidator);
|
$mailgun = MockedMailgun::createMock($this, 'POST', 'domain/messages', [], $fileValidator);
|
||||||
|
|
||||||
$mailgun->sendMessage('domain', [
|
$mailgun->sendMessage('domain', [
|
||||||
'from' => 'bob@example.com',
|
'from' => 'bob@example.com',
|
||||||
|
Loading…
Reference in New Issue
Block a user