2016-10-24 20:01:32 +03:00
|
|
|
<?php
|
|
|
|
|
2016-11-24 01:02:12 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013-2016 Mailgun
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
2016-12-06 21:12:52 +03:00
|
|
|
* of the MIT license. See the LICENSE file for details.
|
2016-11-24 01:02:12 +03:00
|
|
|
*/
|
|
|
|
|
2016-10-24 20:01:32 +03:00
|
|
|
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
|
|
|
|
{
|
2016-10-27 09:34:27 +03:00
|
|
|
/**
|
|
|
|
* 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');
|
|
|
|
}
|
|
|
|
|
2016-10-24 20:01:32 +03:00
|
|
|
abstract protected function getApiClass();
|
|
|
|
|
|
|
|
protected function getApiMock()
|
|
|
|
{
|
|
|
|
$httpClient = $this->getMockBuilder('Http\Client\HttpClient')
|
|
|
|
->setMethods(['sendRequest'])
|
|
|
|
->getMock();
|
|
|
|
$httpClient
|
|
|
|
->expects($this->any())
|
|
|
|
->method('sendRequest');
|
|
|
|
|
2016-11-23 23:55:05 +03:00
|
|
|
$requestClient = $this->getMockBuilder('Mailgun\RequestBuilder')
|
|
|
|
->setMethods(['create'])
|
2016-10-24 20:01:32 +03:00
|
|
|
->getMock();
|
|
|
|
|
2017-03-22 09:44:08 +03:00
|
|
|
$hydrator = $this->getMockBuilder('Mailgun\Hydrator\Hydrator')
|
2016-10-24 20:01:32 +03:00
|
|
|
->setMethods(['deserialize'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
return $this->getMockBuilder($this->getApiClass())
|
2017-02-21 10:22:57 +03:00
|
|
|
->setMethods(['httpGet', 'httpPost', 'httpPostRaw', 'httpDelete', 'httpPut'])
|
2017-03-22 09:44:08 +03:00
|
|
|
->setConstructorArgs([$httpClient, $requestClient, $hydrator])
|
2016-10-24 20:01:32 +03:00
|
|
|
->getMock();
|
|
|
|
}
|
2016-10-27 09:34:27 +03:00
|
|
|
|
|
|
|
protected function getMailgunClient()
|
|
|
|
{
|
|
|
|
return new \Mailgun\Mailgun($this->apiPrivKey);
|
|
|
|
}
|
2016-10-24 20:01:32 +03:00
|
|
|
}
|