diff --git a/.travis.yml b/.travis.yml index db93e51..e125b6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: php php: - - 5.4 - - 5.5 + - 5.5.9 before_script: - wget http://getcomposer.org/composer.phar diff --git a/README.md b/README.md index 8cf48ce..df7eef8 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,10 @@ # Trucker -[](http://indatus.com/company/careers) - [![Latest Stable Version](https://poser.pugx.org/indatus/trucker/v/stable.png)](https://packagist.org/packages/indatus/trucker) [![Total Downloads](https://poser.pugx.org/indatus/trucker/downloads.png)](https://packagist.org/packages/indatus/trucker) [![Build Status](https://travis-ci.org/Indatus/trucker.png?branch=master)](https://travis-ci.org/Indatus/trucker) [![Coverage Status](https://coveralls.io/repos/Indatus/trucker/badge.png?branch=master)](https://coveralls.io/r/Indatus/trucker?branch=master) [![Dependency Status](https://www.versioneye.com/user/projects/530271f4ec1375bab10004bb/badge.png)](https://www.versioneye.com/user/projects/530271f4ec1375bab10004bb) Trucker is a PHP package for mapping remote API resources (usually RESTful) as models in an ActiveResource style. The benefit is easier use of remote APIs in a fast and clean programming interface. - - ```php ### Requirements -- Any flavour of PHP 5.4+ should do +- Any flavour of PHP 5.5+ should do ### Install With Composer @@ -75,9 +69,11 @@ $results = Product::all(); //find a collection You can install the library via [Composer](http://getcomposer.org) by adding the following line to the **require** block of your *composer.json* file: ```` -"indatus/trucker": "dev-master" +"indatus/trucker": "dev-laravel-5" ```` +> Note: This project will not be supported for future versions of Laravel. We do not recommend continuing to implement this package in Laravel projects, unless someone else would like to begin to maintain this project (create an issue if you are). + Next run `composer install`, now you need to publish the config files. Trucker's config files are where you'd define constant things about the API your interacting with, like the end-point, what drivers you want to use etc. @@ -85,27 +81,18 @@ Trucker's config files are where you'd define constant things about the API your ### Configure in Laravel -Trucker works well with the [Laravel](http://laravel.com) framework. If your using Trucker within Laravel, you just need to run the following command to publish the Trucker config files to the **app/config/packages/indatus/trucker** folder. +Trucker works well with the [Laravel](http://laravel.com) framework. If your using Trucker within Laravel, you just need to run the following command to publish the Trucker config files. ```` -php artisan config:publish indatus/trucker +php artisan vendor:publish indatus/trucker ```` The final step is to add the service provider. Open `app/config/app.php`, and add a new item to the providers array. - 'Trucker\TruckerServiceProvider' + 'Trucker\TruckerServiceProvider::class' Now you should be ready to go. - -### Configure outside Laravel - -If your using Trucker outside Laravel you just need to create the `.trucker` folder in your project root and copy the package's config files there. Here's the *nix command for that. - -```` -mkdir .trucker && cp vendor/indatus/trucker/src/config/* .trucker/ -```` - ## Configuration Options diff --git a/composer.json b/composer.json index afba1b2..631e64e 100644 --- a/composer.json +++ b/composer.json @@ -24,13 +24,13 @@ } ], "require": { - "php": ">=5.4.0", - "illuminate/support": "~4", - "illuminate/config": "~4", - "illuminate/container": "~4", + "php": ">=5.5.9", + "illuminate/support": "~5", + "illuminate/config": "~5", + "illuminate/container": "~5", "guzzle/guzzle": "3.8.1", "doctrine/inflector": "1.0", - "patchwork/utf8": "1.1.*" + "patchwork/utf8": "1.2.*" }, "require-dev": { "phpunit/phpunit": "4.1.*", diff --git a/src/Trucker/Factories/ApiTransporterFactory.php b/src/Trucker/Factories/ApiTransporterFactory.php index f012013..c77ada3 100644 --- a/src/Trucker/Factories/ApiTransporterFactory.php +++ b/src/Trucker/Factories/ApiTransporterFactory.php @@ -10,16 +10,15 @@ */ namespace Trucker\Factories; -use Illuminate\Container\Container; -use Trucker\Framework\FactoryDriver; use Trucker\Facades\Config; +use Trucker\Framework\FactoryDriver; class ApiTransporterFactory extends FactoryDriver { /** - * Function to return a string representaion of the namespace + * Function to return a string representaion of the namespace * that all classes built by the factory should be contained within - * + * * @return string - namespace string */ public function getDriverNamespace() @@ -27,11 +26,10 @@ public function getDriverNamespace() return "\Trucker\Transporters"; } - - /** + /** * Function to return the interface that the driver's produced * by the factory must implement - * + * * @return string */ public function getDriverInterface() @@ -39,12 +37,11 @@ public function getDriverInterface() return "\Trucker\Transporters\TransporterInterface"; } - /** * Function to return a string that should be suffixed * to the studly-cased driver name of all the drivers - * that the factory can return - * + * that the factory can return + * * @return string */ public function getDriverNameSuffix() @@ -52,12 +49,11 @@ public function getDriverNameSuffix() return "Transporter"; } - /** * Function to return a string that should be prefixed * to the studly-cased driver name of all the drivers * that the factory can return - * + * * @return string */ public function getDriverNamePrefix() @@ -68,7 +64,7 @@ public function getDriverNamePrefix() /** * Function to return an array of arguments that should be * passed to the constructor of a new driver instance - * + * * @return array */ public function getDriverArgumentsArray() @@ -77,11 +73,11 @@ public function getDriverArgumentsArray() } /** - * Function to return the string representation of the driver + * Function to return the string representation of the driver * itslef based on a value fetched from the config file. This * function will itself access the config, and return the driver * setting - * + * * @return string */ public function getDriverConfigValue() diff --git a/src/Trucker/Factories/AuthFactory.php b/src/Trucker/Factories/AuthFactory.php index 383d9c2..fbf5a15 100644 --- a/src/Trucker/Factories/AuthFactory.php +++ b/src/Trucker/Factories/AuthFactory.php @@ -10,16 +10,15 @@ */ namespace Trucker\Factories; -use Illuminate\Container\Container; -use Trucker\Framework\FactoryDriver; use Trucker\Facades\Config; +use Trucker\Framework\FactoryDriver; class AuthFactory extends FactoryDriver { /** - * Function to return a string representaion of the namespace + * Function to return a string representaion of the namespace * that all classes built by the factory should be contained within - * + * * @return string - namespace string */ public function getDriverNamespace() @@ -27,11 +26,10 @@ public function getDriverNamespace() return "\Trucker\Requests\Auth"; } - /** * Function to return the interface that the driver's produced * by the factory must implement - * + * * @return string */ public function getDriverInterface() @@ -39,12 +37,11 @@ public function getDriverInterface() return "\Trucker\Requests\Auth\AuthenticationInterface"; } - /** * Function to return a string that should be suffixed * to the studly-cased driver name of all the drivers - * that the factory can return - * + * that the factory can return + * * @return string */ public function getDriverNameSuffix() @@ -52,12 +49,11 @@ public function getDriverNameSuffix() return "Authenticator"; } - /** * Function to return a string that should be prefixed * to the studly-cased driver name of all the drivers * that the factory can return - * + * * @return string */ public function getDriverNamePrefix() @@ -68,7 +64,7 @@ public function getDriverNamePrefix() /** * Function to return an array of arguments that should be * passed to the constructor of a new driver instance - * + * * @return array */ public function getDriverArgumentsArray() @@ -77,11 +73,11 @@ public function getDriverArgumentsArray() } /** - * Function to return the string representation of the driver + * Function to return the string representation of the driver * itslef based on a value fetched from the config file. This * function will itself access the config, and return the driver * setting - * + * * @return string */ public function getDriverConfigValue() diff --git a/src/Trucker/Factories/ErrorHandlerFactory.php b/src/Trucker/Factories/ErrorHandlerFactory.php index 7079e95..3e6348a 100644 --- a/src/Trucker/Factories/ErrorHandlerFactory.php +++ b/src/Trucker/Factories/ErrorHandlerFactory.php @@ -10,16 +10,15 @@ */ namespace Trucker\Factories; -use Illuminate\Container\Container; -use Trucker\Framework\FactoryDriver; use Trucker\Facades\Config; +use Trucker\Framework\FactoryDriver; class ErrorHandlerFactory extends FactoryDriver { /** - * Function to return a string representaion of the namespace + * Function to return a string representaion of the namespace * that all classes built by the factory should be contained within - * + * * @return string - namespace string */ public function getDriverNamespace() @@ -27,11 +26,10 @@ public function getDriverNamespace() return "\Trucker\Responses\ErrorHandlers"; } - /** * Function to return the interface that the driver's produced * by the factory must implement - * + * * @return string */ public function getDriverInterface() @@ -39,12 +37,11 @@ public function getDriverInterface() return "\Trucker\Responses\ErrorHandlers\ErrorHandlerInterface"; } - /** * Function to return a string that should be suffixed * to the studly-cased driver name of all the drivers - * that the factory can return - * + * that the factory can return + * * @return string */ public function getDriverNameSuffix() @@ -52,12 +49,11 @@ public function getDriverNameSuffix() return "ErrorHandler"; } - /** * Function to return a string that should be prefixed * to the studly-cased driver name of all the drivers * that the factory can return - * + * * @return string */ public function getDriverNamePrefix() @@ -68,7 +64,7 @@ public function getDriverNamePrefix() /** * Function to return an array of arguments that should be * passed to the constructor of a new driver instance - * + * * @return array */ public function getDriverArgumentsArray() @@ -77,11 +73,11 @@ public function getDriverArgumentsArray() } /** - * Function to return the string representation of the driver + * Function to return the string representation of the driver * itslef based on a value fetched from the config file. This * function will itself access the config, and return the driver * setting - * + * * @return string */ public function getDriverConfigValue() diff --git a/src/Trucker/Factories/QueryConditionFactory.php b/src/Trucker/Factories/QueryConditionFactory.php index 422b0d5..8d8dc4b 100644 --- a/src/Trucker/Factories/QueryConditionFactory.php +++ b/src/Trucker/Factories/QueryConditionFactory.php @@ -10,17 +10,16 @@ */ namespace Trucker\Factories; -use Illuminate\Container\Container; -use Trucker\Framework\FactoryDriver; use Trucker\Facades\Config; +use Trucker\Framework\FactoryDriver; class QueryConditionFactory extends FactoryDriver { /** - * Function to return a string representaion of the namespace + * Function to return a string representaion of the namespace * that all classes built by the factory should be contained within - * + * * @return string - namespace string */ public function getDriverNamespace() @@ -28,11 +27,10 @@ public function getDriverNamespace() return "\Trucker\Finders\Conditions"; } - - /** + /** * Function to return the interface that the driver's produced * by the factory must implement - * + * * @return string */ public function getDriverInterface() @@ -40,12 +38,11 @@ public function getDriverInterface() return "\Trucker\Finders\Conditions\QueryConditionInterface"; } - /** * Function to return a string that should be suffixed * to the studly-cased driver name of all the drivers - * that the factory can return - * + * that the factory can return + * * @return string */ public function getDriverNameSuffix() @@ -53,12 +50,11 @@ public function getDriverNameSuffix() return "QueryCondition"; } - /** * Function to return a string that should be prefixed * to the studly-cased driver name of all the drivers * that the factory can return - * + * * @return string */ public function getDriverNamePrefix() @@ -69,7 +65,7 @@ public function getDriverNamePrefix() /** * Function to return an array of arguments that should be * passed to the constructor of a new driver instance - * + * * @return array */ public function getDriverArgumentsArray() @@ -78,11 +74,11 @@ public function getDriverArgumentsArray() } /** - * Function to return the string representation of the driver + * Function to return the string representation of the driver * itslef based on a value fetched from the config file. This * function will itself access the config, and return the driver * setting - * + * * @return string */ public function getDriverConfigValue() diff --git a/src/Trucker/Factories/QueryResultOrderFactory.php b/src/Trucker/Factories/QueryResultOrderFactory.php index f4369f7..e71420c 100644 --- a/src/Trucker/Factories/QueryResultOrderFactory.php +++ b/src/Trucker/Factories/QueryResultOrderFactory.php @@ -10,17 +10,16 @@ */ namespace Trucker\Factories; -use Illuminate\Container\Container; -use Trucker\Framework\FactoryDriver; use Trucker\Facades\Config; +use Trucker\Framework\FactoryDriver; class QueryResultOrderFactory extends FactoryDriver { /** - * Function to return a string representaion of the namespace + * Function to return a string representaion of the namespace * that all classes built by the factory should be contained within - * + * * @return string - namespace string */ public function getDriverNamespace() @@ -28,11 +27,10 @@ public function getDriverNamespace() return "\Trucker\Finders\Conditions"; } - - /** + /** * Function to return the interface that the driver's produced * by the factory must implement - * + * * @return string */ public function getDriverInterface() @@ -40,12 +38,11 @@ public function getDriverInterface() return "\Trucker\Finders\Conditions\QueryResultOrderInterface"; } - /** * Function to return a string that should be suffixed * to the studly-cased driver name of all the drivers - * that the factory can return - * + * that the factory can return + * * @return string */ public function getDriverNameSuffix() @@ -53,12 +50,11 @@ public function getDriverNameSuffix() return "ResultOrder"; } - /** * Function to return a string that should be prefixed * to the studly-cased driver name of all the drivers * that the factory can return - * + * * @return string */ public function getDriverNamePrefix() @@ -69,7 +65,7 @@ public function getDriverNamePrefix() /** * Function to return an array of arguments that should be * passed to the constructor of a new driver instance - * + * * @return array */ public function getDriverArgumentsArray() @@ -78,11 +74,11 @@ public function getDriverArgumentsArray() } /** - * Function to return the string representation of the driver + * Function to return the string representation of the driver * itslef based on a value fetched from the config file. This * function will itself access the config, and return the driver * setting - * + * * @return string */ public function getDriverConfigValue() diff --git a/src/Trucker/Factories/RequestFactory.php b/src/Trucker/Factories/RequestFactory.php index b3e0da0..ed25999 100644 --- a/src/Trucker/Factories/RequestFactory.php +++ b/src/Trucker/Factories/RequestFactory.php @@ -10,10 +10,10 @@ */ namespace Trucker\Factories; -use Illuminate\Container\Container; -use Trucker\Framework\FactoryDriver; use Guzzle\Http\Client; +use Illuminate\Container\Container; use Trucker\Facades\Config; +use Trucker\Framework\FactoryDriver; class RequestFactory extends FactoryDriver { @@ -25,7 +25,6 @@ class RequestFactory extends FactoryDriver */ protected $client; - /** * Build a new FactoryDriver * @@ -37,21 +36,20 @@ public function __construct(Container $app) $this->client = new \Guzzle\Http\Client(); } - /** * Getter function to access the HTTP Client - * + * * @return Guzzle\Http\Client */ public function &getClient() { return $this->client; } - + /** - * Function to return a string representaion of the namespace + * Function to return a string representaion of the namespace * that all classes built by the factory should be contained within - * + * * @return string - namespace string */ public function getDriverNamespace() @@ -59,11 +57,10 @@ public function getDriverNamespace() return "\Trucker\Requests"; } - /** * Function to return the interface that the driver's produced * by the factory must implement - * + * * @return string */ public function getDriverInterface() @@ -71,12 +68,11 @@ public function getDriverInterface() return "\Trucker\Requests\RequestableInterface"; } - /** * Function to return a string that should be suffixed * to the studly-cased driver name of all the drivers - * that the factory can return - * + * that the factory can return + * * @return string */ public function getDriverNameSuffix() @@ -84,12 +80,11 @@ public function getDriverNameSuffix() return "Request"; } - /** * Function to return a string that should be prefixed * to the studly-cased driver name of all the drivers * that the factory can return - * + * * @return string */ public function getDriverNamePrefix() @@ -100,7 +95,7 @@ public function getDriverNamePrefix() /** * Function to return an array of arguments that should be * passed to the constructor of a new driver instance - * + * * @return array */ public function getDriverArgumentsArray() @@ -109,11 +104,11 @@ public function getDriverArgumentsArray() } /** - * Function to return the string representation of the driver + * Function to return the string representation of the driver * itslef based on a value fetched from the config file. This * function will itself access the config, and return the driver * setting - * + * * @return string */ public function getDriverConfigValue() diff --git a/src/Trucker/Factories/ResponseInterpreterFactory.php b/src/Trucker/Factories/ResponseInterpreterFactory.php index fe8f820..9629fad 100644 --- a/src/Trucker/Factories/ResponseInterpreterFactory.php +++ b/src/Trucker/Factories/ResponseInterpreterFactory.php @@ -10,16 +10,15 @@ */ namespace Trucker\Factories; -use Illuminate\Container\Container; -use Trucker\Framework\FactoryDriver; use Trucker\Facades\Config; +use Trucker\Framework\FactoryDriver; class ResponseInterpreterFactory extends FactoryDriver { /** - * Function to return a string representaion of the namespace + * Function to return a string representaion of the namespace * that all classes built by the factory should be contained within - * + * * @return string - namespace string */ public function getDriverNamespace() @@ -27,11 +26,10 @@ public function getDriverNamespace() return "\Trucker\Responses\Interpreters"; } - /** * Function to return the interface that the driver's produced * by the factory must implement - * + * * @return string */ public function getDriverInterface() @@ -39,12 +37,11 @@ public function getDriverInterface() return "\Trucker\Responses\Interpreters\ResponseInterpreterInterface"; } - /** * Function to return a string that should be suffixed * to the studly-cased driver name of all the drivers - * that the factory can return - * + * that the factory can return + * * @return string */ public function getDriverNameSuffix() @@ -52,12 +49,11 @@ public function getDriverNameSuffix() return "Interpreter"; } - /** * Function to return a string that should be prefixed * to the studly-cased driver name of all the drivers * that the factory can return - * + * * @return string */ public function getDriverNamePrefix() @@ -68,7 +64,7 @@ public function getDriverNamePrefix() /** * Function to return an array of arguments that should be * passed to the constructor of a new driver instance - * + * * @return array */ public function getDriverArgumentsArray() @@ -77,11 +73,11 @@ public function getDriverArgumentsArray() } /** - * Function to return the string representation of the driver + * Function to return the string representation of the driver * itslef based on a value fetched from the config file. This * function will itself access the config, and return the driver * setting - * + * * @return string */ public function getDriverConfigValue() diff --git a/src/Trucker/Finders/CollectionFinder.php b/src/Trucker/Finders/CollectionFinder.php index 3fbdca8..8efdbfd 100644 --- a/src/Trucker/Finders/CollectionFinder.php +++ b/src/Trucker/Finders/CollectionFinder.php @@ -11,14 +11,14 @@ namespace Trucker\Finders; use Illuminate\Container\Container; +use Trucker\Facades\AuthFactory; +use Trucker\Facades\Config; use Trucker\Facades\RequestFactory; use Trucker\Facades\UrlGenerator; -use Trucker\Facades\Config; -use Trucker\Facades\AuthFactory; -use Trucker\Responses\Collection; use Trucker\Finders\Conditions\QueryConditionInterface; use Trucker\Finders\Conditions\QueryResultOrderInterface; use Trucker\Resource\Model; +use Trucker\Responses\Collection; /** * Class for finding collections of models over the remote API @@ -35,7 +35,6 @@ class CollectionFinder */ protected $app; - /** * Build a new CollectionFinder * @@ -46,11 +45,10 @@ public function __construct(Container $app) $this->app = $app; } - /** * Function to fetch a collection of Trucker\Resource\Model object * from the remote API. - * + * * @param Model $model Instance of entity type being fetched * @param QueryConditionInterface $condition Query conditions for the request * @param QueryResultOrderInterface $resultOrder Result ordering requirements for the request @@ -66,7 +64,7 @@ public function fetch( //get a request object $request = RequestFactory::build(); - + //init the request $request->createRequest( Config::get('request.base_uri'), @@ -124,7 +122,7 @@ public function fetch( //add the instance to the records array $records[] = $instance; - }//end foreach + } //end foreach //create a collection object to return $collection = new Collection($records); diff --git a/src/Trucker/Finders/Conditions/GetArrayParamsQueryCondition.php b/src/Trucker/Finders/Conditions/GetArrayParamsQueryCondition.php index 27def73..999096d 100644 --- a/src/Trucker/Finders/Conditions/GetArrayParamsQueryCondition.php +++ b/src/Trucker/Finders/Conditions/GetArrayParamsQueryCondition.php @@ -15,7 +15,7 @@ /** * Class to manage query conditions for a request, where the - * query conditions are passed as HTTP GET array parameters which are + * query conditions are passed as HTTP GET array parameters which are * nested within a particular parameter name (defined in the config). * The resulting GET params might be something like: * @@ -67,7 +67,7 @@ class GetArrayParamsQueryCondition implements QueryConditionInterface * Collection of conditions, each condition * will be a 3 key array having an entry for * property, operator and value - * + * * @var array */ protected $conditions = []; @@ -75,12 +75,11 @@ class GetArrayParamsQueryCondition implements QueryConditionInterface /** * The logical operator that should be used * to group the conditions herein together - * + * * @var string */ protected $logicalOperator; - /** * Build a new GetArrayParamsQueryCondition * @@ -91,11 +90,10 @@ public function __construct(Container $app) $this->app = $app; } - /** * Function to return a new popuplated instance, * typically this would be called from the Facade. - * + * * @return Trucker\Finders\Conditions\GetArrayParamsQueryCondition */ public function newInstance() @@ -104,10 +102,9 @@ public function newInstance() return $instance; } - /** - * Function to add a query condition - * + * Function to add a query condition + * * @param string $property The field the condition operates on * @param string $operator The operator (=, <, >, <= and so on) * @param string $value The value the condition should match @@ -118,16 +115,15 @@ public function addCondition($property, $operator, $value) $this->conditions[] = [ self::PROPERTY => $property, self::OPERATOR => $operator, - self::VALUE => $value + self::VALUE => $value, ]; } - /** - * Function to set the logical operator for the - * combination of any conditions that have been passed to the + * Function to set the logical operator for the + * combination of any conditions that have been passed to the * addCondition() function - * + * * @param string $operator * @return void */ @@ -142,11 +138,10 @@ public function setLogicalOperator($operator) $this->logicalOperator = $operator; } - /** * Function to get the string representing * the AND logical operator - * + * * @return string */ public function getLogicalOperatorAnd() @@ -154,11 +149,10 @@ public function getLogicalOperatorAnd() return Config::get('query_condition.get_array_params.and_operator'); } - /** * Function to get the string representing * the OR logical operator - * + * * @return string */ public function getLogicalOperatorOr() @@ -166,22 +160,21 @@ public function getLogicalOperatorOr() return Config::get('query_condition.get_array_params.or_operator'); } - /** * Function to add all the conditions that have been * given to the class to a given request object - * + * * @param Guzzle\Http\Message\Request $request Request passed by reference * @return void */ public function addToRequest(&$request) { - $query = $request->getQuery(); - + $query = $request->getQuery(); + $conatiner = Config::get('query_condition.get_array_params.container_parameter'); - $property = Config::get('query_condition.get_array_params.property'); - $operator = Config::get('query_condition.get_array_params.operator'); - $value = Config::get('query_condition.get_array_params.value'); + $property = Config::get('query_condition.get_array_params.property'); + $operator = Config::get('query_condition.get_array_params.operator'); + $value = Config::get('query_condition.get_array_params.value'); $x = 0; foreach ($this->conditions as $condition) { @@ -201,7 +194,7 @@ public function addToRequest(&$request) $x++; - }//end foreach $findConditions + } //end foreach $findConditions if (isset($this->logicalOperator)) { $query->add( @@ -211,21 +204,20 @@ public function addToRequest(&$request) } } - /** * Function to convert the conditions and * logical operator represented in this class * to an array, this is useful for testing - * + * * @return array */ public function toArray() { $conatiner = Config::get('query_condition.get_array_params.container_parameter'); - $property = Config::get('query_condition.get_array_params.property'); - $operator = Config::get('query_condition.get_array_params.operator'); - $value = Config::get('query_condition.get_array_params.value'); + $property = Config::get('query_condition.get_array_params.property'); + $operator = Config::get('query_condition.get_array_params.operator'); + $value = Config::get('query_condition.get_array_params.value'); $params = []; @@ -238,7 +230,7 @@ public function toArray() $x++; - }//end foreach $findConditions + } //end foreach $findConditions if (isset($this->logicalOperator)) { $params[Config::get('query_condition.get_array_params.logical_operator')] = $this->logicalOperator; @@ -247,12 +239,11 @@ public function toArray() return $params; } - /** * Function to convert the conditions and logical operator * represented in this class to a querystring, this is useful * for testing - * + * * @return string */ public function toQueryString() diff --git a/src/Trucker/Finders/Conditions/GetParamsResultOrder.php b/src/Trucker/Finders/Conditions/GetParamsResultOrder.php index a3fcee3..b89ab94 100644 --- a/src/Trucker/Finders/Conditions/GetParamsResultOrder.php +++ b/src/Trucker/Finders/Conditions/GetParamsResultOrder.php @@ -37,7 +37,7 @@ class GetParamsResultOrder implements QueryResultOrderInterface /** * Var to hold the order by field * that the results shoudl be sorted on - * + * * @var string */ protected $orderByField; @@ -45,16 +45,15 @@ class GetParamsResultOrder implements QueryResultOrderInterface /** * Var to hold the order direction * for results to be returned - * + * * @var string */ protected $orderDirection; - /** * Constructor, likely never called in implementation * but rather through the service provider - * + * * @param Container $app */ public function __construct(Container $app) @@ -62,11 +61,10 @@ public function __construct(Container $app) $this->app = $app; } - /** * Function to create a new instance that should * be setup with the IoC Container etc - * + * * @return QueryConditionInterface */ public function newInstance() @@ -75,11 +73,10 @@ public function newInstance() return $instance; } - /** - * Function to set the property which the results + * Function to set the property which the results * should be ordered by - * + * * @param string $propertyName */ public function setOrderByField($propertyName) @@ -87,11 +84,10 @@ public function setOrderByField($propertyName) $this->orderByField = $propertyName; } - /** * Function to set the direction which the results * should be sorted by, ascending, descending. - * + * * @param string $direction */ public function setOrderDirection($direction) @@ -106,11 +102,10 @@ public function setOrderDirection($direction) $this->orderDirection = $direction; } - /** * Getter function to return the string that represents * the ascending sort direction - * + * * @return string */ public function getOrderDirectionAscending() @@ -118,11 +113,10 @@ public function getOrderDirectionAscending() return Config::get('result_order.get_params.order_dir_ascending'); } - /** * Getter function to return the string that represents * the descending sort direction - * + * * @return string */ public function getOrderDirectionDescending() @@ -130,11 +124,10 @@ public function getOrderDirectionDescending() return Config::get('result_order.get_params.order_dir_descending'); } - /** * Function to add all the directives that have been * given to the class to a given request object - * + * * @param Guzzle\Http\Message\Request $request Request passed by reference * @return void */ @@ -157,30 +150,28 @@ public function addToRequest(&$request) } } - /** * Function to convert the directives represented in this class * to an array, this is useful for testing - * + * * @return array */ public function toArray() { - $order_by = Config::get('result_order.get_params.order_by'); + $order_by = Config::get('result_order.get_params.order_by'); $order_dir = Config::get('result_order.get_params.order_dir'); - $params = []; - $params[$order_by] = $this->orderByField; + $params = []; + $params[$order_by] = $this->orderByField; $params[$order_dir] = $this->orderDirection; return $params; } - /** - * Function to convert the directives represented in this class + * Function to convert the directives represented in this class * to a querystring, this is useful for testing - * + * * @return string */ public function toQueryString() diff --git a/src/Trucker/Finders/InstanceFinder.php b/src/Trucker/Finders/InstanceFinder.php index 810c1c7..394d9ee 100644 --- a/src/Trucker/Finders/InstanceFinder.php +++ b/src/Trucker/Finders/InstanceFinder.php @@ -11,11 +11,11 @@ namespace Trucker\Finders; use Illuminate\Container\Container; -use Trucker\Facades\RequestFactory; -use Trucker\Facades\UrlGenerator; -use Trucker\Facades\Config; use Trucker\Facades\AuthFactory; +use Trucker\Facades\Config; +use Trucker\Facades\RequestFactory; use Trucker\Facades\ResponseInterpreterFactory; +use Trucker\Facades\UrlGenerator; /** * Class for finding model instances over the remote API @@ -32,7 +32,6 @@ class InstanceFinder */ protected $app; - /** * Build a new InstanceFinder * @@ -44,7 +43,6 @@ public function __construct(Container $app) $this->app = $app; } - /** * Function to find an instance of an Entity record * @@ -78,14 +76,12 @@ public function fetch($model, $id, $getParams = array()) //actually send the request $response = $request->sendRequest(); - - - if (! ResponseInterpreterFactory::build()->success($response)) { + if (!ResponseInterpreterFactory::build()->success($response)) { return null; } //kraft the response into an object to return - $data = $response->parseResponseToData(); + $data = $response->parseResponseToData(); $instance = new $model($data); //inflate the ID property that should be guarded diff --git a/src/Trucker/Requests/Auth/BasicAuthenticator.php b/src/Trucker/Requests/Auth/BasicAuthenticator.php index 5b930b0..76908ee 100644 --- a/src/Trucker/Requests/Auth/BasicAuthenticator.php +++ b/src/Trucker/Requests/Auth/BasicAuthenticator.php @@ -11,8 +11,8 @@ namespace Trucker\Requests\Auth; use Illuminate\Container\Container; -use Trucker\Requests\Auth\AuthenticationInterface; use Trucker\Facades\Config; +use Trucker\Requests\Auth\AuthenticationInterface; class BasicAuthenticator implements AuthenticationInterface { @@ -23,11 +23,10 @@ class BasicAuthenticator implements AuthenticationInterface */ protected $app; - /** * Constructor, likely never called in implementation * but rather through the Factory - * + * * @param Container $app */ public function __construct(Container $app) @@ -35,11 +34,10 @@ public function __construct(Container $app) $this->app = $app; } - /** * Function to add the necessary authentication * to the request - * + * * @param Guzzle\Http\Message\Request $request Request passed by reference * @return void */ diff --git a/src/Trucker/Requests/RestRequest.php b/src/Trucker/Requests/RestRequest.php index 0b87d20..08f7f38 100644 --- a/src/Trucker/Requests/RestRequest.php +++ b/src/Trucker/Requests/RestRequest.php @@ -10,17 +10,17 @@ */ namespace Trucker\Requests; -use Illuminate\Container\Container; use Guzzle\Http\Client; -use Trucker\Facades\TransporterFactory; -use Trucker\Facades\ResponseInterpreterFactory; -use Trucker\Facades\ErrorHandlerFactory; +use Illuminate\Container\Container; use Trucker\Facades\Config; -use Trucker\Responses\RawResponse; +use Trucker\Facades\ErrorHandlerFactory; +use Trucker\Facades\ResponseInterpreterFactory; +use Trucker\Facades\TransporterFactory; use Trucker\Finders\Conditions\QueryConditionInterface; use Trucker\Finders\Conditions\QueryResultOrderInterface; use Trucker\Requests\Auth\AuthenticationInterface; use Trucker\Resource\Model; +use Trucker\Responses\RawResponse; class RestRequest implements RequestableInterface { @@ -33,8 +33,8 @@ class RestRequest implements RequestableInterface protected $app; /** - * Request client - * + * Request client + * * @var \Guzzle\Http\Client */ protected $client; @@ -47,7 +47,6 @@ class RestRequest implements RequestableInterface */ protected $request; - /** * Build a new RestRequest * @@ -60,10 +59,9 @@ public function __construct(Container $app, $client = null) $this->client = $client == null ? new Client : $client; } - /** * Getter function to access the HTTP Client - * + * * @return \Guzzle\Http\Client */ public function &getClient() @@ -71,7 +69,6 @@ public function &getClient() return $this->client; } - /** * Function to create a Guzzle HTTP request * @@ -110,7 +107,6 @@ public function createRequest($baseUri, $path, $httpMethod = 'GET', $requestHead return $this->request; } - /** * Function to set headers on the request * @@ -124,7 +120,6 @@ public function setHeaders($requestHeaders = array()) } } - /** * Function to set given file parameters * on the request @@ -133,12 +128,11 @@ public function setHeaders($requestHeaders = array()) */ public function setBody($body, $contentType = null) { - if(method_exists($this->request, 'setBody')){ + if (method_exists($this->request, 'setBody')) { $this->request->setBody($body, $contentType); } } - /** * Function to set POST parameters onto the request * @@ -151,7 +145,6 @@ public function setPostParameters($params = array()) } } - /** * Functio to set GET parameters onto the * request @@ -166,7 +159,6 @@ public function setGetParameters($params = array()) } } - /** * Function to set given file parameters * on the request @@ -180,7 +172,6 @@ public function setFileParameters($params = array()) } } - /** * Function to set the entities properties on the * request object taking into account any properties that @@ -217,7 +208,6 @@ public function setTransportLanguage() $transporter->setHeaderOnRequest($this->request); } - /** * Function to add an error handler to the request. This could be used * @@ -245,7 +235,6 @@ function (\Guzzle\Common\Event $event) use ($httpStatus, $stopPropagation, $func ); } - /** * Function to add Query conditions to the request * @@ -257,7 +246,6 @@ public function addQueryCondition(QueryConditionInterface $condition) $condition->addToRequest($this->request); } - /** * Function to add Query result ordering conditions to the request * @@ -269,8 +257,6 @@ public function addQueryResultOrder(QueryResultOrderInterface $resultOrder) $resultOrder->addToRequest($this->request); } - - /** * Function to add authentication to the request * @@ -282,7 +268,6 @@ public function authenticate(AuthenticationInterface $auth) $auth->authenticateRequest($this->request); } - /** * Function to send the request to the remote API * @@ -299,7 +284,6 @@ public function sendRequest() return $this->app->make('trucker.response')->newInstance($this->app, $response); } - /** * Function to execute a raw GET request * @@ -313,7 +297,6 @@ public function rawGet($uri, $params = array(), $headers = array()) return $this->rawRequest($uri, 'GET', array(), $params, array(), $headers); } - /** * Function to execute a raw POST request * @@ -329,7 +312,6 @@ public function rawPost($uri, $params = array(), $getParams = array(), $files = return $this->rawRequest($uri, 'POST', $params, $getParams, $files, $headers); } - /** * Function to execute a raw PUT request * @@ -345,7 +327,6 @@ public function rawPut($uri, $params = array(), $getParams = array(), $files = a return $this->rawRequest($uri, 'PUT', $params, $getParams, $files, $headers); } - /** * Function to execute a raw PATCH request * @@ -361,7 +342,6 @@ public function rawPatch($uri, $params = array(), $getParams = array(), $files = return $this->rawRequest($uri, 'PATCH', $params, $getParams, $files, $headers); } - /** * Function to execute a raw DELETE request * @@ -375,7 +355,6 @@ public function rawDelete($uri, $params = array(), $headers = array()) return $this->rawRequest($uri, 'DELETE', array(), $params, array(), $headers); } - /** * Function to execute a raw request on the base URI with the given uri path * and params @@ -416,10 +395,10 @@ public function rawRequest($uri, $method, $params = array(), $getParams = array( $errors = (array) ErrorHandlerFactory::build()->parseErrors($response); return new RawResponse(false, $response, $errors); - - }//end if + + } //end if return new RawResponse(true, $response); - }//end rawRequest + } //end rawRequest } diff --git a/src/Trucker/Resource/Model.php b/src/Trucker/Resource/Model.php index 211e725..d76ff59 100644 --- a/src/Trucker/Resource/Model.php +++ b/src/Trucker/Resource/Model.php @@ -10,15 +10,15 @@ */ namespace Trucker\Resource; -use Trucker\Facades\Response; -use Trucker\Facades\Instance; +use Trucker\Facades\AuthFactory; use Trucker\Facades\Collection; -use Trucker\Facades\UrlGenerator; use Trucker\Facades\Config; +use Trucker\Facades\ErrorHandlerFactory; +use Trucker\Facades\Instance; use Trucker\Facades\RequestFactory; +use Trucker\Facades\Response; use Trucker\Facades\ResponseInterpreterFactory; -use Trucker\Facades\ErrorHandlerFactory; -use Trucker\Facades\AuthFactory; +use Trucker\Facades\UrlGenerator; use Trucker\Finders\Conditions\QueryConditionInterface; use Trucker\Finders\Conditions\QueryResultOrderInterface; @@ -76,7 +76,7 @@ class Model * * * This value can be nested as a comma separated string as well. - * So you could set something like + * So you could set something like * "Company:company_id,Employee:employee_id,Preference:pref_id" * which would generate * /companies/:company_id/employees/:employee_id/preferences/:pref_id @@ -149,16 +149,13 @@ class Model /** * Portion of a property name that would indicate - * that the value would be Base64 encoded when the + * that the value would be Base64 encoded when the * property is set. - * + * * @var string */ protected $base64Indicator; - - - /** * Constructor used to popuplate the instance with * attribute values @@ -170,7 +167,6 @@ public function __construct($attributes = []) $this->fill($attributes); } - /** * Create a new instance of the given model. * @@ -185,11 +181,9 @@ public function newInstance($attributes = []) $model = new static; $model->fill((array) $attributes); - + return $model; } - - /** * Magic getter function for accessing instance properties @@ -206,7 +200,6 @@ public function __get($key) return null; } - /** * Magic setter function for setting instance properties * @@ -223,19 +216,18 @@ public function __set($property, $value) $fileProperty = str_replace($this->getBase64Indicator(), '', $property); if (in_array($fileProperty, $this->getFileFields())) { $this->handleBase64File($fileProperty, $value); - }//end if file field + } //end if file field } else { $this->properties[$property] = $value; } - }//end __set - + } //end __set /** * Magic unsetter function for unsetting an instance property - * + * * @param string $property Property name * @return void */ @@ -244,14 +236,13 @@ public function __unset($property) if (array_key_exists($property, $this->properties)) { unset($this->properties[$property]); } - }//end __unset - + } //end __unset /** * Getter function to access the * underlying attributes array for the * entity - * + * * @return arrayhttpStatusError */ public function attributes() @@ -259,7 +250,6 @@ public function attributes() return $this->properties; } - /** * Function to return any errors that * may have prevented a save @@ -271,7 +261,6 @@ public function errors() return $this->errors; } - /** * Function to fill an instance's properties from an * array of keys and values @@ -300,7 +289,7 @@ public function fill($attributes = []) $this->handleBase64File($fileProperty, $value); - }//end if file field + } //end if file field } else { @@ -310,12 +299,11 @@ public function fill($attributes = []) $this->properties[$property] = $value; } - }//end if-else base64 - }//end if not guarded - }//end foreach + } //end if-else base64 + } //end if not guarded + } //end foreach } - /** * Function to return an array of properties that should not * be set via mass assignment @@ -334,7 +322,6 @@ public function getGuardedAttributes() return $attrs; } - /** * Function to return an array of properties that will * accept a file path @@ -347,7 +334,6 @@ public function getFileFields() return array_filter($attrs); } - /** * Function to take base64 encoded image and write it to a * temp file, then add that file to the property list to get @@ -365,7 +351,7 @@ protected function handleBase64File($property, $value) $ext = end($mimeExp); $output_file = implode( DIRECTORY_SEPARATOR, - array($this->getScratchDiskLocation(), uniqid("tmp_{$property}_").".$ext") + array($this->getScratchDiskLocation(), uniqid("tmp_{$property}_") . ".$ext") ); $f = fopen($output_file, "wb"); fwrite($f, $image); @@ -374,8 +360,7 @@ protected function handleBase64File($property, $value) $this->postRequestCleanUp[] = $output_file; $this->{$property} = $output_file; - }//end handleBase64File - + } //end handleBase64File /** * Function to get the instance ID, returns false if there @@ -392,10 +377,9 @@ public function getId() return false; } - /** * Getter function to return the identity property - * + * * @return string */ public function getIdentityProperty() @@ -403,10 +387,9 @@ public function getIdentityProperty() return $this->identityProperty ?: Config::get('resource.identity_property'); } - /** * Getter function to return the scratch disk location - * + * * @return string */ public function getScratchDiskLocation() @@ -414,10 +397,9 @@ public function getScratchDiskLocation() return $this->scratchDiskLocation ?: Config::get('resource.scratch_disk_location'); } - /** * Getter function to return base64 param indicator - * + * * @return string */ public function getBase64Indicator() @@ -425,11 +407,10 @@ public function getBase64Indicator() return $this->base64Indicator ?: Config::get('resource.base_64_property_indication'); } - /** * Function to return an array of property names * that are read only - * + * * @return array */ public function getReadOnlyFields() @@ -438,11 +419,10 @@ public function getReadOnlyFields() return $cantSet; } - /** * Function to get an associative array of fields * with their values that are NOT read only - * + * * @return array */ public function getMutableFields() @@ -461,7 +441,6 @@ public function getMutableFields() return $mutableFields; } - /** * Function to interpret the URI resource name based on the class called. * Generally this would be the name of the class. @@ -481,11 +460,10 @@ public function getResourceName() return $klass; } - /** * Getter function to return a URI * that has been manually set - * + * * @return string */ public function getURI() @@ -493,7 +471,6 @@ public function getURI() return $this->uri ?: null; } - /** * Function to find an instance of an Entity record * @@ -508,10 +485,9 @@ public static function find($id, $getParams = [], Model $instance = null) return Instance::fetch($m, $id, $getParams); } - /** * Function to find a collection of Entity records from the remote api - * + * * @param QueryConditionInterface $condition query conditions * @param QueryResultOrderInterface $resultOrder result ordering info * @param array $getParams additional GET params @@ -522,10 +498,9 @@ public static function all( QueryResultOrderInterface $resultOrder = null, array $getParams = [] ) { - return Collection::fetch(new static, $condition, $resultOrder, $getParams); + return Collection::fetch(new static , $condition, $resultOrder, $getParams); } - /** * Function to handle persistance of the entity across the * remote API. Function will handle either a CREATE or UPDATE @@ -555,7 +530,7 @@ public function save() Config::get('request.base_uri'), UrlGenerator::getDeleteUri( $this, - [':'.$this->getIdentityProperty() => $this->getId()] + [':' . $this->getIdentityProperty() => $this->getId()] ), 'PUT', [], //no extra headers @@ -584,7 +559,7 @@ public function save() $this->doPostRequestCleanUp(); return false; - }//end if + } //end if //get the response and inflate from that $data = $response->parseResponseToData(); @@ -601,7 +576,6 @@ public function save() return true; } - /** * Function to delete an existing entity * @@ -617,7 +591,7 @@ public function destroy() Config::get('request.base_uri'), UrlGenerator::getDeleteUri( $this, - [':'.$this->getIdentityProperty() => $this->getId()] + [':' . $this->getIdentityProperty() => $this->getId()] ), 'DELETE', [], //no extra headers @@ -647,12 +621,11 @@ public function destroy() //get the errors and set them to our local collection $this->errors = ErrorHandlerFactory::build()->parseErrors($response); - }//end if-else + } //end if-else return false; } - /** * Function to clean up any temp files written for a request * diff --git a/src/Trucker/Responses/ErrorHandlers/ParameterKeyErrorHandler.php b/src/Trucker/Responses/ErrorHandlers/ParameterKeyErrorHandler.php index e8ca3ce..e48ea99 100644 --- a/src/Trucker/Responses/ErrorHandlers/ParameterKeyErrorHandler.php +++ b/src/Trucker/Responses/ErrorHandlers/ParameterKeyErrorHandler.php @@ -22,11 +22,10 @@ class ParameterKeyErrorHandler implements ErrorHandlerInterface */ protected $app; - /** * Constructor to setup the interpreter - * - * @param Container $app + * + * @param Container $app */ public function __construct(Container $app) { @@ -34,15 +33,15 @@ public function __construct(Container $app) } /** - * Function to take the response object and return + * Function to take the response object and return * an array of errors - * + * * @param Trucker\Responses\Response $response - response object * @return array - array of string error messages */ public function parseErrors(\Trucker\Responses\Response $response) { - $result = $response->parseResponseStringToObject(); + $result = $response->parseResponseStringToObject(); $error_key = Config::get('error_handler.errors_key'); if (property_exists($result, $error_key)) { diff --git a/src/Trucker/Responses/Interpreters/HttpStatusCodeInterpreter.php b/src/Trucker/Responses/Interpreters/HttpStatusCodeInterpreter.php index adad423..0c77ab2 100644 --- a/src/Trucker/Responses/Interpreters/HttpStatusCodeInterpreter.php +++ b/src/Trucker/Responses/Interpreters/HttpStatusCodeInterpreter.php @@ -24,7 +24,6 @@ class HttpStatusCodeInterpreter implements ResponseInterpreterInterface */ protected $app; - /** * Constructor to setup the interpreter * @@ -35,7 +34,6 @@ public function __construct(Container $app) $this->app = $app; } - /** * Function to return a boolean value indicating whether * the request was successful or not @@ -48,7 +46,6 @@ public function success(BaseResponse $response) return $this->matchesStatus('response.http_status.success', $response->getStatusCode()); } - /** * Function to return a boolean value indicating whether * the request indicated something was not found @@ -61,7 +58,6 @@ public function notFound(BaseResponse $response) return $this->matchesStatus('response.http_status.not_found', $response->getStatusCode()); } - /** * Function to return a boolean value indicating whether * the request was considered invalid @@ -74,7 +70,6 @@ public function invalid(BaseResponse $response) return $this->matchesStatus('response.http_status.invalid', $response->getStatusCode()); } - /** * Function to return a boolean value indicating whether * the request was ended in an error state diff --git a/src/Trucker/Support/ConfigManager.php b/src/Trucker/Support/ConfigManager.php index 2612dd2..ffc1253 100644 --- a/src/Trucker/Support/ConfigManager.php +++ b/src/Trucker/Support/ConfigManager.php @@ -21,7 +21,6 @@ class ConfigManager */ protected $app; - /** * Build a new ConfigManager * @@ -32,10 +31,9 @@ public function __construct(Container $app) $this->app = $app; } - /** * Getter to access the IoC Container - * + * * @return Container */ public function getApp() @@ -43,10 +41,9 @@ public function getApp() return $this->app; } - /** * Setter for the IoC Container - * + * * @param Container * @return void */ @@ -55,7 +52,6 @@ public function setApp($app) $this->app = $app; } - /** * Get an option from the config file * @@ -65,10 +61,9 @@ public function setApp($app) */ public function get($option) { - return $this->app['config']->get('trucker::'.$option); + return $this->app['config']->get('trucker.' . $option); } - /** * Set an option to the config file * @@ -79,10 +74,9 @@ public function get($option) */ public function set($option, $value) { - return $this->app['config']->set('trucker::'.$option, $value); + return $this->app['config']->set('trucker.' . $option, $value); } - /** * Determine if a config option contains a specific * diff --git a/src/Trucker/TruckerServiceProvider.php b/src/Trucker/TruckerServiceProvider.php index 7f8dfe7..8b57080 100644 --- a/src/Trucker/TruckerServiceProvider.php +++ b/src/Trucker/TruckerServiceProvider.php @@ -15,11 +15,11 @@ use Illuminate\Container\Container; use Illuminate\Support\ServiceProvider; - /** - * Service Provider for interacting with the Trucker class - * - * @author Brian Webb - */ +/** + * Service Provider for interacting with the Trucker class + * + * @author Brian Webb + */ class TruckerServiceProvider extends ServiceProvider { @@ -77,7 +77,6 @@ public static function make($app = null) return $app; } - /** * Bind the Trucker paths * @@ -97,7 +96,6 @@ public function bindPaths(Container $app) return $app; } - /** * Bind the core classes * @@ -111,7 +109,7 @@ public function bindCoreClasses(Container $app) $app->bindIf('config', function ($app) { - $fileloader = new FileLoader($app['files'], __DIR__.'/../config'); + $fileloader = new FileLoader($app['files'], __DIR__ . '/../config'); return new Repository($fileloader, 'config'); @@ -153,10 +151,9 @@ public function bindClasses(Container $app) }); $app->bind('trucker.model', function ($app) { - return new Resource\Model(); + return new Resource\Model(); }); - //Factories $app->bind('trucker.conditions', function ($app) { return new Factories\QueryConditionFactory($app); @@ -202,25 +199,11 @@ public function bindClasses(Container $app) */ protected function registerConfig(Container $app) { - // Register config file(filename) - $app['config']->package('indatus/trucker', __DIR__.'/../config'); - $app['config']->getLoader(); - - - // Register custom config - $custom = $app['path.trucker.config']; - if (file_exists($custom)) { - $app['config']->afterLoading('trucker', function ($me, $group, $items) use ($custom) { - $customItems = $custom.'/'.$group.'.php'; - if (!file_exists($customItems)) { - return $items; - } + $this->publishes([ + __DIR__ . '/../config/trucker.php' => $this->app['path.trucker.config'] . DIRECTORY_SEPARATOR . 'trucker.php' + ]); - $customItems = include $customItems; - - return array_replace_recursive($items, $customItems); - }); - } + $this->mergeConfigFrom(__DIR__ . '/../config/trucker.php', 'trucker'); return $app; } diff --git a/src/config/auth.php b/src/config/auth.php deleted file mode 100644 index c7ee27f..0000000 --- a/src/config/auth.php +++ /dev/null @@ -1,28 +0,0 @@ - null, - - //credentials for HTTP Basic Authentication - 'basic' => [ - 'username' => '{basic_username}', - 'password' => '{basic_password}', - ], - -); diff --git a/src/config/error_handler.php b/src/config/error_handler.php deleted file mode 100644 index 11e4108..0000000 --- a/src/config/error_handler.php +++ /dev/null @@ -1,37 +0,0 @@ - 'array_response', - - /* - |-------------------------------------------------------------------------- - | API Errors Key - |-------------------------------------------------------------------------- - | - | When returning a response for an API action this element may contain a - | string or an array of errors that prevented the success of the request. - | - */ - - 'errors_key' => null, - -); diff --git a/src/config/query_condition.php b/src/config/query_condition.php deleted file mode 100644 index 42d59c5..0000000 --- a/src/config/query_condition.php +++ /dev/null @@ -1,73 +0,0 @@ - 'get_array_params', - - - /* - |-------------------------------------------------------------------------- - | Get Array Params Driver Config - |-------------------------------------------------------------------------- - | - | Config values that are specific to the 'get_array_params' driver - | - */ - - 'get_array_params' => [ - - // The request parameter which will contain the array of search conditions - 'container_parameter' => 'search', - - // The name of the parameter key used to identify an attribute - // of a remote entity - 'property' => 'property', - - // Name of the parameter key used to specify a search rule operator - // i.e.: = >= <= != LIKE - 'operator' => 'operator', - - // Name of the parameter key used to identify an entity value - // when providing search conditions - 'value' => 'value', - - // Name of the parameter key used to identify how search criteria - // should be combined when multiples are present - 'logical_operator' => 'logical_operator', - - // Name of the parameter value for specifying "AND" search rule - // combination behavior - 'and_operator' => 'AND', - - // Name of the parameter value for specifying "OR" search rule - // combination behavior - 'or_operator' => 'OR', - - ], - -); diff --git a/src/config/request.php b/src/config/request.php deleted file mode 100644 index f16bf79..0000000 --- a/src/config/request.php +++ /dev/null @@ -1,50 +0,0 @@ - 'http://example.com', - - /* - |-------------------------------------------------------------------------- - | HTTP Request Driver - |-------------------------------------------------------------------------- - | - | This parameter specifies the driver to use for making HTTP requests to - | the remote API. The driver handles how the requests are made, formatted etc. - | - | Supported Options: rest - | - | rest - The rest driver makes HTTP request using GET, PUT, POST and DELETE - | HTTP methods to indicate what type of CRUD operation should be completed. - | Optional usage of the http_method_param config option can also be used. - | - */ - - 'driver' => 'rest', - - /* - |-------------------------------------------------------------------------- - | HTTP method request parameter - |-------------------------------------------------------------------------- - | - | This is a parameter to send with the request that will contain - | a string disclosing the desired HTTP method ('put', 'post', 'patch', - | 'delete'). If specified PUT, POST, PATCH and DELETE requests will - | all be made as a POST and the given parameter will be added - | with the http method as it's value. An example might be "_method". - | - | Otherwise a true PUT, POST, PATCH or DELETE request will be made - | - */ - - 'http_method_param' => null, - -); diff --git a/src/config/resource.php b/src/config/resource.php deleted file mode 100644 index 7aaa57c..0000000 --- a/src/config/resource.php +++ /dev/null @@ -1,67 +0,0 @@ - 'id', - - /* - |-------------------------------------------------------------------------- - | API Collection Key - |-------------------------------------------------------------------------- - | - | When returning a collection of items ( /products for example ) if your API - | provides the collection within a sub element of the response it can be defined - | here. - | - */ - - 'collection_key' => null, - - /* - |-------------------------------------------------------------------------- - | Base64 Property Indication - |-------------------------------------------------------------------------- - | - | When working with an entity that will have properties which contain a - | file the property's value may be set as a Base64 encoded string that - | contains the file contents. Before sending to the API endpoint the - | Base64 string will be written to a file at the scratch_disk_location, - | then added to the HTTP Request using HTTP-Chunk-Encoding. - | - | This config setting provides a way to indicate that the property value - | to be set contains Base64 encoded content. The indication can be anywhere - | in the property name. - | - | Example: ( 'base_64_property_indication' => '_base64' ) - | - | $instance->avatar_base64 = $base64EncodedAvatarImageString; - | echo $instance->avatar; // => /tmp/tmp_avatar_52dad37453c67.jpg - | - */ - - 'base_64_property_indication' => '_base64', - - /* - |-------------------------------------------------------------------------- - | Scratch Disk location - |-------------------------------------------------------------------------- - | - | This is a filesystem path where temporary files could be written if needed. - | - | An example would be an Entity attribute that is a file (via base64 encoded - | string). The file would be written to the scratch disk before sending to - | the endpoint, then sent with the request via HTTP chunked transfer encoding. - | - */ - - 'scratch_disk_location' => '/tmp', - -); diff --git a/src/config/response.php b/src/config/response.php deleted file mode 100644 index 739ba18..0000000 --- a/src/config/response.php +++ /dev/null @@ -1,46 +0,0 @@ - 'http_status_code', - - /* - |-------------------------------------------------------------------------- - | HTTP Status Codes - |-------------------------------------------------------------------------- - | - | When making API requests the HTTP Status code returned with the data will - | be used to determine the success or error of the request. - | - */ - - 'http_status' => array( - - //successful request - 'success' => [200, 201], - - //not found - 'not_found' => 404, - - //invalid request. i.e. an entity couldn't be saved - 'invalid' => 422, - - //an error was encountered when processing the request - 'error' => 500, - - ), - -); diff --git a/src/config/result_order.php b/src/config/result_order.php deleted file mode 100644 index e15b341..0000000 --- a/src/config/result_order.php +++ /dev/null @@ -1,49 +0,0 @@ - 'get_params', - - /* - |-------------------------------------------------------------------------- - | Get Params Driver Config - |-------------------------------------------------------------------------- - | - | Config values that are specific to the 'get_params' driver - | - */ - - 'get_params' => [ - - // Name of the parameter key used to identify the property to order - // search results by - 'order_by' => 'order_by', - - // Name of the parameter key used to identify the order direction - // of search results when providing the 'order_by' parameter - 'order_dir' => 'order_dir', - - // Name of the parameter value for specifying ascending result ordering - 'order_dir_ascending' => 'ASC', - - // Name of the parameter value for specifying descending result ordering - 'order_dir_descending' => 'DESC', - - ], - -); diff --git a/src/config/transporter.php b/src/config/transporter.php deleted file mode 100644 index 6264bbd..0000000 --- a/src/config/transporter.php +++ /dev/null @@ -1,17 +0,0 @@ - 'json', - -); diff --git a/src/config/trucker.php b/src/config/trucker.php new file mode 100644 index 0000000..9dcde59 --- /dev/null +++ b/src/config/trucker.php @@ -0,0 +1,377 @@ + array( + + /* + |-------------------------------------------------------------------------- + | Authentication Driver + |-------------------------------------------------------------------------- + | + | This parameter specifies the driver to use for authenticating requests + | with the remote API. + | + | Supported Options: basic + | + | basic - This driver will use HTTP Basic Authentication, and set the + | `auth.basic.username` and `auth.basic.password` config values + | on the request. + | + | + */ + + 'driver' => null, + + //credentials for HTTP Basic Authentication + 'basic' => [ + 'username' => '{basic_username}', + 'password' => '{basic_password}', + ], + + ), + + 'error_handler' => array( + + /* + |-------------------------------------------------------------------------- + | Error Handler Driver + |-------------------------------------------------------------------------- + | + | This parameter specifies the driver to use for interpreting error messages + | provided by the remote API. + | + | Supported Options: array_response, parameter_key + | + | + | array_response - This driver assumes that when there is an error any error + | messages will be given as the full response body as an array. + | + | parameter_key - This driver uses finds the response parameter with a key + | that matches what is defined in `errors_key` and parses the + | error messages contained therein. + | + */ + + 'driver' => 'array_response', + + /* + |-------------------------------------------------------------------------- + | API Errors Key + |-------------------------------------------------------------------------- + | + | When returning a response for an API action this element may contain a + | string or an array of errors that prevented the success of the request. + | + */ + + 'errors_key' => null, + + ), + + 'query_condition' => array( + + /* + |-------------------------------------------------------------------------- + | Collection Query Condition Driver + |-------------------------------------------------------------------------- + | + | This setting tells Trucker how to give directives to the remote API which + | govern how conditions on a collection fetch shoud be conveyed. + | + | Supported Options: + | + | get_array - This option will send the collection query conditions as an + | array of GET parameters nested under the search.container_parameter + | parameter defined in the config. The resulting GET parameters + | may look something like: + | + | search[0][property]=someProperty + | search[0][operator]=< + | search[0][value]=1234 + | search[1][property]=anotherProperty + | search[1][operator]=LIKE + | search[1][value]=someString + | logical_operator=AND + | + | + | + */ + + 'driver' => 'get_array_params', + + /* + |-------------------------------------------------------------------------- + | Get Array Params Driver Config + |-------------------------------------------------------------------------- + | + | Config values that are specific to the 'get_array_params' driver + | + */ + + 'get_array_params' => [ + + // The request parameter which will contain the array of search conditions + 'container_parameter' => 'search', + + // The name of the parameter key used to identify an attribute + // of a remote entity + 'property' => 'property', + + // Name of the parameter key used to specify a search rule operator + // i.e.: = >= <= != LIKE + 'operator' => 'operator', + + // Name of the parameter key used to identify an entity value + // when providing search conditions + 'value' => 'value', + + // Name of the parameter key used to identify how search criteria + // should be combined when multiples are present + 'logical_operator' => 'logical_operator', + + // Name of the parameter value for specifying "AND" search rule + // combination behavior + 'and_operator' => 'AND', + + // Name of the parameter value for specifying "OR" search rule + // combination behavior + 'or_operator' => 'OR', + + ], + + ), + + 'request' => array( + + /* + |-------------------------------------------------------------------------- + | API endpoint URI + |-------------------------------------------------------------------------- + | + | This is the base URI that your API requests will be made to. + | It should be in a format such as http://my-endpoint.com + | + */ + + 'base_uri' => 'http://example.com', + + /* + |-------------------------------------------------------------------------- + | HTTP Request Driver + |-------------------------------------------------------------------------- + | + | This parameter specifies the driver to use for making HTTP requests to + | the remote API. The driver handles how the requests are made, formatted etc. + | + | Supported Options: rest + | + | rest - The rest driver makes HTTP request using GET, PUT, POST and DELETE + | HTTP methods to indicate what type of CRUD operation should be completed. + | Optional usage of the http_method_param config option can also be used. + | + */ + + 'driver' => 'rest', + + /* + |-------------------------------------------------------------------------- + | HTTP method request parameter + |-------------------------------------------------------------------------- + | + | This is a parameter to send with the request that will contain + | a string disclosing the desired HTTP method ('put', 'post', 'patch', + | 'delete'). If specified PUT, POST, PATCH and DELETE requests will + | all be made as a POST and the given parameter will be added + | with the http method as it's value. An example might be "_method". + | + | Otherwise a true PUT, POST, PATCH or DELETE request will be made + | + */ + + 'http_method_param' => null, + + ), + + 'response' => array( + + /* + |-------------------------------------------------------------------------- + | Response Interpreter Driver + |-------------------------------------------------------------------------- + | + | This parameter specifies the driver to use for interpreting API responses + | as successful, invalid, error etc. + | + | Supported Options: http_status_code + | + | http_status_code - This driver uses status codes set in the `http_status` + | config section. + | + */ + + 'driver' => 'http_status_code', + + /* + |-------------------------------------------------------------------------- + | HTTP Status Codes + |-------------------------------------------------------------------------- + | + | When making API requests the HTTP Status code returned with the data will + | be used to determine the success or error of the request. + | + */ + + 'http_status' => array( + + //successful request + 'success' => [200, 201], + + //not found + 'not_found' => 404, + + //invalid request. i.e. an entity couldn't be saved + 'invalid' => 422, + + //an error was encountered when processing the request + 'error' => 500, + + ), + + ), + + 'resource' => array( + + /* + |-------------------------------------------------------------------------- + | Resource Identity Property + |-------------------------------------------------------------------------- + | + | This setting defines the response property that contains a remote resource's + | unique identity property. + | + */ + + 'identity_property' => 'id', + + /* + |-------------------------------------------------------------------------- + | API Collection Key + |-------------------------------------------------------------------------- + | + | When returning a collection of items ( /products for example ) if your API + | provides the collection within a sub element of the response it can be defined + | here. + | + */ + + 'collection_key' => null, + + /* + |-------------------------------------------------------------------------- + | Base64 Property Indication + |-------------------------------------------------------------------------- + | + | When working with an entity that will have properties which contain a + | file the property's value may be set as a Base64 encoded string that + | contains the file contents. Before sending to the API endpoint the + | Base64 string will be written to a file at the scratch_disk_location, + | then added to the HTTP Request using HTTP-Chunk-Encoding. + | + | This config setting provides a way to indicate that the property value + | to be set contains Base64 encoded content. The indication can be anywhere + | in the property name. + | + | Example: ( 'base_64_property_indication' => '_base64' ) + | + | $instance->avatar_base64 = $base64EncodedAvatarImageString; + | echo $instance->avatar; // => /tmp/tmp_avatar_52dad37453c67.jpg + | + */ + + 'base_64_property_indication' => '_base64', + + /* + |-------------------------------------------------------------------------- + | Scratch Disk location + |-------------------------------------------------------------------------- + | + | This is a filesystem path where temporary files could be written if needed. + | + | An example would be an Entity attribute that is a file (via base64 encoded + | string). The file would be written to the scratch disk before sending to + | the endpoint, then sent with the request via HTTP chunked transfer encoding. + | + */ + + 'scratch_disk_location' => '/tmp', + + ), + + 'result_order' => array( + + /* + |-------------------------------------------------------------------------- + | Collection Result Order Driver + |-------------------------------------------------------------------------- + | + | This setting tells Trucker how give directives to the remote API + | which govern how collection results should be ordered. + | + | Supported Options: + | + | get_param - This option will send the property to order results by, + | and the sort direction as GET parameters on the request. + | The parameters are specified in search.order_by and + | search.order_dir + | + */ + + 'driver' => 'get_params', + + /* + |-------------------------------------------------------------------------- + | Get Params Driver Config + |-------------------------------------------------------------------------- + | + | Config values that are specific to the 'get_params' driver + | + */ + + 'get_params' => [ + + // Name of the parameter key used to identify the property to order + // search results by + 'order_by' => 'order_by', + + // Name of the parameter key used to identify the order direction + // of search results when providing the 'order_by' parameter + 'order_dir' => 'order_dir', + + // Name of the parameter value for specifying ascending result ordering + 'order_dir_ascending' => 'ASC', + + // Name of the parameter value for specifying descending result ordering + 'order_dir_descending' => 'DESC', + + ], + + ), + + 'transporter' => array( + + /* + |-------------------------------------------------------------------------- + | API Transport Method + |-------------------------------------------------------------------------- + | + | This setting defines the transport method for data to and from the remote + | API endpoint. + | + | Supported methods are: json + | + */ + + 'driver' => 'json', + + ), +]; diff --git a/tests/BootstrapperTest.php b/tests/BootstrapperTest.php index 96a05f3..c5cb794 100644 --- a/tests/BootstrapperTest.php +++ b/tests/BootstrapperTest.php @@ -90,6 +90,6 @@ public function testCanReplaceStubsInConfigurationFile() $this->bootstrapper->updateConfiguration($path, array('basic_username' => 'foo')); $this->assertFileExists(__DIR__.'/../.trucker'); - $this->assertContains('foo', file_get_contents(__DIR__.'/../.trucker/auth.php')); + $this->assertContains('foo', file_get_contents(__DIR__.'/../.trucker/trucker.php')); } } diff --git a/tests/Finders/CollectionFinderTest.php b/tests/Finders/CollectionFinderTest.php index dc39525..0640e6c 100644 --- a/tests/Finders/CollectionFinderTest.php +++ b/tests/Finders/CollectionFinderTest.php @@ -1,10 +1,10 @@ getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->makeGuzzleAssertions('GET', $base_uri, $uri); @@ -40,8 +40,6 @@ public function testFindAll() $this->assertEquals('John Doe', $found->first()->name); } - - public function testFindAllWithGetParams() { $this->setupIndividualTest($this->getTestOptions()); @@ -50,9 +48,9 @@ public function testFindAllWithGetParams() $found = User::all(null, null, $queryParams); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->makeGuzzleAssertions('GET', $base_uri, $uri, $queryParams); @@ -65,7 +63,6 @@ public function testFindAllWithGetParams() $this->assertEquals('John Doe', $found->first()->name); } - public function testFindAllWithGetParamsQueryConditions() { $this->setupIndividualTest($this->getTestOptions()); @@ -100,9 +97,9 @@ public function testFindAllWithGetParamsQueryConditions() $found = User::all($conditions); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->makeGuzzleAssertions('GET', $base_uri, $uri, $conditions->toArray()); @@ -115,7 +112,6 @@ public function testFindAllWithGetParamsQueryConditions() $this->assertEquals('John Doe', $found->first()->name); } - public function testFindAllWithGetParamsQueryConditionsAndGetOrderResults() { $this->setupIndividualTest($this->getTestOptions()); @@ -148,9 +144,9 @@ public function testFindAllWithGetParamsQueryConditionsAndGetOrderResults() $getParams = array_merge($conditions->toArray(), $order->toArray()); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->makeGuzzleAssertions('GET', $base_uri, $uri, $getParams); @@ -163,12 +159,11 @@ public function testFindAllWithGetParamsQueryConditionsAndGetOrderResults() $this->assertEquals('John Doe', $found->first()->name); } - public function testFindAllWithCollectionKeyOption() { $config = [ - 'trucker::request.base_uri' => 'http://example.com', - 'trucker::resource.collection_key' => 'collection' + 'trucker::request.base_uri' => 'http://example.com', + 'trucker::resource.collection_key' => 'collection', ]; $this->setupIndividualTest( @@ -181,9 +176,9 @@ public function testFindAllWithCollectionKeyOption() $found = User::all(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->makeGuzzleAssertions('GET', $base_uri, $uri); @@ -201,20 +196,18 @@ public function testFindAllWithCollectionKeyOption() ); } - - /** * Helper function to get commonly used testing data - * + * * @return array */ private function getTestOptions($collectionKey = null) { //some vars for our test - $data = []; - $data['uri'] = '/users'; - $data['base_uri'] = 'http://example.com'; - $data['queryParams'] = ['foo' => 'bar', 'biz' => 'bang']; + $data = []; + $data['uri'] = '/users'; + $data['base_uri'] = 'http://example.com'; + $data['queryParams'] = ['foo' => 'bar', 'biz' => 'bang']; $data['response_body'] = json_encode( $this->getRecords($collectionKey) ); @@ -222,34 +215,33 @@ private function getTestOptions($collectionKey = null) return $data; } - private function getRecords($collectionKey = null) { $records = [ [ - 'id' => 1234, - 'name' => 'John Doe', - 'email' => 'jdoe@noboddy.com' + 'id' => 1234, + 'name' => 'John Doe', + 'email' => 'jdoe@noboddy.com', ], [ - 'id' => 1235, - 'name' => 'Sammy Smith', - 'email' => 'sammys@mysite.com' + 'id' => 1235, + 'name' => 'Sammy Smith', + 'email' => 'sammys@mysite.com', ], [ - 'id' => 1236, - 'name' => 'Tommy Jingles', - 'email' => 'tjingles@gmail.com' + 'id' => 1236, + 'name' => 'Tommy Jingles', + 'email' => 'tjingles@gmail.com', ], [ - 'id' => 1237, - 'name' => 'Brent Sanders', - 'email' => 'bsanders@yahoo.com' + 'id' => 1237, + 'name' => 'Brent Sanders', + 'email' => 'bsanders@yahoo.com', ], [ - 'id' => 1238, - 'name' => 'Michael Blanton', - 'email' => 'mblanton@outlook.com' + 'id' => 1238, + 'name' => 'Michael Blanton', + 'email' => 'mblanton@outlook.com', ], ]; @@ -262,14 +254,13 @@ private function getRecords($collectionKey = null) return $result; } - /** - * Function to mock a request for us and + * Function to mock a request for us and * expect test data - * - * @param array $options + * + * @param array $options * @param array $config_overrides - * @param int $status + * @param int $status * @param string $content_type * @return void */ @@ -298,8 +289,8 @@ private function setupIndividualTest( //HTTP response headers // [ - 'Location' => $base_uri.'/'.$uri, - 'Content-Type' => $content_type + 'Location' => $base_uri . '/' . $uri, + 'Content-Type' => $content_type, ], // //response to return diff --git a/tests/Models/ModelTest.php b/tests/Models/ModelTest.php index eb4f1ea..ee99cd4 100644 --- a/tests/Models/ModelTest.php +++ b/tests/Models/ModelTest.php @@ -1,31 +1,25 @@ app->make('trucker.model'); $this->assertEquals($t->attributes(), array()); } - - public function testFacade() { $this->assertEquals(Trucker::attributes(), array()); } - - public function testSimplePropertyGettersAndSetters() { $t = $this->app->make('trucker.model'); @@ -34,8 +28,6 @@ public function testSimplePropertyGettersAndSetters() $this->assertTrue(array_key_exists('foo', $t->attributes()), 'set value missing from attributes array'); } - - public function testFillWithGuarded() { //TEST fill via constructor @@ -50,10 +42,9 @@ public function testFillWithGuarded() $this->assertEquals('bang', $t->biz); $this->assertTrue(array_key_exists('biz', $t->attributes()), 'set value missing from attributes array'); - //simulate that the guarded field was set in the class $this->simulateSetInaccessableProperty($t, 'guarded', 'one,two'); - + //TEST fill with guarded properties $t->fill(['one' => 1, 'two' => 2, 'three' => 3]); $this->assertEquals(null, $t->one); @@ -61,15 +52,13 @@ public function testFillWithGuarded() $this->assertEquals(3, $t->three); } - - public function testBase64PropertySetterMutators() { $t = Trucker::newInstance(); //TEST fill with base64 property $this->simulateSetInaccessableProperty($t, 'fileFields', 'meme,other_meme'); - $testImagePath = __DIR__.'/../fixtures/test-all-things.jpg'; + $testImagePath = __DIR__ . '/../fixtures/test-all-things.jpg'; $md5 = md5_file($testImagePath); $imgData = file_get_contents($testImagePath); $base64Image = base64_encode($imgData); @@ -93,16 +82,14 @@ public function testBase64PropertySetterMutators() unlink($tmp2); //remove the test generated file } - - public function testPostRequestCleanUp() { $t = Trucker::newInstance(); //create our test files and assert that they exist - $path = __DIR__.'/../fixtures'; - $tmp1 = $path.'/'.time().'-'.rand().'.txt'; - $tmp2 = $path.'/'.time().'-'.rand().'.txt'; + $path = __DIR__ . '/../fixtures'; + $tmp1 = $path . '/' . time() . '-' . rand() . '.txt'; + $tmp2 = $path . '/' . time() . '-' . rand() . '.txt'; file_put_contents($tmp1, "Data for {$tmp1}"); file_put_contents($tmp2, "Data for {$tmp1}"); @@ -118,8 +105,6 @@ public function testPostRequestCleanUp() $this->assertFalse(file_exists($tmp2), 'Expected {$tmp2} to have been unlinked'); } - - public function testGetUri() { $u = Trucker::newInstance(); @@ -130,8 +115,6 @@ public function testGetUri() $this->assertEquals('employees', $u->getURI()); } - - public function testGetResourceName() { $u = new User; @@ -142,8 +125,6 @@ public function testGetResourceName() $this->assertEquals('Employee', $u->getResourceName()); } - - public function testGetMutableFields() { $u = Trucker::newInstance(['foo' => 'bar', 'biz' => 'bang']); @@ -155,8 +136,6 @@ public function testGetMutableFields() ); } - - public function testGetReadOnlyFields() { $u = Trucker::newInstance(); @@ -168,8 +147,6 @@ public function testGetReadOnlyFields() ); } - - public function testGetIdentityProperty() { $u = Trucker::newInstance(); @@ -182,8 +159,6 @@ public function testGetIdentityProperty() $this->assertEquals('user_id', $u->getIdentityProperty()); } - - public function testGetFileFields() { $u = Trucker::newInstance(); @@ -195,8 +170,6 @@ public function testGetFileFields() ); } - - public function testGetGuardedAttributes() { $u = Trucker::newInstance(); @@ -209,8 +182,6 @@ public function testGetGuardedAttributes() ); } - - public function testErrorsGetter() { $u = Trucker::newInstance(); @@ -222,8 +193,6 @@ public function testErrorsGetter() ); } - - public function testAttributesGetter() { $attrs = ['foo' => 'bar', 'biz' => 'bang']; @@ -235,8 +204,6 @@ public function testAttributesGetter() ); } - - public function testUnsetFunction() { $attrs = ['foo' => 'bar', 'biz' => 'bang']; @@ -255,8 +222,6 @@ public function testUnsetFunction() ); } - - public function testGetId() { $t = Trucker::newInstance(); @@ -265,8 +230,6 @@ public function testGetId() $this->assertEquals(123456, $t->getId(), 'identity property could not properly resolve'); } - - public function testCreateShouldSaveWithoutHttpMethodParam() { //setup our creation mocks, expected results etc @@ -276,9 +239,9 @@ public function testCreateShouldSaveWithoutHttpMethodParam() $result = $u->save(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->assertTrue($response->isSuccessful()); $this->assertTrue($result, "Save() should have been true"); @@ -295,14 +258,12 @@ public function testCreateShouldSaveWithoutHttpMethodParam() $this->assertEquals(1, $u->getId(), "Expected respose to set ID"); } - - public function testCreateShouldSaveWithHttpMethodParam() { //setup our creation mocks, expected results etc $config = [ - 'trucker::request.base_uri' => 'http://example.com', - 'trucker::request.http_method_param' => '_method' + 'trucker::request.base_uri' => 'http://example.com', + 'trucker::request.http_method_param' => '_method', ]; $this->setupIndividualTest($this->getCreateTestOptions(), $config); @@ -310,9 +271,9 @@ public function testCreateShouldSaveWithHttpMethodParam() $result = $u->save(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->assertTrue($response->isSuccessful()); $this->assertTrue($result, "Save() should have been true"); @@ -329,16 +290,14 @@ public function testCreateShouldSaveWithHttpMethodParam() $this->assertArrayHasKey('_method', $request->getPostFields()->toArray(), 'Expected http method param'); } - - public function testCreateShouldFailWithErrorsKey() { $invalid_status = Config::get('response.http_status.invalid'); $config = [ - 'trucker::request.base_uri' => 'http://example.com', + 'trucker::request.base_uri' => 'http://example.com', 'trucker::error_handler.driver' => 'parameter_key', - 'trucker::error_handler.errors_key' => 'errors' + 'trucker::error_handler.errors_key' => 'errors', ]; //setup our creation mocks, expected results etc @@ -354,9 +313,9 @@ public function testCreateShouldFailWithErrorsKey() $result = $u->save(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->assertEquals( $invalid_status, @@ -366,8 +325,6 @@ public function testCreateShouldFailWithErrorsKey() $this->assertCount(2, $u->errors(), 'Expected 2 errors'); } - - public function testCreateShouldFailWithoutErrorsKey() { $invalid_status = Config::get('response.http_status.invalid'); @@ -383,9 +340,9 @@ public function testCreateShouldFailWithoutErrorsKey() $result = $u->save(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->assertEquals( $invalid_status, @@ -395,8 +352,6 @@ public function testCreateShouldFailWithoutErrorsKey() $this->assertCount(2, $u->errors(), 'Expected 2 errors'); } - - public function testUpdateShouldSaveWithoutHttpMethodParam() { //setup our creation mocks, expected results etc @@ -407,9 +362,9 @@ public function testUpdateShouldSaveWithoutHttpMethodParam() $result = $u->save(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->assertTrue($response->isSuccessful()); $this->assertTrue($result, "Save() should have been true"); @@ -425,13 +380,12 @@ public function testUpdateShouldSaveWithoutHttpMethodParam() $this->assertEquals('/users/1', $request->getPath(), "Expected request to go to /users/1"); } - public function testUpdateShouldSaveWithHttpMethodParam() { //setup our creation mocks, expected results etc $config = [ - 'trucker::request.base_uri' => 'http://example.com', - 'trucker::request.http_method_param' => '_method' + 'trucker::request.base_uri' => 'http://example.com', + 'trucker::request.http_method_param' => '_method', ]; $this->setupIndividualTest($this->getUpdateTestOptions(), $config); @@ -440,9 +394,9 @@ public function testUpdateShouldSaveWithHttpMethodParam() $result = $u->save(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->assertTrue($response->isSuccessful()); $this->assertTrue($result, "Save() should have been true"); @@ -460,16 +414,14 @@ public function testUpdateShouldSaveWithHttpMethodParam() $this->assertArrayHasKey('_method', $request->getPostFields()->toArray(), 'Expected http method param'); } - - public function testUpdateShouldFailWithErrorsKey() { $invalid_status = Config::get('response.http_status.invalid'); $config = [ - 'trucker::request.base_uri' => 'http://example.com', + 'trucker::request.base_uri' => 'http://example.com', 'trucker::error_handler.driver' => 'parameter_key', - 'trucker::error_handler.errors_key' => 'errors' + 'trucker::error_handler.errors_key' => 'errors', ]; //setup our creation mocks, expected results etc @@ -486,9 +438,9 @@ public function testUpdateShouldFailWithErrorsKey() $result = $u->save(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->assertFalse($result, 'Expected save to return false'); $this->assertEquals( @@ -499,8 +451,6 @@ public function testUpdateShouldFailWithErrorsKey() $this->assertCount(2, $u->errors(), 'Expected 2 errors'); } - - public function testUpdateShouldFailWithoutErrorsKey() { $invalid_status = Config::get('response.http_status.invalid'); @@ -517,9 +467,9 @@ public function testUpdateShouldFailWithoutErrorsKey() $result = $u->save(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->assertFalse($result, 'Expected save to return false'); $this->assertEquals( @@ -530,8 +480,6 @@ public function testUpdateShouldFailWithoutErrorsKey() $this->assertCount(2, $u->errors(), 'Expected 2 errors'); } - - public function testDestroyWithoutHttpMethodParam() { //setup our creation mocks, expected results etc @@ -542,9 +490,9 @@ public function testDestroyWithoutHttpMethodParam() $result = $u->destroy(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->assertTrue($response->isSuccessful()); $this->assertTrue($result, "destroy() should have been true"); @@ -553,14 +501,12 @@ public function testDestroyWithoutHttpMethodParam() $this->assertEquals('/users/1', $request->getPath(), "Expected request to go to /users/1"); } - - public function testDestroyWithHttpMethodParam() { //setup our creation mocks, expected results etc $config = [ - 'trucker::request.base_uri' => 'http://example.com', - 'trucker::request.http_method_param' => '_method' + 'trucker::request.base_uri' => 'http://example.com', + 'trucker::request.http_method_param' => '_method', ]; $this->setupIndividualTest($this->getCreateTestOptions(), $config); @@ -569,9 +515,9 @@ public function testDestroyWithHttpMethodParam() $result = $u->destroy(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->assertTrue($response->isSuccessful()); $this->assertTrue($result, "destroy() should have been true"); @@ -580,16 +526,14 @@ public function testDestroyWithHttpMethodParam() $this->assertArrayHasKey('_method', $request->getPostFields()->toArray(), 'Expected http method param'); } - - public function testDestroyShouldFailWithErrorsKey() { $invalid_status = Config::get('response.http_status.invalid'); $config = [ - 'trucker::request.base_uri' => 'http://example.com', + 'trucker::request.base_uri' => 'http://example.com', 'trucker::error_handler.driver' => 'parameter_key', - 'trucker::error_handler.errors_key' => 'errors' + 'trucker::error_handler.errors_key' => 'errors', ]; //setup our creation mocks, expected results etc @@ -606,9 +550,9 @@ public function testDestroyShouldFailWithErrorsKey() $result = $u->destroy(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->assertFalse($result, 'Expected destroy() to return false'); $this->assertEquals( @@ -619,8 +563,6 @@ public function testDestroyShouldFailWithErrorsKey() $this->assertCount(2, $u->errors(), 'Expected 2 errors'); } - - public function testDestroyShouldFailWithoutErrorsKey() { $invalid_status = Config::get('response.http_status.invalid'); @@ -637,9 +579,9 @@ public function testDestroyShouldFailWithoutErrorsKey() $result = $u->destroy(); //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); $this->assertFalse($result, 'Expected destroy() to return false'); $this->assertEquals( @@ -650,61 +592,56 @@ public function testDestroyShouldFailWithoutErrorsKey() $this->assertCount(2, $u->errors(), 'Expected 2 errors'); } - - /** * Helper function to get commonly used testing data * for creating an entity - * + * * @return array */ private function getCreateTestOptions() { //some vars for our test - $data = []; - $data['uri'] = '/users'; - $data['base_uri'] = 'http://example.com'; + $data = []; + $data['uri'] = '/users'; + $data['base_uri'] = 'http://example.com'; $data['response_body'] = json_encode( [ - 'id' => 1, - 'name' => 'John Doe', - 'email' => 'jdoe@noboddy.com' + 'id' => 1, + 'name' => 'John Doe', + 'email' => 'jdoe@noboddy.com', ] ); return $data; } - - /** * Helper function to get commonly used testing data * for updating an entity - * + * * @return array */ private function getUpdateTestOptions() { //some vars for our test - $data = []; - $data['uri'] = '/users/1'; - $data['base_uri'] = 'http://example.com'; + $data = []; + $data['uri'] = '/users/1'; + $data['base_uri'] = 'http://example.com'; $data['response_body'] = json_encode( [ - 'id' => 1, - 'name' => 'John Doe', - 'email' => 'jdoe@noboddy.com' + 'id' => 1, + 'name' => 'John Doe', + 'email' => 'jdoe@noboddy.com', ] ); return $data; } - /** * Helper function to get commonly used testing data * for error testing entity saving - * + * * @return array */ private function getSaveErrorTestOptions($key = null) @@ -712,7 +649,7 @@ private function getSaveErrorTestOptions($key = null) $errors = [ "Username can't be blank", - "Email format is invalid" + "Email format is invalid", ]; if ($key) { @@ -722,21 +659,20 @@ private function getSaveErrorTestOptions($key = null) } //some vars for our test - $data = []; - $data['uri'] = '/users/1'; - $data['base_uri'] = 'http://example.com'; + $data = []; + $data['uri'] = '/users/1'; + $data['base_uri'] = 'http://example.com'; $data['response_body'] = json_encode($errorsArray); return $data; } - /** - * Function to mock a request for us and + * Function to mock a request for us and * expect test data - * - * @param array $options + * + * @param array $options * @param array $config_overrides - * @param int $status + * @param int $status * @param string $content_type * @return void */ @@ -765,8 +701,8 @@ private function setupIndividualTest( //HTTP response headers // [ - 'Location' => $base_uri.'/'.$uri, - 'Content-Type' => $content_type + 'Location' => $base_uri . '/' . $uri, + 'Content-Type' => $content_type, ], // //response to return diff --git a/tests/Requests/RestRequestTest.php b/tests/Requests/RestRequestTest.php index 500abb7..7d443dd 100644 --- a/tests/Requests/RestRequestTest.php +++ b/tests/Requests/RestRequestTest.php @@ -1,9 +1,9 @@ shouldIgnoreMissing(); $config->shouldReceive('get')->with('trucker::transporter.driver') - ->andReturn('json'); + ->andReturn('json'); $app = m::mock('Illuminate\Container\Container'); $app->shouldIgnoreMissing(); @@ -25,8 +25,6 @@ public function testGetOption() $this->assertEquals('json', $transporter); } - - public function testSetTransportLanguage() { $request = $this->simpleMockRequest([ @@ -34,16 +32,14 @@ public function testSetTransportLanguage() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ]); $r = $request->createRequest('http://example.com', '/users', 'GET'); } - - public function testCreateNewRequest() { $request = $this->simpleMockRequest([ @@ -51,16 +47,14 @@ public function testCreateNewRequest() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ]); $result = $request->createRequest('http://example.com', '/users', 'GET'); $this->assertTrue($result instanceof \Guzzle\Http\Message\Request); } - - public function testSetPostParameters() { $request = $this->simpleMockRequest([ @@ -68,8 +62,8 @@ public function testSetPostParameters() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ['method' => 'setPostField', 'args' => ['biz', 'banng']], ]); @@ -78,8 +72,6 @@ public function testSetPostParameters() $request->setPostParameters(['biz' => 'banng']); } - - public function testSetGetParameters() { $mQuery = m::mock('Guzzle\Http\QueryString'); @@ -90,8 +82,8 @@ public function testSetGetParameters() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ['method' => 'getQuery', 'return' => $mQuery], ]); @@ -100,8 +92,6 @@ public function testSetGetParameters() $request->setGetParameters(['foo' => 'bar']); } - - public function testSetFileParameters() { $request = $this->simpleMockRequest([ @@ -109,8 +99,8 @@ public function testSetFileParameters() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ['method' => 'addPostFile', 'args' => ['fileOne', '/path/to/fileOne']], ]); @@ -119,8 +109,6 @@ public function testSetFileParameters() $request->setFileParameters(['fileOne' => '/path/to/fileOne']); } - - public function testSettingModelProperties() { $request = $this->simpleMockRequest([ @@ -128,8 +116,8 @@ public function testSettingModelProperties() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ['method' => 'setPostField', 'args' => ['foo', 'bar']], ['method' => 'setPostField', 'args' => ['biz', 'bang']], @@ -138,12 +126,12 @@ public function testSettingModelProperties() ]); $attributes = [ - 'foo' => 'bar', - 'biz' => 'bang', + 'foo' => 'bar', + 'biz' => 'bang', 'roOne' => 'roOneVal', 'roTwo' => 'roTwoVal', - 'fOne' => '/path/to/file/one', - 'fTwo' => '/path/to/file/two' + 'fOne' => '/path/to/file/one', + 'fTwo' => '/path/to/file/two', ]; $mUser = m::mock('User'); @@ -155,8 +143,6 @@ public function testSettingModelProperties() $request->setModelProperties($mUser); } - - public function testSettingHeaders() { $request = $this->simpleMockRequest([ @@ -164,8 +150,8 @@ public function testSettingHeaders() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ['method' => 'setHeader', 'args' => ['Cache-Control', 'no-cache, must-revalidate']], ]); @@ -174,8 +160,6 @@ public function testSettingHeaders() $request->createRequest('http://example.com', '/users', 'GET', $headers); } - - public function testSettingBody() { $request = \Guzzle\Http\Message\RequestFactory::getInstance()->create('PUT', 'http://www.test.com/'); @@ -184,8 +168,6 @@ public function testSettingBody() $this->assertFalse($request->hasHeader('Transfer-Encoding')); } - - public function testAddingErrorHandler() { $dispatcher = m::mock('Symfony\Component\EventDispatcher\EventDispatcher'); @@ -196,8 +178,8 @@ public function testAddingErrorHandler() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ['method' => 'getEventDispatcher', 'return' => $dispatcher], ]); @@ -210,8 +192,6 @@ public function testAddingErrorHandler() $request->addErrorHandler(200, $func, true); } - - public function testAddQueryCondition() { $request = $this->simpleMockRequest([ @@ -219,8 +199,8 @@ public function testAddQueryCondition() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ]); $r = $request->createRequest('http://example.com', '/users', 'GET'); @@ -231,8 +211,6 @@ public function testAddQueryCondition() $request->addQueryCondition($c); } - - public function testAddQueryResultOrder() { $request = $this->simpleMockRequest([ @@ -240,8 +218,8 @@ public function testAddQueryResultOrder() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ]); $r = $request->createRequest('http://example.com', '/users', 'GET'); @@ -252,8 +230,6 @@ public function testAddQueryResultOrder() $request->addQueryResultOrder($o); } - - public function testAddAuthentication() { $request = $this->simpleMockRequest([ @@ -261,8 +237,8 @@ public function testAddAuthentication() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ]); $r = $request->createRequest('http://example.com', '/users', 'GET'); @@ -273,8 +249,6 @@ public function testAddAuthentication() $request->authenticate($auth); } - - public function testSendRequest() { $request = $this->simpleMockRequest([ @@ -282,8 +256,8 @@ public function testSendRequest() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ['method' => 'send', 'return' => m::mock('Guzzle\Http\Message\Response')], ]); @@ -292,8 +266,6 @@ public function testSendRequest() $request->sendRequest(); } - - public function testHttpMethodParam() { $request = $this->simpleMockRequest( @@ -302,8 +274,8 @@ public function testHttpMethodParam() 'method' => 'setHeaders', 'args' => [[ 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ]] + 'Content-Type' => 'application/json', + ]], ], ['method' => 'setPostField', 'args' => ['_method', 'PUT']], ], @@ -315,14 +287,12 @@ public function testHttpMethodParam() $request->createRequest('http://example.com', '/users/1', 'PUT', [], '_method'); } - - /** * Function to create and return a Trucker\Requests\RestRequest object * with mock client & rquest objects injected - * - * @param array $shouldReceive - * @param string $baseUrl + * + * @param array $shouldReceive + * @param string $baseUrl * @param string $uri * @param string $method * @return Trucker\Requests\RestRequest diff --git a/tests/Responses/ResponseTest.php b/tests/Responses/ResponseTest.php index af4a2a3..f8a9a06 100644 --- a/tests/Responses/ResponseTest.php +++ b/tests/Responses/ResponseTest.php @@ -1,8 +1,8 @@ shouldReceive('getStatusCode') - ->once() - ->andReturn(200); + ->once() + ->andReturn(200); $response = new \Trucker\Responses\Response($this->app, $gResponse); $this->assertEquals(200, $response->getStatusCode()); } - - public function testGetOption() { $config = m::mock('Illuminate\Config\Repository'); $config->shouldIgnoreMissing(); $config->shouldReceive('get')->with('trucker::transporter.driver') - ->andReturn('json'); + ->andReturn('json'); $app = m::mock('Illuminate\Container\Container'); $app->shouldIgnoreMissing(); @@ -35,14 +33,12 @@ public function testGetOption() $this->assertEquals('json', $transporter); } - - public function testNewInstanceCreator() { $gResponse = m::mock('Guzzle\Http\Message\Response'); $gResponse->shouldReceive('getStatusCode') - ->times(2) - ->andReturn(200); + ->times(2) + ->andReturn(200); $i = Response::newInstance($this->app, $gResponse); $this->assertTrue( @@ -56,14 +52,12 @@ public function testNewInstanceCreator() $this->assertEquals(200, $i->__call('getStatusCode', [])); } - - public function testParseJsonResponseToData() { $config = m::mock('Illuminate\Config\Repository'); $config->shouldIgnoreMissing(); $config->shouldReceive('get')->with('trucker::transporter.driver') - ->andReturn('json'); + ->andReturn('json'); $app = m::mock('Illuminate\Container\Container'); $app->shouldIgnoreMissing(); @@ -73,22 +67,20 @@ public function testParseJsonResponseToData() $gResponse = m::mock('Guzzle\Http\Message\Response'); $gResponse->shouldReceive('json') - ->once() - ->andReturn($data); + ->once() + ->andReturn($data); $response = new \Trucker\Responses\Response($app, $gResponse); $this->assertTrue( $this->arraysAreSimilar($data, $response->parseResponseToData()) ); } - - public function testParseJsonResponseStringToObject() { $config = m::mock('Illuminate\Config\Repository'); $config->shouldIgnoreMissing(); $config->shouldReceive('get')->with('trucker::transporter.driver') - ->andReturn('json'); + ->andReturn('json'); $app = m::mock('Illuminate\Container\Container'); $app->shouldIgnoreMissing(); @@ -100,9 +92,9 @@ public function testParseJsonResponseStringToObject() $gResponse = m::mock('Guzzle\Http\Message\Response'); $gResponse->shouldReceive('getBody') - ->with(true) - ->once() - ->andReturn($dataJson); + ->with(true) + ->once() + ->andReturn($dataJson); $response = new \Trucker\Responses\Response($app, $gResponse); $this->assertEquals( $decodedJson, diff --git a/tests/test_helpers/GuzzleTestingTrait.php b/tests/test_helpers/GuzzleTestingTrait.php index 7aa1aae..dd53c0a 100644 --- a/tests/test_helpers/GuzzleTestingTrait.php +++ b/tests/test_helpers/GuzzleTestingTrait.php @@ -1,22 +1,21 @@ addSubscriber($this->history); } - /** * Function to mock an HTTP response to a Guzzle Request - * + * * @param Guzzle\Client $client Guzzle Client to mock response for * @param integer $http_status HTTP status to return * @param array $headers HTTP Headers for the response @@ -55,7 +53,7 @@ public function mockHttpResponse(&$client, $http_status = 200, $headers = array( /** * Function to return the Guzzle History plugin * to look at requests for a client - * + * * @return Guzzle\Plugin\History */ public function getHttpClientHistory() @@ -63,11 +61,10 @@ public function getHttpClientHistory() return $this->history; } - /** * Helper function to setup for testing requests that leverage * the Request class and guzzle - * + * * @param array $config config overrides * @return Guzzle\Http\Client */ @@ -81,11 +78,10 @@ protected function &initGuzzleRequestTest($config = array()) return $client; } - /** * Helper function to test various aspects of a Guzzle * request / response - * + * * @param string $method HTTP method expected * @param string $baseUri Base URL expected in request * @param string $uri URI expected for request @@ -104,9 +100,9 @@ protected function makeGuzzleAssertions( ) { //get objects to assert on - $history = $this->getHttpClientHistory(); - $request = $history->getLastRequest(); - $response = $history->getLastResponse(); + $history = $this->getHttpClientHistory(); + $request = $history->getLastRequest(); + $response = $history->getLastResponse(); //assert the HTTP REQUEST is manufactured as it should be $this->assertEquals( @@ -119,7 +115,7 @@ protected function makeGuzzleAssertions( $request->getPath(), "The request path is wrong" ); - + $this->assertTrue( $this->arraysAreSimilar( $queryParams, @@ -169,7 +165,7 @@ protected function makeGuzzleAssertions( } } - }//end if request can have post / files + } //end if request can have post / files $this->assertEquals( $method,