2016-12-10 01:15:06 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2017-11-22 11:37:04 +03:00
|
|
|
* Copyright (C) 2013 Mailgun
|
2016-12-10 01:15:06 +03:00
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Mailgun\Tests\Api;
|
|
|
|
|
2017-03-25 16:02:11 +03:00
|
|
|
use GuzzleHttp\Psr7\Response;
|
2018-08-05 12:07:33 +03:00
|
|
|
use Mailgun\Api\Route;
|
|
|
|
use Mailgun\Model\Route\Response\DeleteResponse;
|
|
|
|
use Mailgun\Model\Route\Response\IndexResponse;
|
|
|
|
use Mailgun\Model\Route\Response\ShowResponse;
|
|
|
|
use Mailgun\Model\Route\Response\UpdateResponse;
|
2017-03-25 16:02:11 +03:00
|
|
|
|
2016-12-10 01:15:06 +03:00
|
|
|
/**
|
|
|
|
* @author David Garcia <me@davidgarcia.cat>
|
2018-08-05 12:07:33 +03:00
|
|
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
2016-12-10 01:15:06 +03:00
|
|
|
*/
|
2017-03-26 17:11:33 +03:00
|
|
|
class RouteTest extends TestCase
|
2016-12-10 01:15:06 +03:00
|
|
|
{
|
2018-08-05 12:07:33 +03:00
|
|
|
public function testIndex()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('GET');
|
|
|
|
$this->setRequestUri('/v3/routes?limit=100&skip=0');
|
|
|
|
$this->setHydrateClass(IndexResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->index();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testShow()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('GET');
|
|
|
|
$this->setRequestUri('/v3/routes/4711');
|
|
|
|
$this->setHydrateClass(ShowResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->show('4711');
|
|
|
|
}
|
|
|
|
|
2017-03-25 16:02:11 +03:00
|
|
|
public function testCreate()
|
|
|
|
{
|
|
|
|
$api = $this->getApiMock();
|
|
|
|
$api->expects($this->once())
|
|
|
|
->method('httpPost')
|
|
|
|
->willReturn(new Response());
|
|
|
|
|
|
|
|
$api->create('catch_all()', ['forward("mailbox@myapp.com")'], 'example', 100);
|
|
|
|
}
|
|
|
|
|
2018-08-05 12:07:33 +03:00
|
|
|
|
|
|
|
public function testUpdate()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('PUT');
|
|
|
|
$this->setRequestUri('/v3/routes/4711');
|
|
|
|
$this->setHydrateClass(UpdateResponse::class);
|
|
|
|
$this->setRequestBody([
|
|
|
|
'expression' => 'catch_all()',
|
|
|
|
'action' => 'forward("mailbox@myapp.com")',
|
|
|
|
'description' => 'example',
|
|
|
|
'priority' => 100,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->update('4711', 'catch_all()', ['forward("mailbox@myapp.com")'], 'example', 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDelete()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('DELETE');
|
|
|
|
$this->setRequestUri('/v3/routes/4711');
|
|
|
|
$this->setHydrateClass(DeleteResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->delete('4711');
|
|
|
|
}
|
|
|
|
|
2016-12-10 01:15:06 +03:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function getApiClass()
|
|
|
|
{
|
2018-08-05 12:07:33 +03:00
|
|
|
return Route::class;
|
2016-12-10 01:15:06 +03:00
|
|
|
}
|
|
|
|
}
|