mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-26 14:56:03 +03:00
9bd6732efd
* Introduce a request builder. We inject every dependency (eg RequestFactory and MultipartStreamBuilder) and we do not have to use postMultipart. * code style * Use uppercase on http verbs * Added setters and use getters * Added tests * style
69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Mailgun\Tests\Api;
|
|
|
|
/**
|
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
|
* @author Contributors of https://github.com/KnpLabs/php-github-api
|
|
*/
|
|
abstract class TestCase extends \PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* Private Mailgun API key.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $apiPrivKey;
|
|
|
|
/**
|
|
* Public Mailgun API key.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $apiPubKey;
|
|
|
|
/**
|
|
* Domain used for API testing.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $testDomain;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->apiPrivKey = getenv('MAILGUN_PRIV_KEY');
|
|
$this->apiPubKey = getenv('MAILGUN_PUB_KEY');
|
|
$this->testDomain = getenv('MAILGUN_DOMAIN');
|
|
}
|
|
|
|
abstract protected function getApiClass();
|
|
|
|
protected function getApiMock()
|
|
{
|
|
$httpClient = $this->getMockBuilder('Http\Client\HttpClient')
|
|
->setMethods(['sendRequest'])
|
|
->getMock();
|
|
$httpClient
|
|
->expects($this->any())
|
|
->method('sendRequest');
|
|
|
|
$requestClient = $this->getMockBuilder('Mailgun\RequestBuilder')
|
|
->setMethods(['create'])
|
|
->getMock();
|
|
|
|
$deserializer = $this->getMockBuilder('Mailgun\Deserializer\ResponseDeserializer')
|
|
->setMethods(['deserialize'])
|
|
->getMock();
|
|
|
|
return $this->getMockBuilder($this->getApiClass())
|
|
->setMethods(['httpGet', 'httpPost', 'httpPostRaw', 'httpDelete', 'httPut'])
|
|
->setConstructorArgs([$httpClient, $requestClient, $deserializer])
|
|
->getMock();
|
|
}
|
|
|
|
protected function getMailgunClient()
|
|
{
|
|
return new \Mailgun\Mailgun($this->apiPrivKey);
|
|
}
|
|
}
|