Skip to content

Commit

Permalink
Exception Unit Tests + Exception Abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelJ2324 committed Mar 22, 2017
1 parent 8fdaf83 commit eb1972f
Show file tree
Hide file tree
Showing 21 changed files with 124 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/Endpoint/Abstracts/AbstractCollectionEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function update(array $collection){
//Collection Interface
/**
* @inheritdoc
* @throws \MRussell\REST\Exception\Endpoint\InvalidRequestException
* @throws \MRussell\REST\Exception\Endpoint\InvalidRequest
*/
public function fetch() {
$this->setProperty('httpMethod',Curl::HTTP_GET);
Expand Down
22 changes: 11 additions & 11 deletions src/Endpoint/Abstracts/AbstractEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use MRussell\REST\Endpoint\Data\AbstractEndpointData;
use MRussell\REST\Endpoint\Data\DataInterface;
use MRussell\REST\Endpoint\Interfaces\EndpointInterface;
use MRussell\REST\Exception\Endpoint\InvalidRequestException;
use MRussell\REST\Exception\Endpoint\InvalidURLException;
use MRussell\REST\Exception\Endpoint\RequiredDataException;
use MRussell\REST\Exception\Endpoint\RequiredOptionsException;
use MRussell\REST\Exception\Endpoint\InvalidRequest;
use MRussell\REST\Exception\Endpoint\InvalidURLEndpointException;
use MRussell\REST\Exception\Endpoint\InvalidData;
use MRussell\REST\Exception\Endpoint\InvalidOptions;
use MRussell\Http\Response\ResponseInterface;
use MRussell\Http\Request\RequestInterface;

Expand Down Expand Up @@ -221,8 +221,8 @@ public function getResponse()
* @inheritdoc
* @param null $data - short form data for Endpoint, which is configure by configureData method
* @return $this
* @throws InvalidRequestException
* @throws InvalidURLException
* @throws InvalidRequest
* @throws InvalidURLEndpointException
*/
public function execute()
{
Expand All @@ -232,7 +232,7 @@ public function execute()
$this->configureResponse($this->Response);
}
} else {
throw new InvalidRequestException(get_called_class(), "Request property not configured");
throw new InvalidRequest(get_called_class(), "Request property not configured");
}
return $this;
}
Expand Down Expand Up @@ -271,8 +271,8 @@ public function getAuth()
* Verifies URL and Data are setup, then sets them on the Request Object
* @param RequestInterface $Request
* @return RequestInterface
* @throws InvalidURLException
* @throws RequiredDataException
* @throws InvalidURLEndpointException
* @throws InvalidData
*/
protected function configureRequest(RequestInterface $Request)
{
Expand Down Expand Up @@ -365,12 +365,12 @@ protected function configureURL(array $options)
* Verify if URL is configured properly
* @param string $url
* @return bool
* @throws InvalidURLException
* @throws InvalidURLEndpointException
*/
private function verifyUrl($url)
{
if (strpos($url, static::$_URL_VAR_CHARACTER) !== false) {
throw new InvalidURLException(get_called_class(), "Configured URL is ".$url);
throw new InvalidURLEndpointException(get_called_class(), "Configured URL is ".$url);
}
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Endpoint/Abstracts/AbstractModelEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use MRussell\REST\Endpoint\Data\AbstractEndpointData;
use MRussell\REST\Endpoint\Data\DataInterface;
use MRussell\REST\Endpoint\Interfaces\ModelInterface;
use MRussell\REST\Exception\Endpoint\Exception;
use MRussell\REST\Exception\Endpoint\EndpointException;

/**
* Class AbstractModelEndpoint
Expand Down Expand Up @@ -184,7 +184,7 @@ public function set($key, $value) {

/**
* @inheritdoc
* @throws \MRussell\REST\Exception\Endpoint\InvalidRequestException
* @throws \MRussell\REST\Exception\Endpoint\InvalidRequest
*/
public function retrieve($id = NULL) {
$idKey = $this->modelIdKey();
Expand All @@ -195,7 +195,7 @@ public function retrieve($id = NULL) {
}
} else {
if (!isset($this->model[$idKey])){
throw new Exception("Cannot retrieve Model without an ID");
throw new EndpointException("Cannot retrieve Model without an ID");
}
}
$this->action = self::MODEL_ACTION_RETRIEVE;
Expand All @@ -205,7 +205,7 @@ public function retrieve($id = NULL) {

/**
* @inheritdoc
* @throws \MRussell\REST\Exception\Endpoint\InvalidRequestException
* @throws \MRussell\REST\Exception\Endpoint\InvalidRequest
*/
public function save() {
if (isset($this->model[$this->modelIdKey()])){
Expand Down
4 changes: 2 additions & 2 deletions src/Endpoint/Abstracts/AbstractSmartEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use MRussell\REST\Endpoint\Data\AbstractEndpointData;
use MRussell\REST\Endpoint\Data\EndpointData;
use MRussell\REST\Exception\Endpoint\Exception;
use MRussell\REST\Exception\Endpoint\EndpointException;

abstract class AbstractSmartEndpoint extends AbstractEndpoint
{
Expand Down Expand Up @@ -73,7 +73,7 @@ public function setData($data) {
$this->data->reset();
$this->data->update($data);
} else {
throw new Exception("Invalid data passed to Endpoint");
throw new EndpointException("Invalid data passed to Endpoint");
}
return $this;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Endpoint/Data/AbstractEndpointData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MRussell\REST\Endpoint\Data;

use MRussell\REST\Exception\Endpoint\RequiredDataException;
use MRussell\REST\Exception\Endpoint\InvalidData;

abstract class AbstractEndpointData implements DataInterface
{
Expand Down Expand Up @@ -118,7 +118,7 @@ public function offsetGet($offset) {
* Return the entire Data array
* @param bool $verify - Whether or not to verify if Required Data is filled in
* @return array
* @throws RequiredDataException
* @throws InvalidData
*/
public function asArray($verify = FALSE){
if ($verify){
Expand Down Expand Up @@ -192,7 +192,7 @@ protected function configureDefaultData(){
/**
* Validate Required Data for the Endpoint
* @return bool
* @throws RequiredDataException
* @throws InvalidData
*/
protected function verifyRequiredData()
{
Expand All @@ -208,7 +208,7 @@ protected function verifyRequiredData()
}
}
if ($error){
throw new RequiredDataException(get_called_class());
throw new InvalidData(get_called_class());
}
return $error;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Endpoint/Provider/AbstractEndpointProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use MRussell\REST\Auth\AuthControllerInterface;
use MRussell\REST\Endpoint\ControllerInterface;
use MRussell\REST\Endpoint\Interfaces\EndpointInterface;
use MRussell\REST\Exception\Endpoint\RegistrationException;
use MRussell\REST\Exception\Endpoint\InvalidEndpointRegistration;
use MRussell\REST\Exception\Endpoint\UnknownEndpoint;

abstract class AbstractEndpointProvider implements EndpointProviderInterface
Expand Down Expand Up @@ -33,7 +33,7 @@ public function __construct() {

/**
* @inheritdoc
* @throws RegistrationException
* @throws InvalidEndpointRegistration
*/
public function registerEndpoint($name, $className, array $properties = array())
{
Expand All @@ -44,7 +44,7 @@ public function registerEndpoint($name, $className, array $properties = array())
'properties' => $properties
);
} else {
throw new RegistrationException($className);
throw new InvalidEndpointRegistration($className);
}
return $this;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Exception/Auth/AuthException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace MRussell\REST\Exception\Auth;

use MRussell\REST\Exception\RestClientException;

class AuthException extends \Exception
class AuthException extends RestClientException
{
protected $message = 'Unknown Auth Exception occurred.';
protected $message = 'Unknown Auth Exception occurred on Controller: %s';
}
1 change: 0 additions & 1 deletion src/Exception/Auth/NotAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MRussell\REST\Exception\Auth;


class NotAuthenticated extends AuthException
{
protected $message = 'Auth Controller not currently authenticated.';
Expand Down
11 changes: 3 additions & 8 deletions src/Exception/Client/ClientException.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
<?php
/**
* Created by PhpStorm.
* User: mrussell
* Date: 1/20/17
* Time: 10:51 AM
*/

namespace MRussell\REST\Exception\Client;

use MRussell\REST\Exception\RestClientException;

class ClientException extends \Exception {
class ClientException extends RestClientException {

protected $message = 'Unknown REST Client Exception occurred.';
protected $message = 'Unknown Exception occurred on REST Client: %s';

}
11 changes: 11 additions & 0 deletions src/Exception/Endpoint/EndpointException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace MRussell\REST\Exception\Endpoint;

use MRussell\REST\Exception\RestClientException;

class EndpointException extends RestClientException
{
protected $message = 'Unknown Exception occurred on Endpoint: %s';

}
10 changes: 0 additions & 10 deletions src/Exception/Endpoint/Exception.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace MRussell\REST\Exception\Endpoint;

class RequiredDataException extends \Exception
class InvalidData extends EndpointException
{
protected $message = "Missing or Invalid data on Endpoint [%s].";

}
8 changes: 8 additions & 0 deletions src/Exception/Endpoint/InvalidOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace MRussell\REST\Exception\Endpoint;

class InvalidOptions extends EndpointException
{
protected $message = 'Invalid or missing options of Endpoint: %s';
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MRussell\REST\Exception\Endpoint;

class RegistrationException extends Exception {
class InvalidRegistration extends EndpointException {

protected $message = 'Endpoint Object [%s] must extend MRussell\REST\Endpoint\EndpointInterface';

Expand Down
8 changes: 8 additions & 0 deletions src/Exception/Endpoint/InvalidRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace MRussell\REST\Exception\Endpoint;

class InvalidRequest extends EndpointException
{
protected $message = 'Request Property not configured on Endpoint: %s';
}
11 changes: 0 additions & 11 deletions src/Exception/Endpoint/InvalidRequestException.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Exception/Endpoint/InvalidURLException.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Exception/Endpoint/RequiredOptionsException.php

This file was deleted.

11 changes: 2 additions & 9 deletions src/Exception/Endpoint/UnknownEndpoint.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
<?php
/**
* Created by PhpStorm.
* User: mrussell
* Date: 1/19/17
* Time: 10:35 PM
*/

namespace MRussell\REST\Exception\Endpoint;


class UnknownEndpoint extends Exception
class UnknownEndpoint extends EndpointException
{
protected $message = 'An Unknown Endpoint [%s] was requested.';


protected $code = 404;
}
15 changes: 15 additions & 0 deletions src/Exception/RestClientException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace MRussell\REST\Exception;

class RestClientException extends \Exception
{
protected $message = 'An Unknown Exception occurred in the REST Client Framework';

public function __construct($args = array()) {
if (!empty($args)){
$this->message = vsprintf($this->message,$args);
}
parent::__construct($this->message);
}
}
Loading

0 comments on commit eb1972f

Please sign in to comment.