mailgun-php/tests/Api/RouteTest.php

91 lines
2.2 KiB
PHP
Raw Normal View History

Routes API (#249) * Add initial (empty) Routes PHP Unit Test file We still need to provide the automated tests * Add initial Routes file * Describe API Methods * Inherit method from TestCase - adding @inheritdoc annotation * Add new DTOs to map API responses to known objects * Add new Response to manage the Routes list * Implement method to retrieve a list of Routes * Add new Response to manage a single Route resource * Implement method to retrieve a single Route * Set ShowResponse as final * Add new Response to manage the Create process * Implement method to create a new Route * Fix missing annotation * Add new Response to manage the Delete Route process * Implement method to delete a Route based on the ID * Add new Response to manage the Update Route process This response is based on Domain API docs due there are no examples on Routes API docs. We may need to update the response. * Implement method to update a Route based on the ID * Require a $limit value greater than 0 * Require a $skip value greater than or equal to 0 * Set UpdateResponse as final * Add new (empty) public methods to test the Routes API * Provide method to get the Routes API from Mailgun Client * Add missed annotation * Update ShowResponse to return an instance of ApiResponse instead of the DTO * Update annotation * Fix annotation * Update array $actions to provide an empty array by default * Update parameters to make sure the last arg always is a DateTime (or null) * Use empty() * Remove DTO suffix * Move DTOs to the parent folder/namespace * Fix annotations
2016-12-10 01:15:06 +03:00
<?php
declare(strict_types=1);
Routes API (#249) * Add initial (empty) Routes PHP Unit Test file We still need to provide the automated tests * Add initial Routes file * Describe API Methods * Inherit method from TestCase - adding @inheritdoc annotation * Add new DTOs to map API responses to known objects * Add new Response to manage the Routes list * Implement method to retrieve a list of Routes * Add new Response to manage a single Route resource * Implement method to retrieve a single Route * Set ShowResponse as final * Add new Response to manage the Create process * Implement method to create a new Route * Fix missing annotation * Add new Response to manage the Delete Route process * Implement method to delete a Route based on the ID * Add new Response to manage the Update Route process This response is based on Domain API docs due there are no examples on Routes API docs. We may need to update the response. * Implement method to update a Route based on the ID * Require a $limit value greater than 0 * Require a $skip value greater than or equal to 0 * Set UpdateResponse as final * Add new (empty) public methods to test the Routes API * Provide method to get the Routes API from Mailgun Client * Add missed annotation * Update ShowResponse to return an instance of ApiResponse instead of the DTO * Update annotation * Fix annotation * Update array $actions to provide an empty array by default * Update parameters to make sure the last arg always is a DateTime (or null) * Use empty() * Remove DTO suffix * Move DTOs to the parent folder/namespace * Fix annotations
2016-12-10 01:15:06 +03:00
/*
* Copyright (C) 2013 Mailgun
Routes API (#249) * Add initial (empty) Routes PHP Unit Test file We still need to provide the automated tests * Add initial Routes file * Describe API Methods * Inherit method from TestCase - adding @inheritdoc annotation * Add new DTOs to map API responses to known objects * Add new Response to manage the Routes list * Implement method to retrieve a list of Routes * Add new Response to manage a single Route resource * Implement method to retrieve a single Route * Set ShowResponse as final * Add new Response to manage the Create process * Implement method to create a new Route * Fix missing annotation * Add new Response to manage the Delete Route process * Implement method to delete a Route based on the ID * Add new Response to manage the Update Route process This response is based on Domain API docs due there are no examples on Routes API docs. We may need to update the response. * Implement method to update a Route based on the ID * Require a $limit value greater than 0 * Require a $skip value greater than or equal to 0 * Set UpdateResponse as final * Add new (empty) public methods to test the Routes API * Provide method to get the Routes API from Mailgun Client * Add missed annotation * Update ShowResponse to return an instance of ApiResponse instead of the DTO * Update annotation * Fix annotation * Update array $actions to provide an empty array by default * Update parameters to make sure the last arg always is a DateTime (or null) * Use empty() * Remove DTO suffix * Move DTOs to the parent folder/namespace * Fix annotations
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;
2018-08-05 12:07:33 +03:00
use Mailgun\Api\Route;
use Mailgun\Model\Route\DeleteResponse;
use Mailgun\Model\Route\IndexResponse;
use Mailgun\Model\Route\ShowResponse;
use Mailgun\Model\Route\UpdateResponse;
2021-08-18 22:48:47 +03:00
use Nyholm\Psr7\Response;
Routes API (#249) * Add initial (empty) Routes PHP Unit Test file We still need to provide the automated tests * Add initial Routes file * Describe API Methods * Inherit method from TestCase - adding @inheritdoc annotation * Add new DTOs to map API responses to known objects * Add new Response to manage the Routes list * Implement method to retrieve a list of Routes * Add new Response to manage a single Route resource * Implement method to retrieve a single Route * Set ShowResponse as final * Add new Response to manage the Create process * Implement method to create a new Route * Fix missing annotation * Add new Response to manage the Delete Route process * Implement method to delete a Route based on the ID * Add new Response to manage the Update Route process This response is based on Domain API docs due there are no examples on Routes API docs. We may need to update the response. * Implement method to update a Route based on the ID * Require a $limit value greater than 0 * Require a $skip value greater than or equal to 0 * Set UpdateResponse as final * Add new (empty) public methods to test the Routes API * Provide method to get the Routes API from Mailgun Client * Add missed annotation * Update ShowResponse to return an instance of ApiResponse instead of the DTO * Update annotation * Fix annotation * Update array $actions to provide an empty array by default * Update parameters to make sure the last arg always is a DateTime (or null) * Use empty() * Remove DTO suffix * Move DTOs to the parent folder/namespace * Fix annotations
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>
Routes API (#249) * Add initial (empty) Routes PHP Unit Test file We still need to provide the automated tests * Add initial Routes file * Describe API Methods * Inherit method from TestCase - adding @inheritdoc annotation * Add new DTOs to map API responses to known objects * Add new Response to manage the Routes list * Implement method to retrieve a list of Routes * Add new Response to manage a single Route resource * Implement method to retrieve a single Route * Set ShowResponse as final * Add new Response to manage the Create process * Implement method to create a new Route * Fix missing annotation * Add new Response to manage the Delete Route process * Implement method to delete a Route based on the ID * Add new Response to manage the Update Route process This response is based on Domain API docs due there are no examples on Routes API docs. We may need to update the response. * Implement method to update a Route based on the ID * Require a $limit value greater than 0 * Require a $skip value greater than or equal to 0 * Set UpdateResponse as final * Add new (empty) public methods to test the Routes API * Provide method to get the Routes API from Mailgun Client * Add missed annotation * Update ShowResponse to return an instance of ApiResponse instead of the DTO * Update annotation * Fix annotation * Update array $actions to provide an empty array by default * Update parameters to make sure the last arg always is a DateTime (or null) * Use empty() * Remove DTO suffix * Move DTOs to the parent folder/namespace * Fix annotations
2016-12-10 01:15:06 +03:00
*/
class RouteTest extends TestCase
Routes API (#249) * Add initial (empty) Routes PHP Unit Test file We still need to provide the automated tests * Add initial Routes file * Describe API Methods * Inherit method from TestCase - adding @inheritdoc annotation * Add new DTOs to map API responses to known objects * Add new Response to manage the Routes list * Implement method to retrieve a list of Routes * Add new Response to manage a single Route resource * Implement method to retrieve a single Route * Set ShowResponse as final * Add new Response to manage the Create process * Implement method to create a new Route * Fix missing annotation * Add new Response to manage the Delete Route process * Implement method to delete a Route based on the ID * Add new Response to manage the Update Route process This response is based on Domain API docs due there are no examples on Routes API docs. We may need to update the response. * Implement method to update a Route based on the ID * Require a $limit value greater than 0 * Require a $skip value greater than or equal to 0 * Set UpdateResponse as final * Add new (empty) public methods to test the Routes API * Provide method to get the Routes API from Mailgun Client * Add missed annotation * Update ShowResponse to return an instance of ApiResponse instead of the DTO * Update annotation * Fix annotation * Update array $actions to provide an empty array by default * Update parameters to make sure the last arg always is a DateTime (or null) * Use empty() * Remove DTO suffix * Move DTOs to the parent folder/namespace * Fix annotations
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');
}
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',
2018-08-05 12:07:33 +03:00
]);
$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');
}
Routes API (#249) * Add initial (empty) Routes PHP Unit Test file We still need to provide the automated tests * Add initial Routes file * Describe API Methods * Inherit method from TestCase - adding @inheritdoc annotation * Add new DTOs to map API responses to known objects * Add new Response to manage the Routes list * Implement method to retrieve a list of Routes * Add new Response to manage a single Route resource * Implement method to retrieve a single Route * Set ShowResponse as final * Add new Response to manage the Create process * Implement method to create a new Route * Fix missing annotation * Add new Response to manage the Delete Route process * Implement method to delete a Route based on the ID * Add new Response to manage the Update Route process This response is based on Domain API docs due there are no examples on Routes API docs. We may need to update the response. * Implement method to update a Route based on the ID * Require a $limit value greater than 0 * Require a $skip value greater than or equal to 0 * Set UpdateResponse as final * Add new (empty) public methods to test the Routes API * Provide method to get the Routes API from Mailgun Client * Add missed annotation * Update ShowResponse to return an instance of ApiResponse instead of the DTO * Update annotation * Fix annotation * Update array $actions to provide an empty array by default * Update parameters to make sure the last arg always is a DateTime (or null) * Use empty() * Remove DTO suffix * Move DTOs to the parent folder/namespace * Fix annotations
2016-12-10 01:15:06 +03:00
/**
* {@inheritdoc}
*/
protected function getApiClass()
{
2018-08-05 12:07:33 +03:00
return Route::class;
Routes API (#249) * Add initial (empty) Routes PHP Unit Test file We still need to provide the automated tests * Add initial Routes file * Describe API Methods * Inherit method from TestCase - adding @inheritdoc annotation * Add new DTOs to map API responses to known objects * Add new Response to manage the Routes list * Implement method to retrieve a list of Routes * Add new Response to manage a single Route resource * Implement method to retrieve a single Route * Set ShowResponse as final * Add new Response to manage the Create process * Implement method to create a new Route * Fix missing annotation * Add new Response to manage the Delete Route process * Implement method to delete a Route based on the ID * Add new Response to manage the Update Route process This response is based on Domain API docs due there are no examples on Routes API docs. We may need to update the response. * Implement method to update a Route based on the ID * Require a $limit value greater than 0 * Require a $skip value greater than or equal to 0 * Set UpdateResponse as final * Add new (empty) public methods to test the Routes API * Provide method to get the Routes API from Mailgun Client * Add missed annotation * Update ShowResponse to return an instance of ApiResponse instead of the DTO * Update annotation * Fix annotation * Update array $actions to provide an empty array by default * Update parameters to make sure the last arg always is a DateTime (or null) * Use empty() * Remove DTO suffix * Move DTOs to the parent folder/namespace * Fix annotations
2016-12-10 01:15:06 +03:00
}
}