diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7b266c9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.phpunit.result.cache +**/error_log diff --git a/Cpanel/Core/Object.php b/Cpanel/Core/Object.php index c13a47b..9ff3937 100644 --- a/Cpanel/Core/Object.php +++ b/Cpanel/Core/Object.php @@ -2,7 +2,7 @@ /** * Cpanel_Core_Object * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Core * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -48,13 +48,13 @@ * @category Cpanel * @package Cpanel_Core * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ -class Cpanel_Core_Object implements IteratorAggregate +class Cpanel_Core_Object implements IteratorAggregate, Countable { /** * internal storage location @@ -83,6 +83,11 @@ public function getIterator() { return new ArrayIterator($this->dataContainer); } + + public function count() { + return $this->getIterator()->count(); + } + /** * Accessor for storing data internally * diff --git a/Cpanel/Core/PriorityQueue.php b/Cpanel/Core/PriorityQueue.php index 19b90c8..684c0dd 100644 --- a/Cpanel/Core/PriorityQueue.php +++ b/Cpanel/Core/PriorityQueue.php @@ -2,7 +2,7 @@ /** * Cpanel_Core_PriorityQueue * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Core * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -48,9 +48,9 @@ * @category Cpanel * @package Cpanel_Core * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Examples/Accessing_Response_Data.php b/Cpanel/Examples/Accessing_Response_Data.php index 5a35317..b61df00 100644 --- a/Cpanel/Examples/Accessing_Response_Data.php +++ b/Cpanel/Examples/Accessing_Response_Data.php @@ -2,7 +2,7 @@ /** * Example usage of iterating over a response (Cpanel_Query_Object) * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_PublicAPI * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Examples/Basic_WHM_Service.php b/Cpanel/Examples/Basic_WHM_Service.php index e61e18e..345489f 100644 --- a/Cpanel/Examples/Basic_WHM_Service.php +++ b/Cpanel/Examples/Basic_WHM_Service.php @@ -2,7 +2,7 @@ /** * Example usage of WHM Service * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_PublicAPI * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Examples/Basic_cPanel_Service.php b/Cpanel/Examples/Basic_cPanel_Service.php index eb99a0a..244be25 100644 --- a/Cpanel/Examples/Basic_cPanel_Service.php +++ b/Cpanel/Examples/Basic_cPanel_Service.php @@ -2,7 +2,7 @@ /** * Example usage of cPanel Service * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_PublicAPI * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Examples/Introduction_to_PublicAPI.php b/Cpanel/Examples/Introduction_to_PublicAPI.php index 1b8eabd..7c47375 100644 --- a/Cpanel/Examples/Introduction_to_PublicAPI.php +++ b/Cpanel/Examples/Introduction_to_PublicAPI.php @@ -2,7 +2,7 @@ /** * Introduction to PublicAPI and the cPanel PHP library * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_PublicAPI * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Examples/PublicAPI_DirectURL.php b/Cpanel/Examples/PublicAPI_DirectURL.php index cb409f6..1db853f 100644 --- a/Cpanel/Examples/PublicAPI_DirectURL.php +++ b/Cpanel/Examples/PublicAPI_DirectURL.php @@ -2,7 +2,7 @@ /** * Example usage of Direct URL query via PublicAPI client * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_PublicAPI * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Examples/PublicAPI_and_Service_Configuration.php b/Cpanel/Examples/PublicAPI_and_Service_Configuration.php index ba4246b..72c1eb6 100644 --- a/Cpanel/Examples/PublicAPI_and_Service_Configuration.php +++ b/Cpanel/Examples/PublicAPI_and_Service_Configuration.php @@ -3,7 +3,7 @@ * Example usage of configuration options for the PublicAPI client and cPanel * PHP library. * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -14,7 +14,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -32,9 +32,9 @@ * @category Cpanel * @package Cpanel_PublicAPI * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Examples/Token_Access_cPanel_Service.php b/Cpanel/Examples/Token_Access_cPanel_Service.php new file mode 100644 index 0000000..ad49e4b --- /dev/null +++ b/Cpanel/Examples/Token_Access_cPanel_Service.php @@ -0,0 +1,90 @@ + + * @copyright Copyright (c) 2019, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) + * @license http://sdk.cpanel.net/license/bsd.html BSD License + * @version 0.2.0 + * @link http://sdk.cpanel.net + * @since 0.2.0 + */ + +/** + * Please look at the Introduction_to_PublicAPI.php for more details. + */ +TRY { + require_once realpath( dirname(__FILE__) . '/../Util/Autoload.php'); + + # Replace these values with real values from your server + # You can generate a cPanel API Token in the Cpanel > API Tokens Interface + $HOST_NAME = '10.1.32.118'; + $HOST_USER = 'green'; + $TOKEN = '33JK2FL611YNDACZX1EO4M1N7O37HHPE'; + + /** + * Getting a cPanel Service object and invoking the api2_request method on + * the cPanel Service object itself. The preferred method is to use the + * cpanel_api{n}_request() method available in the PublicAPI interface, but + * this is here for demonstration purposes of the Service available in the + * cPanel library. + * + * We use the cPanel Service's accessor methods to set initialization + * variables. Authenticating as the user with a token + */ + $cpanel = Cpanel_PublicAPI::factory('cPanel'); + $cpanel->setUser($HOST_USER) + ->setToken($TOKEN) + ->setHost($HOST_NAME); + + $service = 'cpanel'; + $queryMF = array( + 'module' => 'Email', + 'function' => 'listforwards', + 'user' => $HOST_USER, + ); + $response = $cpanel->api2_request($service, $queryMF); + + echo "API2 response for {$queryMF['module']}::{$queryMF['function']} '\n"; + + foreach ($response->cpanelresult->data as $dataset) { + foreach ($dataset as $key => $value) { + echo "\t$key: $value\n"; + } + } + + echo "\n"; +} +CATCH(Exception $e) { + echo $e->getMessage() . "\n" . $e->getTraceAsString() . "\n"; +} +echo "EOF: You've successfully ended the " . basename(__FILE__) . " script.\n"; +?> \ No newline at end of file diff --git a/Cpanel/Examples/Using_the_LivePHP_Service.php b/Cpanel/Examples/Using_the_LivePHP_Service.php index cedb98a..55a46e4 100644 --- a/Cpanel/Examples/Using_the_LivePHP_Service.php +++ b/Cpanel/Examples/Using_the_LivePHP_Service.php @@ -2,7 +2,7 @@ /** * Example usage of LivePHP Service * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_PublicAPI * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Listner/Observer/GenericLogger.php b/Cpanel/Listner/Observer/GenericLogger.php index 0a586a7..7d2681f 100644 --- a/Cpanel/Listner/Observer/GenericLogger.php +++ b/Cpanel/Listner/Observer/GenericLogger.php @@ -2,7 +2,7 @@ /** * Cpanel_Listner_Observer_GenericLogger * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -32,9 +32,9 @@ * @package Cpanel_Listner * @subpackage Observer * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -46,9 +46,9 @@ * @package Cpanel_Listner * @subpackage Observer * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Listner/Subject/Abstract.php b/Cpanel/Listner/Subject/Abstract.php index 9843352..9b6bdf7 100644 --- a/Cpanel/Listner/Subject/Abstract.php +++ b/Cpanel/Listner/Subject/Abstract.php @@ -2,7 +2,7 @@ /** * Cpanel_Listner_Subject_Abstract * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -32,9 +32,9 @@ * @package Cpanel_Listner * @subpackage Subject * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -46,9 +46,9 @@ * @package Cpanel_Listner * @subpackage Subject * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Listner/Subject/Logger.php b/Cpanel/Listner/Subject/Logger.php index e85b3cd..f746972 100644 --- a/Cpanel/Listner/Subject/Logger.php +++ b/Cpanel/Listner/Subject/Logger.php @@ -2,7 +2,7 @@ /** * Cpanel_Listner_Subject_Logger * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -32,9 +32,9 @@ * @package Cpanel_Listner * @subpackage Subject * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -46,9 +46,9 @@ * @package Cpanel_Listner * @subpackage Subject * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Parser/Interface.php b/Cpanel/Parser/Interface.php index 4ff616a..7bfb9c7 100644 --- a/Cpanel/Parser/Interface.php +++ b/Cpanel/Parser/Interface.php @@ -2,7 +2,7 @@ /** * Cpanel_Parser_Interface * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Parser * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -44,9 +44,9 @@ * @category Cpanel * @package Cpanel_Parser * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Parser/JSON.php b/Cpanel/Parser/JSON.php index a592307..024c95c 100644 --- a/Cpanel/Parser/JSON.php +++ b/Cpanel/Parser/JSON.php @@ -2,7 +2,7 @@ /** * Cpanel_Parser_JSON * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Parser * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -44,9 +44,9 @@ * @category Cpanel * @package Cpanel_Parser * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -207,29 +207,39 @@ public function getParserInternalErrors($prefix = '', $default = ' Could not loa $errmsg.= $prefix; if (version_compare(PHP_VERSION, '5.3.0', '>=')) { switch (json_last_error()) { - case JSON_ERROR_DEPTH: - //Parse do not support setting depth, but it's here anyway - //@codeCoverageIgnoreStart - $errmsg.= 'Maximum stack depth exceeded.'; - break; - //@codeCoverageIgnoreEnd - - case JSON_ERROR_CTRL_CHAR: - $errmsg.= 'Unexpected control character found.'; - break; - - case JSON_ERROR_SYNTAX: - $errmsg.= 'Syntax error, malformed JSON.'; - break; - - case JSON_ERROR_STATE_MISMATCH: - $errmsg.= 'Invalid or malformed JSON.'; - break; - //@todo with 5.3.3 add JSON_ERROR_UTF8 to switch - - case JSON_ERROR_NONE: - default: - $errmsg.= $default; + case JSON_ERROR_DEPTH: + $errmsg.= 'The maximum stack depth has been exceeded'; + break; + case JSON_ERROR_STATE_MISMATCH: + $errmsg.= 'Invalid or malformed JSON'; + break; + case JSON_ERROR_CTRL_CHAR: + $errmsg.= 'Control character error, possibly incorrectly encoded'; + break; + case JSON_ERROR_SYNTAX: + $errmsg.= 'Syntax error'; + break; + case JSON_ERROR_UTF8: + $errmsg.= 'Malformed UTF-8 characters, possibly incorrectly encoded'; + break; + case JSON_ERROR_RECURSION: + $errmsg.= 'One or more recursive references in the value to be encoded'; + break; + case JSON_ERROR_INF_OR_NAN: + $errmsg.= 'One or more NAN or INF values in the value to be encoded'; + break; + case JSON_ERROR_UNSUPPORTED_TYPE: + $errmsg.= 'A value of a type that cannot be encoded was given'; + break; + case JSON_ERROR_INVALID_PROPERTY_NAME: + $errmsg.= 'A property name that cannot be encoded was given'; + break; + case JSON_ERROR_UTF16: + $errmsg.= 'Malformed UTF-16 characters, possibly incorrectly encoded'; + break; + case JSON_ERROR_NONE: + default: + $errmsg.= $default; } //@codeCoverageIgnoreStart diff --git a/Cpanel/Parser/LiveJSON.php b/Cpanel/Parser/LiveJSON.php index c0017fd..60f094d 100644 --- a/Cpanel/Parser/LiveJSON.php +++ b/Cpanel/Parser/LiveJSON.php @@ -2,7 +2,7 @@ /** * Cpanel_Parser_LiveJSON * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Parser * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -44,9 +44,9 @@ * @category Cpanel * @package Cpanel_Parser * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Parser/XML.php b/Cpanel/Parser/XML.php index ae6d156..30160fd 100644 --- a/Cpanel/Parser/XML.php +++ b/Cpanel/Parser/XML.php @@ -2,7 +2,7 @@ /** * Cpanel_Parser_XML * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Parser * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -44,9 +44,9 @@ * @category Cpanel * @package Cpanel_Parser * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -244,6 +244,9 @@ private function _recurse_node_build($data, $obj) $this->_recurse_node_build($value, $sub_obj[$i]); } } else { + if (!is_string($value)) { + throw new Exception('Value must be a raw response string'); + } $sub_obj[$i] = $this->_dom->createElement($key, $value); $obj->appendChild($sub_obj[$i]); } diff --git a/Cpanel/PublicAPI.php b/Cpanel/PublicAPI.php index a752662..c6e25ca 100644 --- a/Cpanel/PublicAPI.php +++ b/Cpanel/PublicAPI.php @@ -2,7 +2,7 @@ /** * Cpanel_PublicAPI * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_PublicAPI * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -49,9 +49,9 @@ * @category Cpanel * @package Cpanel_PublicAPI * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -312,8 +312,9 @@ private static function _getAggregateConfig($type, $optsArray, $name) //TODO: decouple and thoroughly test deeply nested configs if (!empty($name)) { $workingConfigNamed = $self->getNamedConfig($name, $workingConfig); + if (count($workingConfigNamed)) { - if (count($workingConfig->config)) { + if ($workingConfig->config && count($workingConfig->config)) { //must try to merge $workingConfig = self::mergeConfigs( $workingConfig->config->getAllDataRecursively(), diff --git a/Cpanel/Query/Http/Abstract.php b/Cpanel/Query/Http/Abstract.php index 2da7666..8d6580b 100644 --- a/Cpanel/Query/Http/Abstract.php +++ b/Cpanel/Query/Http/Abstract.php @@ -2,7 +2,7 @@ /** * Cpanel_Query_Http_Abstract * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -32,9 +32,9 @@ * @package Cpanel_Query * @subpackage Http * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -46,9 +46,9 @@ * @package Cpanel_Query * @subpackage Http * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -80,6 +80,10 @@ abstract class Cpanel_Query_Http_Abstract extends Cpanel_Core_Object * Authenticating user */ protected $user = null; + /** + * Authenticating token + */ + protected $token = null; /** * PHP remote query function set * 'curl'|'fopen' @@ -351,9 +355,9 @@ public function getProtocol() */ public function setAuthType($auth_type) { - if ($auth_type != 'hash' && $auth_type != 'pass') { + if ($auth_type != 'hash' && $auth_type != 'pass' && $auth_type != 'token') { throw new Exception( - 'The only two allowable auth types are "hash" and "pass"' + 'The only allowable auth types are "hash", "pass", and "token"' ); } $this->auth_type = $auth_type; @@ -376,6 +380,23 @@ public function setPassword($pass) $this->auth = $pass; return $this; } + /** + * Accessor to set the authentication token + * + * The method will invoke {@link setAuthType} with 'token' + * + * @param string $token The api token to authenticate with + * + * @see setAuthType() + * + * @return Cpanel_Query_Http_Abstract + */ + public function setToken($token) + { + $this->setAuthType('token'); + $this->auth = $token; + return $this; + } /** * Accessor to set the authentication hash * @@ -608,6 +629,12 @@ public function buildAuthStr() . ':' . $this->auth . "\r\n"; + } elseif ($this->auth_type == 'token') { + return 'Authorization: cpanel ' + . $this->user + . ':' + . $this->auth + . "\r\n"; } elseif ($this->auth_type == 'pass') { return 'Authorization: Basic ' . base64_encode($this->user . ':' . $this->auth) @@ -1034,7 +1061,9 @@ public function __call($method, $args) if (count($nameParts) > 1) { array_walk( $nameParts, - create_function('&$v', '$v = ucfirst(strtolower($v));') + function ($v){ + $v = ucfirst(strtolower($v)); + } ); $mname = 'set' . implode('', $nameParts); } else { diff --git a/Cpanel/Query/Http/Interface.php b/Cpanel/Query/Http/Interface.php index 5dbca2d..1405885 100644 --- a/Cpanel/Query/Http/Interface.php +++ b/Cpanel/Query/Http/Interface.php @@ -2,7 +2,7 @@ /** * Cpanel_Query_Http_Interface * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -32,9 +32,9 @@ * @package Cpanel_Query * @subpackage Http * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -46,9 +46,9 @@ * @package Cpanel_Query * @subpackage Http * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Query/Interface.php b/Cpanel/Query/Interface.php index f202cd9..d3e4d27 100644 --- a/Cpanel/Query/Interface.php +++ b/Cpanel/Query/Interface.php @@ -2,7 +2,7 @@ /** * Cpanel_Query_Interface * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Query * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -44,9 +44,9 @@ * @category Cpanel * @package Cpanel_Query * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Query/Live/Abstract.php b/Cpanel/Query/Live/Abstract.php index ea3a957..b83bbb2 100644 --- a/Cpanel/Query/Live/Abstract.php +++ b/Cpanel/Query/Live/Abstract.php @@ -2,7 +2,7 @@ /** * Cpanel_Query_Live_Abstract * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -32,9 +32,9 @@ * @package Cpanel_Query * @subpackage Live * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -47,9 +47,9 @@ * @package Cpanel_Query * @subpackage Live * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Query/Live/Interface.php b/Cpanel/Query/Live/Interface.php index 555f010..8d22aa8 100644 --- a/Cpanel/Query/Live/Interface.php +++ b/Cpanel/Query/Live/Interface.php @@ -2,7 +2,7 @@ /** * Cpanel_Query_Live_Interface * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -32,9 +32,9 @@ * @package Cpanel_Query * @subpackage Live * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -46,9 +46,9 @@ * @package Cpanel_Query * @subpackage Live * @author David Neimeyer - * @copyright (c) 2011 cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright (c) 2011 cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Query/Object.php b/Cpanel/Query/Object.php index 4492588..634ee86 100644 --- a/Cpanel/Query/Object.php +++ b/Cpanel/Query/Object.php @@ -2,7 +2,7 @@ /** * Cpanel_Query_Object * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Query * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -54,9 +54,9 @@ * @category Cpanel * @package Cpanel_Query * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Service/Abstract.php b/Cpanel/Service/Abstract.php index c0f1efe..b0c3640 100644 --- a/Cpanel/Service/Abstract.php +++ b/Cpanel/Service/Abstract.php @@ -2,7 +2,7 @@ /** * Cpanel_Service_Abstract * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -44,9 +44,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -515,7 +515,8 @@ protected function arrayType($arr) ); } ksort($arr); - $fkey = array_shift(array_keys($arr)); + $arr = array_keys($arr); + $fkey = array_shift($arr); if (is_int($fkey)) { return self::API1ARGS; } @@ -582,6 +583,23 @@ public function setPassword($password) } return $this; } + /** + * Proxy accessor method for pushing token into adapters + * + * @param string $token Value to set + * + * @return Cpanel_Service_Abstract + */ + public function setToken($token) + { + $this->setOptions(array('token'=>$token)); + foreach ($this->adapters as $a) { + if (method_exists($a, 'setToken')) { + $a->setToken($token); + } + } + return $this; + } /** * Proxy accessor method for pushing host into adapters * diff --git a/Cpanel/Service/Adapter/Cpanelapi.php b/Cpanel/Service/Adapter/Cpanelapi.php index 79e6b99..60e80ee 100644 --- a/Cpanel/Service/Adapter/Cpanelapi.php +++ b/Cpanel/Service/Adapter/Cpanelapi.php @@ -2,7 +2,7 @@ /** * Cpanel_Service_Adapter_Cpanelapi * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -44,9 +44,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Service/Adapter/Liveapi.php b/Cpanel/Service/Adapter/Liveapi.php index 7af92c3..23e250b 100644 --- a/Cpanel/Service/Adapter/Liveapi.php +++ b/Cpanel/Service/Adapter/Liveapi.php @@ -2,7 +2,7 @@ /** * Cpanel_Service_Adapter_Liveapi * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -44,9 +44,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Service/Adapter/WHMapi.php b/Cpanel/Service/Adapter/WHMapi.php index 463131b..defc2d0 100644 --- a/Cpanel/Service/Adapter/WHMapi.php +++ b/Cpanel/Service/Adapter/WHMapi.php @@ -2,7 +2,7 @@ /** * Cpanel_Service_Adapter_WHMapi * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -44,9 +44,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Service/WHM.php b/Cpanel/Service/WHM.php index 82a815e..27b23de 100644 --- a/Cpanel/Service/WHM.php +++ b/Cpanel/Service/WHM.php @@ -2,7 +2,7 @@ /** * Cpanel_Service_WHM * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -47,9 +47,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Service/XmlapiClientClass.php b/Cpanel/Service/XmlapiClientClass.php index 17b0207..ce5d58f 100644 --- a/Cpanel/Service/XmlapiClientClass.php +++ b/Cpanel/Service/XmlapiClientClass.php @@ -2,7 +2,7 @@ /** * Cpanel_Service_XmlapiClientClass * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -49,9 +49,9 @@ * @package Cpanel_Service * @author David Neimeyer * @author Matt Dees - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Service/cPanel.php b/Cpanel/Service/cPanel.php index f78b74c..5c710d1 100644 --- a/Cpanel/Service/cPanel.php +++ b/Cpanel/Service/cPanel.php @@ -2,7 +2,7 @@ /** * Cpanel_Service_cPanel * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ @@ -44,9 +44,9 @@ * @category Cpanel * @package Cpanel_Service * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Tests/Cpanel/Core/AbstractTest.php b/Cpanel/Tests/Cpanel/Core/AbstractTest.php index eb1da37..4861141 100644 --- a/Cpanel/Tests/Cpanel/Core/AbstractTest.php +++ b/Cpanel/Tests/Cpanel/Core/AbstractTest.php @@ -28,7 +28,7 @@ class mockCoreException extends Exception * @author davidneimeyer * */ -class Cpanel_Service_AbstractTest extends PHPUnit_Framework_TestCase +class Cpanel_Service_AbstractTest extends CpanelTestCase { /** * @var Cpanel_Service_Abstract @@ -55,7 +55,7 @@ public function getCS($methods = array(), $args = array(), $mockName = '', $call if (empty($methods)) { $methods = null; } - $m = $this->getMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); + $m = $this->_makeMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); return $m; } /** @@ -76,7 +76,7 @@ public function getRObj($mock = false, $methods = array(), $args = array(), $moc if (empty($methods)) { $methods = null; } - return $this->getMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); + return $this->_makeMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); } return new Cpanel_Query_Object(); } @@ -148,11 +148,11 @@ public function testHasAbstractMethods() $this->assertEquals($expected, $actual); } /** - * @expectedException Exception * @depends testHasAbstractMethods */ public function testConstructThrowsOnBadInput() { + $this->expectExceptionMessage('setOptions() must receive an iterable variable type.'); $cs = $this->getCS(); $rmeth = new ReflectionMethod($this->cut, '__construct'); $rmeth->invoke($cs, 'fakestring'); @@ -202,10 +202,11 @@ public function testInstantiationSetsALogger() $this->assertInstanceOf('Cpanel_Listner_Subject_Abstract', $cs->listner); } /** - * @expectedException Exception + * @expectExceptionMessage Exception */ public function testDisableAdapterThrowOnBadType() { + $this->expectExceptionMessage('Invalid adapter type'); $cs = $this->getCS(array( 'validAdapter' )); @@ -225,10 +226,11 @@ public function testDisableAdapterStoresOnValidType() $this->assertTrue(in_array('foo', $da)); } /** - * @expectedException Exception + * @expectExceptionMessage Exception */ public function testEnableAdapterThrowOnBadType() { + $this->expectExceptionMessage('Invalid adapter type'); $cs = $this->getCS(array( 'validAdapter' )); @@ -259,7 +261,7 @@ public function testPrivategetEUIDAuthReturnsArray() $rmeth = new ReflectionMethod($cs, '_getEUIDAuth'); $rmeth->setAccessible(true); $r = $rmeth->invoke($cs); - $this->assertInternalType('array', $r); + $this->assertIsArray($r); } /** * @depends testPrivategetEUIDAuthReturnsArray @@ -675,7 +677,7 @@ public function testInitAdapterCallsAdapterInit() 'protocol' => $protocol, 'disableEnvironmentContext' => true, ); - $adapter = $this->getMock('concreteCoreRemoteQuery', array( + $adapter = $this->_makeMock('concreteCoreRemoteQuery', array( 'init' )); $adapter->expects($this->once())->method('init')->with($host, $user, $password); @@ -703,7 +705,7 @@ public function testInitAdapterDoesNotCallAdapterSetPortByDefault() 'protocol' => $protocol, 'disableEnvironmentContext' => true, ); - $adapter = $this->getMock('concreteCoreRemoteQuery', array( + $adapter = $this->_makeMock('concreteCoreRemoteQuery', array( 'init', 'setPort' )); @@ -734,7 +736,7 @@ public function testInitAdapterCallAdapterSetPortWhenPortHasValue() 'protocol' => $protocol, 'disableEnvironmentContext' => true, ); - $adapter = $this->getMock('concreteCoreRemoteQuery', array( + $adapter = $this->_makeMock('concreteCoreRemoteQuery', array( 'init', 'setPort' )); @@ -765,7 +767,7 @@ public function testInitAdapterDoesNotCallAdapterSetProtocolByDefault() 'protocol' => $protocol, 'disableEnvironmentContext' => true, ); - $adapter = $this->getMock('concreteCoreRemoteQuery', array( + $adapter = $this->_makeMock('concreteCoreRemoteQuery', array( 'init', 'setProtocol' )); @@ -797,7 +799,7 @@ public function testInitAdapterCallAdapterSetProtocolWhenPortHasNoValueAndProtoc 'protocol' => $protocol, 'disableEnvironmentContext' => true, ); - $adapter = $this->getMock('concreteCoreRemoteQuery', array( + $adapter = $this->_makeMock('concreteCoreRemoteQuery', array( 'init', 'setProtocol' )); @@ -828,7 +830,7 @@ public function testInitAdapterCallAdapterSetHashWhenHashExists() 'protocol' => $protocol, 'disableEnvironmentContext' => true, ); - $adapter = $this->getMock('concreteCoreRemoteQuery', array( + $adapter = $this->_makeMock('concreteCoreRemoteQuery', array( 'init', 'setHash' )); @@ -1059,10 +1061,11 @@ public function testGetAdapterDoesNotCallGetDefaultAdapterNameWhenAdapterIsSetIn $this->assertEquals($oAdapterName, $rObj->query->adapter); } /** - * @expectedException Exception + * @expectExceptionMessage Exception */ public function testGetAdapterThroWhenAdapterIsSetInROThatsDisabled() { + $this->expectExceptionMessage('Requested adapter \'live\' has been disabled'); $rObj = $this->getRObj(); $cs = $this->getCS(array( 'getDefaultAdapterName' @@ -1159,7 +1162,7 @@ public function argumentData() 'two', ), 0, - 'ordinal' + 'associative' ), ); } @@ -1175,7 +1178,9 @@ public function testProtectedArrayTypeThrowsOnBadInput($input, $expectExcep, $ex $rprop = new ReflectionMethod($cs, 'arrayType'); $rprop->setAccessible(true); if ($expectExcep) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); + }else{ + $this->assertEquals($expectType, $rprop->invoke($cs, $input)); } $rprop->invoke($cs, $input); } @@ -1189,15 +1194,20 @@ public function testProtectedArrayTypeThrowsOnBadInput($input, $expectExcep, $ex */ public function testProtectedArrayTypeReturnRightType($input, $expectExcep, $expectType = null) { - if (!is_null($expectType)) { - $cs = $this->getCS(); - $rprop = new ReflectionMethod($cs, 'arrayType'); - $rprop->setAccessible(true); + $cs = $this->getCS(); + $rprop = new ReflectionMethod($cs, 'arrayType'); + $rprop->setAccessible(true); + if ($expectExcep) { + $this->expectException('Exception'); + }else{ $this->assertEquals($expectType, $rprop->invoke($cs, $input)); } + $rprop->invoke($cs, $input); + } public function testLegacySetUnderscoreTypeUsesStoreAdapter() { + $rObj = $this->getRObj(); $cs = $this->getCS(array( 'genResponseObject', 'getDefaultAdapterName' @@ -1217,6 +1227,7 @@ public function testLegacySetUnderscoreTypeUsesStoreAdapter() } public function testLegacySetUnderscoreTypeAltersAdapter() { + $rObj = $this->getRObj(); $cs = $this->getCS(array( 'genResponseObject', 'getDefaultAdapterName' @@ -1272,11 +1283,13 @@ public function badSetOutputData() } /** * @dataProvider badSetOutputData - * @expectedException Exception + * @expectExceptionMessage Exception * @depends testLegacySetUnderscoreTypeUsesStoreAdapter */ public function testLegacySetUnderscoreTypeThrowOnBadInput($type) { + $this->expectExceptionMessage('Invalid adapter'); + $rObj = $this->getRObj(); $cs = $this->getCS(array( 'genResponseObject', 'getDefaultAdapterName' @@ -1345,10 +1358,11 @@ public function checkParamData() * @dataProvider checkParamData * @depends testClassHasConstants * @depends testProtectedCheckParamsHasRightInputArgs - * @expectedException Exception + * @expectExceptionMessage Exception */ public function testProtectedCheckParamsThrowsOnBadInput($service, $mf, $args, $method, $argType) { + $this->expectExceptionMessage('someMethodNameForLogging requires a'); $cs = $this->getCS(array( 'validAdapter' )); @@ -1412,7 +1426,7 @@ public function testProtectedCheckParamsNormalizesService($service, $mf, $args, 'isLocalQuery' )); if ($expectFail) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $fail = ($expectFail) ? false : $service; $cs->expects($this->once())->method('validAdapter')->will($this->returnValue($fail)); @@ -1483,7 +1497,7 @@ public function testProtectedCheckParamsNormalizesLiveService($service, $mf, $ar 'isLocalQuery' )); if ($expectFail) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $cs->expects($this->once())->method('validAdapter')->will($this->returnValue($service)); $cs->expects($this->once())->method('isLocalQuery')->will($this->returnValue($live)); @@ -1582,7 +1596,7 @@ public function testProtectedCheckParamsChecksModuleFunctionArray($service, $mf, } $cs->expects($this->once())->method('validAdapter')->will($this->returnValue($n)); if ($expectFail) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $rmeth = new ReflectionMethod($cs, 'checkParams'); $rmeth->setAccessible(true); @@ -1684,7 +1698,7 @@ public function testProtectedCheckParamsChecksArrayType($service, $mf, $args, $m } $cs->expects($this->once())->method('validAdapter')->will($this->returnValue($n)); if ($expectFail) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $rmeth = new ReflectionMethod($cs, 'checkParams'); $rmeth->setAccessible(true); diff --git a/Cpanel/Tests/Cpanel/Core/ObjectTest.php b/Cpanel/Tests/Cpanel/Core/ObjectTest.php index 78b69e8..0841d1c 100644 --- a/Cpanel/Tests/Cpanel/Core/ObjectTest.php +++ b/Cpanel/Tests/Cpanel/Core/ObjectTest.php @@ -1,11 +1,10 @@ setOptions($values); - foreach ($values as $value) { - $this->assertAttributeContains($value, 'dataContainer', $fixture); + foreach ($values as $key => $value) { + $this->assertEquals($fixture->getOption($key), $value); } return $fixture; } @@ -103,31 +102,35 @@ public function testSetOptionsNoOverrideOnRequest() $values = self::$simpleArray; $localFixture = new Cpanel_Core_Object(); $localFixture->setOptions($values); - $callBack = create_function('&$item1, $key', '$item1 .= $item1;'); + $callBack = function (&$item1, $key) { + return $item1 .= $item1; + }; array_walk($values, $callBack); $localFixture->setOptions($values, false); - foreach ($values as $value) { - $this->assertAttributeNotContains($value, 'dataContainer', $localFixture); + foreach ($values as $key => $value) { + $this->assertNotEquals($localFixture->getOption($key), $value); } return $localFixture; } /** * Verify setOptions will throw exception if passed non-traversable - * @expectedException Exception + * @expectException Exception */ public function testSetOptionsThrowsExceptionOnNonTraversableArg() { + $this->expectException("Exception"); $localFixture = new Cpanel_Core_Object(); $localFixture->setOptions('string'); } /** * Verify setOptions will throw exception if $dataContainer is NULL, aka * Cpanel_Core_Object (or classes that inherit it) aren't constructed properly - * @expectedException Exception + * @expectException Exception */ public function testSetOptionsThrowsExceptionIfInternalPropertyIsNull() { - $stub = $this->getMock('Cpanel_Core_Object', array( + $this->expectException("Exception"); + $stub = $this->_makeMock('Cpanel_Core_Object', array( '__set' )); $rprop = new ReflectionProperty('Cpanel_Core_Object', 'dataContainer'); @@ -141,7 +144,7 @@ public function testSetOptionsThrowsExceptionIfInternalPropertyIsNull() public function testSetOptionReturnSelfWhenPassedEmptyTraversable() { $data = self::$simpleArray; - $mockArrayObject = $this->getMock('ArrayObject', array( + $mockArrayObject = $this->_makeMock('ArrayObject', array( 'count' ), array( $data @@ -274,7 +277,7 @@ public function testSetOptionsCanMergeCpanelObjectWithoutOverwritting() 'c' => 3 ); $cpObj = new Cpanel_Core_Object($arr2); - $cpObj->setOptions(new Cpanel_Core_Object($arr1), false); + $cpObj->setOptions($arr1, false); $this->assertEquals($expected, $cpObj->getAllDataRecursively()); } /** @@ -282,7 +285,7 @@ public function testSetOptionsCanMergeCpanelObjectWithoutOverwritting() */ public function testMagicGetter() { - $stub = $this->getMock('Cpanel_Core_Object', array( + $stub = $this->_makeMock('Cpanel_Core_Object', array( '__get' )); $stub->expects($this->once())->method('__get')->with('foo')->will($this->returnValue('success')); @@ -293,7 +296,7 @@ public function testMagicGetter() */ public function testMagicGetterUsesGetOption() { - $stub = $this->getMock('Cpanel_Core_Object', array( + $stub = $this->_makeMock('Cpanel_Core_Object', array( 'getOption' )); $stub->expects($this->once())->method('getOption')->with('foo')->will($this->returnValue('success')); @@ -304,7 +307,7 @@ public function testMagicGetterUsesGetOption() */ public function testMagicSetter() { - $stub = $this->getMock('Cpanel_Core_Object', array( + $stub = $this->_makeMock('Cpanel_Core_Object', array( '__set' )); $stub->expects($this->once())->method('__set')->with('foo', 'bar'); @@ -316,7 +319,7 @@ public function testMagicSetter() */ public function testMagicSetterUsesSetOptions() { - $stub = $this->getMock('Cpanel_Core_Object', array( + $stub = $this->_makeMock('Cpanel_Core_Object', array( 'setOptions' )); $stub->expects($this->once())->method('setOptions')->with(array( diff --git a/Cpanel/Tests/Cpanel/Core/PriorityQueueTest.php b/Cpanel/Tests/Cpanel/Core/PriorityQueueTest.php index 393093e..c664835 100644 --- a/Cpanel/Tests/Cpanel/Core/PriorityQueueTest.php +++ b/Cpanel/Tests/Cpanel/Core/PriorityQueueTest.php @@ -1,8 +1,11 @@ obj = new $this->cut(); $this->obs = $this->getNewObserver(); @@ -27,7 +30,7 @@ protected function setUp() * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() + protected function tearDown(): void { } /** @@ -75,34 +78,34 @@ public function testAttachStoresSomething() } /** * Verify Exception throw for string attach - * @expectedException Exception */ public function testAttachThrowsOnString() { + $this->expectException("Exception"); $this->obj->attach('--fake--', 90); } /** * Verify Exception throw for array attach - * @expectedException Exception */ public function testAttachThrowsOnArray() { + $this->expectException("Exception"); $this->obj->attach(array(), 99); } /** * Verify Exception throw for bool attach - * @expectedException Exception */ public function testAttachThrowsOnBool() { + $this->expectException("Exception"); $this->obj->attach(true, 108); } /** * Verify Exception throw for int attach - * @expectedException Exception */ public function testAttachThrowsOnInt() { + $this->expectException("Exception"); $this->obj->attach(117, 117); } /** @@ -128,34 +131,34 @@ public function testContainsProperlyReturnsFalse() } /** * Verify Exception throw for string contains - * @expectedException Exception */ public function testContainsThrowsOnString() { + $this->expectException("Exception"); $this->obj->contains('--fake--'); } /** * Verify Exception throw for array contains - * @expectedException Exception */ public function testContainsThrowsOnArray() { + $this->expectException("Exception"); $this->obj->contains(array()); } /** * Verify Exception throw for bool contains - * @expectedException Exception */ public function testContainsThrowsOnBool() { + $this->expectException("Exception"); $this->obj->contains(true); } /** * Verify Exception throw for int contains - * @expectedException Exception */ public function testContainsThrowsOnInt() { + $this->expectException("Exception"); $this->obj->contains(117); } /** @@ -173,34 +176,34 @@ public function testDetachWillRemoveStoredObject($fixtureArray) } /** * Verify Exception throw for string detach - * @expectedException Exception */ public function testDetachThrowsOnString() { + $this->expectException("Exception"); $this->obj->detach('--fake--'); } /** * Verify Exception throw for array detach - * @expectedException Exception */ public function testDetachThrowsOnArray() { + $this->expectException("Exception"); $this->obj->detach(array()); } /** * Verify Exception throw for bool detach - * @expectedException Exception */ public function testDetachThrowsOnBool() { + $this->expectException("Exception"); $this->obj->detach(true); } /** * Verify Exception throw for int detach - * @expectedException Exception */ public function testDetachThrowsOnInt() { + $this->expectException("Exception"); $this->obj->detach(117); } /** @@ -298,10 +301,10 @@ public function testKey($fixtureArray) } /** * @depends testAttachStoresSomething - * @expectedException Exception */ public function testPrivateReturnStructureThrowOnObj() { + $this->expectException("Exception"); $rmeth = new ReflectionMethod($this->cut, '_returnStructure'); $rmeth->setAccessible(true); $pq = $this->obj; @@ -313,10 +316,10 @@ public function testPrivateReturnStructureThrowOnObj() } /** * @depends testAttachStoresSomething - * @expectedException Exception */ public function testPrivateReturnStructureThrowOnString() { + $this->expectException("Exception"); $rmeth = new ReflectionMethod($this->cut, '_returnStructure'); $rmeth->setAccessible(true); $pq = $this->obj; @@ -328,10 +331,10 @@ public function testPrivateReturnStructureThrowOnString() } /** * @depends testAttachStoresSomething - * @expectedException Exception */ public function testPrivateReturnStructureThrowOnInt() { + $this->expectException("Exception"); $rmeth = new ReflectionMethod($this->cut, '_returnStructure'); $rmeth->setAccessible(true); $pq = $this->obj; @@ -343,10 +346,10 @@ public function testPrivateReturnStructureThrowOnInt() } /** * @depends testAttachStoresSomething - * @expectedException Exception */ public function testPrivateReturnStructureThrowOnBool() { + $this->expectException("Exception"); $rmeth = new ReflectionMethod($this->cut, '_returnStructure'); $rmeth->setAccessible(true); $pq = $this->obj; @@ -358,10 +361,10 @@ public function testPrivateReturnStructureThrowOnBool() } /** * @depends testAttachStoresSomething - * @expectedException Exception */ public function testPrivateReturnStructureThrowOnEmptyArray() { + $this->expectException("Exception"); $rmeth = new ReflectionMethod($this->cut, '_returnStructure'); $rmeth->setAccessible(true); $pq = $this->obj; @@ -463,7 +466,7 @@ public function testPrivateReturnStructureReturnsFlagTypeOnRequest() 'inf' => 346 ); $r = $rmeth->invoke($pq, $mref); - $this->assertInternalType('array', $r); + $this->assertIsArray($r); $this->assertArrayHasKey('data', $r); $this->assertArrayHasKey('priority', $r); $this->assertEquals(spl_object_hash($obs), spl_object_hash($r['data'])); @@ -480,7 +483,7 @@ public function testPrivateReturnStructureReturnsFlagTypeOnRequest() public function testCurrent($fixtureArray) { list($pq, $rprop, $mockObserver) = $fixtureArray; - $pq = $this->getMock($this->cut, array( + $pq = $this->_makeMock($this->cut, array( '_returnStructure' )); $pq->setExtractFlag(Cpanel_Core_PriorityQueue::EXTR_DATA); @@ -708,10 +711,10 @@ public function getBadCompareInput() } /** * @dataProvider getBadCompareInput - * @expectedException Exception */ public function testCompareThrowsOnBadInput($a, $b) { + $this->expectException("Exception"); $pq = $this->obj; // $a = $badInput[0]; // $b = $badInput[1]; @@ -832,7 +835,7 @@ public function testTop($intList) */ public function testExtractCallsTop() { - $mock = $this->getMock($this->cut, array( + $mock = $this->_makeMock($this->cut, array( 'top' )); $mock->setExtractFlag(Cpanel_Core_PriorityQueue::EXTR_PRIORITY); @@ -864,7 +867,7 @@ public function testExtractGrabsFirstIndex() */ public function testGetInfoCallsValid() { - $mock = $this->getMock($this->cut, array( + $mock = $this->_makeMock($this->cut, array( 'valid' )); $mock->expects($this->once())->method('valid'); @@ -903,7 +906,7 @@ public function testGetInfoReturnsPriority() */ public function testSetInfoCallsValid() { - $mock = $this->getMock($this->cut, array( + $mock = $this->_makeMock($this->cut, array( 'valid' )); $mock->expects($this->once())->method('valid'); @@ -961,7 +964,7 @@ public function testSetInfoSetPriority() */ public function testOffsetSet() { - $mock = $this->getMock($this->cut, array( + $mock = $this->_makeMock($this->cut, array( 'offsetSet' )); $mock->expects($this->once())->method('offsetSet')->with($this->obs, 613); @@ -969,10 +972,10 @@ public function testOffsetSet() } /** * Verify Exception is throw for non object - * @expectedException Exception */ public function testOffsetSetThrowsOnBlankIndex() { + $this->expectException("Exception"); $obs = $this->getNewObserver(); $this->obj[] = 69; } @@ -991,7 +994,7 @@ public function testOffsetStores() public function testOffsetExists() { $obs = $this->getNewObserver(); - $mock = $this->getMock($this->cut, array( + $mock = $this->_makeMock($this->cut, array( 'contains' )); $mock->expects($this->once())->method('contains')->with($obs); @@ -1003,7 +1006,7 @@ public function testOffsetExists() public function testOffsetUnset() { $obs = $this->getNewObserver(); - $mock = $this->getMock($this->cut, array( + $mock = $this->_makeMock($this->cut, array( 'detach' )); $mock->expects($this->once())->method('detach')->with($obs); @@ -1015,7 +1018,7 @@ public function testOffsetUnset() public function testOffsetGetCallsContains() { $obs = $this->getNewObserver(); - $mock = $this->getMock($this->cut, array( + $mock = $this->_makeMock($this->cut, array( 'contains' )); $mock->expects($this->once())->method('contains')->with($obs); diff --git a/Cpanel/Tests/Cpanel/Listner/Subject/LoggerTest.php b/Cpanel/Tests/Cpanel/Listner/Subject/LoggerTest.php index 98ae1f4..ca67c70 100644 --- a/Cpanel/Tests/Cpanel/Listner/Subject/LoggerTest.php +++ b/Cpanel/Tests/Cpanel/Listner/Subject/LoggerTest.php @@ -1,11 +1,14 @@ getMockBuilder('SplObserver')->setMethods(array( + $mockObserver = $this->_makeMock('SplObserver', array( 'update' - ))->getMock(); + )); return $mockObserver; } /** @@ -82,7 +85,7 @@ public function testNewObserverWillBeStored($l) public function testAttachSeeksInternalStorage($fixtureArray) { list($l, $rprop, $mockObserver) = $fixtureArray; - $mock = $this->getMock($this->cut, array( + $mock = $this->_makeMock($this->cut, array( 'contains' )); $mock->expects($this->once())->method('contains')->with($this->anything())->will($this->returnValue(true)); @@ -95,7 +98,7 @@ public function testAttachSeeksInternalStorage($fixtureArray) public function testAttachWillCallChangePriorityForStoredObservers($fixtureArray) { list($l, $rprop, $mockObserver) = $fixtureArray; - $mock = $this->getMock($this->cut, array( + $mock = $this->_makeMock($this->cut, array( 'contains', 'changePriority' )); @@ -116,7 +119,7 @@ public function testDetachRequiresSplObserver() */ public function testDetachSeeksObserverInStorage() { - $mock = $this->getMock($this->cut, array( + $mock = $this->_makeMock($this->cut, array( 'contains' )); $mock->expects($this->once())->method('contains')->with($this->anything())->will($this->returnValue(true)); @@ -196,15 +199,17 @@ public function testNotifyCallsUpdateAccordingToPriority() foreach ($called as $observer) { $actual[] = spl_object_hash($observer); } + $expected = sort($expected); + $actual = sort($actual); $this->assertEquals($expected, $actual); } /** * Verify that first arg is object instance of SplObserver and exception is * thrown without arg2 - * @expectedException Exception */ public function testChangePriorityRequiresObserverAndPriority() { + $this->expectException('Exception'); $rmeth = new ReflectionMethod($this->cut, 'changePriority'); $rparams = $rmeth->getParameters(); $actual = $rparams[0]->getClass()->getName(); @@ -215,30 +220,30 @@ public function testChangePriorityRequiresObserverAndPriority() } /** * Verify string are not accepted for priority - * @expectedException Exception */ public function testChangePriorityThrowsOnStringForPriority() { + $this->expectException('Exception'); $l = new $this->cut(); $obs = $this->getMockSplObserver(); $l->changePriority($obs, '--fake--'); } /** * Verify bool are not accepted for priority - * @expectedException Exception */ public function testChangePriorityThrowsOnBoolForPriority() { + $this->expectException('Exception'); $l = new $this->cut(); $obs = $this->getMockSplObserver(); $l->changePriority($obs, true); } /** * Verify objs are not accepted for priority - * @expectedException Exception */ public function testChangePriorityThrowsOnObjectForPriority() { + $this->expectException('Exception'); $l = new $this->cut(); $obs = $this->getMockSplObserver(); $obj = new stdClass(); @@ -251,7 +256,8 @@ public function testChangePriorityCanTakeNumberForPriority() { $l = new $this->cut(); $obs = $this->getMockSplObserver(); - $l->changePriority($obs, 1); + // Ensure that this returns it self and doesn't throw an exception + $this->assertEquals($l, $l->changePriority($obs, 1)); } /** * Verify numbers in an array are accepted for priority @@ -260,17 +266,19 @@ public function testChangePriorityCanTakeNumbersInArrayForPriority() { $l = new $this->cut(); $obs = $this->getMockSplObserver(); - $l->changePriority($obs, array( + $value = array( 1, 2 - )); + ); + // Ensure that this returns it self and doesn't throw an exception + $this->assertEquals($l, $l->changePriority($obs, $value)); } /** * Verify non-numbers in an array are not accepted for priority - * @expectedException Exception */ public function testChangePriorityThrowOnStringInArrayForPriority() { + $this->expectException('Exception'); $l = new $this->cut(); $obs = $this->getMockSplObserver(); $l->changePriority($obs, array( @@ -280,10 +288,10 @@ public function testChangePriorityThrowOnStringInArrayForPriority() } /** * Verify non-numbers in an array are not accepted for priority - * @expectedException Exception */ public function testChangePriorityThrowOnObjInArrayForPriority() { + $this->expectException('Exception'); $l = new $this->cut(); $obs = $this->getMockSplObserver(); $obj = new stdClass(); @@ -294,10 +302,10 @@ public function testChangePriorityThrowOnObjInArrayForPriority() } /** * Verify bool in array are not accepted for priority - * @expectedException Exception */ public function testChangePriorityThrowsOnBoolInArrayForPriority() { + $this->expectException('Exception'); $l = new $this->cut(); $obs = $this->getMockSplObserver(); $l->changePriority($obs, array( @@ -307,10 +315,10 @@ public function testChangePriorityThrowsOnBoolInArrayForPriority() } /** * Verify null in array are not accepted for priority - * @expectedException Exception */ public function testChangePriorityThrowsOnNullInArrayForPriority() { + $this->expectException('Exception'); $l = new $this->cut(); $obs = $this->getMockSplObserver(); $l->changePriority($obs, array( @@ -320,10 +328,10 @@ public function testChangePriorityThrowsOnNullInArrayForPriority() } /** * Verify empty array are not accepted for priority - * @expectedException Exception */ public function testChangePriorityThrowsOnEmptyArrayForPriority() { + $this->expectException('Exception'); $l = new $this->cut(); $obs = $this->getMockSplObserver(); $l->changePriority($obs, array()); @@ -381,7 +389,7 @@ public function testGetDebugLevelReturnProtectedDebugLevel() } public function testSetDebugLevelSetsProtectedLevelAndCallsNotify() { - $l = $this->getMock($this->cut, array( + $l = $this->_makeMock($this->cut, array( 'notify' )); $l->expects($this->once())->method('notify'); diff --git a/Cpanel/Tests/Cpanel/Parser/JSONTest.php b/Cpanel/Tests/Cpanel/Parser/JSONTest.php index 4427941..a546be2 100644 --- a/Cpanel/Tests/Cpanel/Parser/JSONTest.php +++ b/Cpanel/Tests/Cpanel/Parser/JSONTest.php @@ -1,10 +1,13 @@ getMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); + $m = $this->_makeMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); return $m; } /** @@ -52,7 +55,7 @@ public function getRObj($mock = false, $methods = array(), $args = array(), $moc if (empty($methods)) { $methods = null; } - return $this->getMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); + return $this->_makeMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); } return new Cpanel_Query_Object(); } @@ -176,11 +179,6 @@ public function testSetMode($input, $mode) $p->setMode($input); $this->assertEquals($p->mode, $mode); } - public function testPrivateHasParseError() - { - $p = new $this->cut(); - $this->assertAttributeEquals(null, '_hasParseError', $p); - } public function testInterface() { $p = new $this->cut(); @@ -271,26 +269,30 @@ public function getPrettyJSONDataLarge($int = "\t") public function getJSONErrorMsg($errCode) { switch ($errCode) { - case JSON_ERROR_DEPTH: - $errmsg = 'Maximum stack depth exceeded.'; - break; - - case JSON_ERROR_CTRL_CHAR: - $errmsg = 'Unexpected control character found.'; - break; - - case JSON_ERROR_SYNTAX: - $errmsg = 'Syntax error, malformed JSON.'; - break; - - case JSON_ERROR_STATE_MISMATCH: - $errmsg = 'Invalid or malformed JSON.'; - break; - - default: - $errmsg = ''; + case JSON_ERROR_DEPTH: + return 'The maximum stack depth has been exceeded'; + case JSON_ERROR_STATE_MISMATCH: + return 'Invalid or malformed JSON'; + case JSON_ERROR_CTRL_CHAR: + return 'Control character error, possibly incorrectly encoded'; + case JSON_ERROR_SYNTAX: + return 'Syntax error'; + case JSON_ERROR_UTF8: + return 'Malformed UTF-8 characters, possibly incorrectly encoded'; + case JSON_ERROR_RECURSION: + return 'One or more recursive references in the value to be encoded'; + case JSON_ERROR_INF_OR_NAN: + return 'One or more NAN or INF values in the value to be encoded'; + case JSON_ERROR_UNSUPPORTED_TYPE: + return 'A value of a type that cannot be encoded was given'; + case JSON_ERROR_INVALID_PROPERTY_NAME: + return 'A property name that cannot be encoded was given'; + case JSON_ERROR_UTF16: + return 'Malformed UTF-16 characters, possibly incorrectly encoded'; + case JSON_ERROR_NONE: + default: + return ''; } - return $errmsg; } /** * @dataProvider rftData @@ -315,9 +317,6 @@ public function testGetParserInternalErrorsParameters() } $this->assertEquals($expected, $actual); } - /** - * @depends testPrivateHasParseError - */ public function testGetParserInternalErrorsReturnBlankByDefault() { $p = $this->getP(); @@ -388,7 +387,7 @@ public function badJSONData() ), array( $raw . "}", - JSON_ERROR_STATE_MISMATCH + JSON_ERROR_SYNTAX ), ); } @@ -460,10 +459,15 @@ public function parseMethodData() public function testParseThrowOnBadInput($input, $expectE) { if ($expectE) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $p = new $this->cut(); - $p->parse($input); + $result = $p->parse($input); + if(!$expectE && $input == ''){ + $this->assertEquals($result, 'JSON Decode - Cannot decode empty string.'); + }else{ + $this->assertEquals($result, $this->getParsedDataArray()); + } } public function parseMethodData2() { @@ -489,7 +493,7 @@ public function parseMethodData2() ), array( $raw . "}", - $classerr . $this->getJSONErrorMsg(JSON_ERROR_STATE_MISMATCH) + $classerr . $this->getJSONErrorMsg(JSON_ERROR_SYNTAX) ), ); } @@ -559,15 +563,16 @@ public function testEncodeQueryObjectThrowOnBadInput($input, $expectE) { $p = new $this->cut(); if ($expectE) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); + } + $result = $p->encodeQueryObject($input); + if(!$expectE){ + $this->assertEquals($result, '[]'); } - $p->encodeQueryObject($input); } - /** - * @expectedException Exception - */ public function testEncodeQueryObjectThrowOnBadEncode() { + $this->expectException('Exception'); $p = new $this->cut(); $data = array( 'foo' => 'bar', diff --git a/Cpanel/Tests/Cpanel/Parser/LiveJSONTest.php b/Cpanel/Tests/Cpanel/Parser/LiveJSONTest.php index f6387d3..57d4b4a 100644 --- a/Cpanel/Tests/Cpanel/Parser/LiveJSONTest.php +++ b/Cpanel/Tests/Cpanel/Parser/LiveJSONTest.php @@ -1,10 +1,13 @@ getMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); + $m = $this->_makeMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); return $m; } /** @@ -52,7 +55,7 @@ public function getRObj($mock = false, $methods = array(), $args = array(), $moc if (empty($methods)) { $methods = null; } - return $this->getMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); + return $this->_makeMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); } return new Cpanel_Query_Object($args); } @@ -176,11 +179,6 @@ public function testSetMode($input, $mode) $p->setMode($input); $this->assertEquals($p->mode, $mode); } - public function testPrivateHasParseError() - { - $p = new $this->cut(); - $this->assertAttributeEquals(null, '_hasParseError', $p); - } public function testInterface() { $p = new $this->cut(); @@ -326,28 +324,6 @@ public function testGetParserInternalErrorsParameters() } $this->assertEquals($expected, $actual); } - /** - * @depends testPrivateHasParseError - */ - public function testGetParserInternalErrorsReturnBlankByDefault() - { - $p = $this->getP(); - $this->assertEmpty($p->getParserInternalErrors()); - } - /** - * @depends testGetParserInternalErrorsReturnBlankByDefault - */ - public function testGetParserInternalErrorsReturnMinimumOfPrefix() - { - $p = new $this->cut(); - $prefix = 'foo'; - $rprop = new ReflectionProperty($p, '_hasParseError'); - $rprop->setAccessible(true); - $rprop->setValue($p, true); - $r = $p->getParserInternalErrors($prefix); - $condition = (strpos($r, $prefix) === 0); - $this->assertTrue($condition); - } /** * @depends testGetParserInternalErrorsParameters */ @@ -399,7 +375,7 @@ public function badJSONData() ), array( $raw . "}", - JSON_ERROR_STATE_MISMATCH + JSON_ERROR_SYNTAX ), ); } @@ -471,10 +447,15 @@ public function parseMethodData() public function testParseThrowOnBadInput($input, $expectE) { if ($expectE) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $p = new $this->cut(); - $p->parse($input); + $result = $p->parse($input); + if(!$expectE && $input == ''){ + $this->assertEquals($result, 'JSON Decode - Cannot decode empty string.'); + }else{ + $this->assertEquals($result, $this->getParsedDataArray()); + } } public function parseMethodData2() { @@ -505,7 +486,7 @@ public function parseMethodData2() ), array( $this->addLiveWrapTag($raw . "}"), - $classerr . $this->getJSONErrorMsg(JSON_ERROR_STATE_MISMATCH) + $classerr . $this->getJSONErrorMsg(JSON_ERROR_SYNTAX) ), ); } @@ -593,15 +574,15 @@ public function testEncodeQueryObjectThrowOnBadInput($input, $expectE) { $p = new $this->cut(); if ($expectE) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } - $p->encodeQueryObject($input); + $result = $p->encodeQueryObject($input); + // no assertions, not no exceptions either + $this->expectNotToPerformAssertions(); } - /** - * @expectedException Exception - */ public function testEncodeQueryObjectThrowOnBadEncode() { + $this->expectException('Exception'); $p = new $this->cut(); $data = array( 'foo' => 'bar', @@ -663,9 +644,11 @@ public function testEncodeQueryThrowOnBadInput($input, $expectE) { $p = new $this->cut(); if ($expectE) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $p->encodeQuery($input); + // no assertions, not no exceptions either + $this->expectNotToPerformAssertions(); } public function rObjData() { @@ -746,11 +729,10 @@ public function testEncodeQueryAcceptsGoodQueryData($reqtype, $module, $func, $a $rObj->query->func = $func; $rObj->query->apiversion = $apiverion; $rObj->query->args = $args; - if ($expectE) { - $this->setExpectedException('Exception'); - } $p = new $this->cut(); - $p->encodeQuery($rObj); + $result = $p->encodeQuery($rObj); + // no assertions, not no exceptions either + $this->expectNotToPerformAssertions(); } public function rObjData2() { diff --git a/Cpanel/Tests/Cpanel/Parser/XMLTest.php b/Cpanel/Tests/Cpanel/Parser/XMLTest.php index ae7fd41..4af94d5 100644 --- a/Cpanel/Tests/Cpanel/Parser/XMLTest.php +++ b/Cpanel/Tests/Cpanel/Parser/XMLTest.php @@ -1,10 +1,13 @@ getMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); + $m = $this->_makeMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); return $m; } /** @@ -52,7 +55,7 @@ public function getRObj($mock = false, $methods = array(), $args = array(), $moc if (empty($methods)) { $methods = null; } - return $this->getMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); + return $this->_makeMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); } return new Cpanel_Query_Object(); } @@ -199,11 +202,6 @@ public function testSetMode($input, $mode) $p->setMode($input); $this->assertEquals($p->mode, $mode); } - public function testPrivateHasParseError() - { - $p = new $this->cut(); - $this->assertAttributeEquals(null, '_hasParseError', $p); - } public function testInterface() { $p = new $this->cut(); @@ -273,28 +271,6 @@ public function testGetParserInternalErrorsParameters() } $this->assertEquals($expected, $actual); } - /** - * @depends testPrivateHasParseError - */ - public function testGetParserInternalErrorsReturnBlankByDefault() - { - $p = $this->getP(); - $this->assertEmpty($p->getParserInternalErrors()); - } - /** - * @depends testGetParserInternalErrorsReturnBlankByDefault - */ - public function testGetParserInternalErrorsReturnMinimumOfPrefix() - { - $p = new $this->cut(); - $prefix = 'foo'; - $rprop = new ReflectionProperty($p, '_hasParseError'); - $rprop->setAccessible(true); - $rprop->setValue($p, true); - $r = $p->getParserInternalErrors($prefix); - $condition = (strpos($r, $prefix) === 0); - $this->assertTrue($condition); - } /** * @depends testGetParserInternalErrorsParameters */ @@ -457,15 +433,18 @@ public function testEncodeQueryObjectThrowOnBadInput($input, $expectE) { $p = new $this->cut(); if ($expectE) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $p->encodeQueryObject($input); + // no assertions, not no exceptions either + $this->expectNotToPerformAssertions(); } /** - * @expectedException Exception + * @expectException Exception */ public function testEncodeQueryObjectThrowOnBadEncode() { + $this->expectException('Exception'); $p = new $this->cut(); $data = array( 'foo' => 'bar', @@ -544,12 +523,13 @@ public function badInput() ); } /** - * @expectedException Exception + * @expectException Exception * @dataProvider badInput * @paramsunknown_type $input */ public function testParseThrowOnBadInput($input) { + $this->expectException('Exception'); $p = new $this->cut(); $actual = $p->parse($input); } @@ -682,7 +662,7 @@ public function getXMLListPopsWithDisk() 2 <_diskquota>262144000 - <_diskused> + <_diskused/> 250 250 auththis diff --git a/Cpanel/Tests/Cpanel/PublicAPITest.php b/Cpanel/Tests/Cpanel/PublicAPITest.php index da120c1..d064784 100644 --- a/Cpanel/Tests/Cpanel/PublicAPITest.php +++ b/Cpanel/Tests/Cpanel/PublicAPITest.php @@ -1,19 +1,19 @@ expectException('Exception'); $cp = new Cpanel_PublicAPI(); } /** @@ -22,7 +22,7 @@ public function testCanNotInstanciateDirectly() public function testGetInstanceWithoutParam() { $cp = Cpanel_PublicAPI::getInstance(); - $this->assertInternalType('object', $cp); + $this->assertIsObject($cp); return $cp; } public static $simpleArray = array( @@ -84,10 +84,11 @@ public function testCanResetInstance() } /** * Verify clone will throw exception - * @expectedException Exception + * @expectException Exception */ public function testCloneThrowsException() { + $this->expectException('Exception'); $cp = Cpanel_PublicAPI::getInstance(); $no = clone $cp; } @@ -107,7 +108,7 @@ public function testGetInstanceWithArray() { Cpanel_PublicAPI::resetInstance(); $cp = Cpanel_PublicAPI::getInstance(self::$simpleArray); - $this->assertInternalType('object', $cp); + $this->assertIsObject($cp); return $cp; } /** @@ -143,7 +144,8 @@ public function mockCpanel($methods, $reveal = array()) $reveal = (is_array($reveal)) ? $reveal : array(); $reveal['_canInstantiate'] = true; //setup a mock; don't call construct when creating mock - $stub = $this->getMockBuilder('Cpanel_PublicAPI')->disableOriginalConstructor()->setMethods($methods)->getMock(); + + $stub = $this->_makeMock('Cpanel_PublicAPI',$methods,array(),'',false); foreach ($reveal as $key => $value) { $rprop = new ReflectionProperty('Cpanel_PublicAPI', $key); $rprop->setAccessible(true); @@ -159,11 +161,9 @@ public function testDefaultCreatesRegistry() Cpanel_PublicAPI::resetInstance(); $rprop = new ReflectionProperty('Cpanel_PublicAPI', '_registry'); $rprop->setAccessible(true); - //verify that the class defines a 'blank' value - $this->assertEmpty($rprop->getValue(new ReflectionClass('Cpanel_PublicAPI'))); //verify instantiate does the minimum, assigns an object to $_registry $cp = Cpanel_PublicAPI::getInstance(); - $this->assertInternalType('object', $rprop->getValue($cp)); + $this->assertIsObject($rprop->getValue($cp)); return $cp; } /** @@ -175,7 +175,7 @@ public function testGetRegistry($fixture) $rmeth = new ReflectionMethod('Cpanel_PublicAPI', 'getRegistry'); $rmeth->setAccessible(true); $obj = $rmeth->invoke($fixture); - $this->assertInternalType('object', $obj); + $this->assertIsObject($obj); } /** * Verify that registerRegistry is called during instantiation @@ -244,7 +244,7 @@ public function testGetNamedConfigReturnsEmptyArrayIfPassedEmptyArray() Cpanel_PublicAPI::resetInstance(); $cp = Cpanel_PublicAPI::getInstance(); $result = $cp->getNamedConfig('myserver1', array()); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEmpty($result); } /** @@ -258,7 +258,7 @@ public function testGetNamedConfigReturnsEmptyArrayIfPassedNameNotInConfig() Cpanel_PublicAPI::resetInstance(); $cp = Cpanel_PublicAPI::getInstance(); $result = $cp->getNamedConfig('--fake--', $cpObj); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEmpty($result); } /** @@ -383,10 +383,11 @@ public function testGetAggregateConfig() } /** * Factory should throw exception when invoked with 'blank' type, arg-0 - * @expectedException Exception + * @expectException Exception */ public function testFactoryThrowsExceptionWithArg0() { + $this->expectException('Exception'); Cpanel_PublicAPI::resetInstance(); Cpanel_PublicAPI::factory('', array(), ''); } @@ -479,11 +480,12 @@ public function testCallerReturnsRequestedObj() * invocation * * @depends testFactoryCanReturnWHMFromSimpleConfig - * @expectedException Exception + * @expectException Exception * @outputBuffering disabled */ public function testCallerThrowExceptionWhenNoArgsOnDispatchedApiRequest() { + $this->expectException('Exception'); $arr = array( 'service' => array( 'whm' => array( diff --git a/Cpanel/Tests/Cpanel/Query/Http/AbstractTest.php b/Cpanel/Tests/Cpanel/Query/Http/AbstractTest.php index 2fa7a83..7de8a1c 100644 --- a/Cpanel/Tests/Cpanel/Query/Http/AbstractTest.php +++ b/Cpanel/Tests/Cpanel/Query/Http/AbstractTest.php @@ -1,4 +1,7 @@ getMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); + return $this->_makeMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); } /** * @return Cpanel_Query_Object @@ -51,15 +54,16 @@ public function getRObj($mock = false, $methods = array(), $args = array(), $moc if (empty($methods)) { $methods = null; } - return $this->getMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); + return $this->_makeMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); } return new Cpanel_Query_Object(); } /** - * @expectedException Exception + * @expectException Exception */ public function testConstructThrowsOnBadInput() { + $this->expectException('Exception'); $rq = $this->getRQ(); $rmeth = new ReflectionMethod($this->cut, '__construct'); $rmeth->invoke($rq, new stdClass()); @@ -92,10 +96,11 @@ public function testHasAbstractMethods() $this->assertEquals($expected, $actual); } /** - * @expectedException Exception + * @expectException Exception */ public function testSetResponseObjectThrowOnNonQueryObject() { + $this->expectException('Exception'); $rq = $this->getRQ(); $rq->setResponseObject(new stdClass()); } @@ -105,7 +110,7 @@ public function testSetResponseObjectThrowOnNonQueryObject() public function testSetResponseObjectDoesSomething() { $rObj = $this->getRObj(); - $mock = $this->getMock($this->cut, array( + $mock = $this->_makeMock($this->cut, array( 'setOptions' )); $mock->expects($this->once())->method('setOptions')->with(array( @@ -163,10 +168,11 @@ public function testInitCallsGetValidClientType() /** * Verify client type is checked * @depends testInitCallsGetValidClientType - * @expectedException Exception + * @expectException Exception */ public function testInitThrowsOnBadGetClientTypeReturn() { + $this->expectException('Exception'); $rq = $this->getRQ(array( 'getValidClientType' )); @@ -183,10 +189,11 @@ public function testInitCallsSetProtocol() } /** * @depends testInitParamOrder - * @expectedException Exception + * @expectException Exception */ public function testInitThrowsWithoutHost() { + $this->expectException('Exception'); $rq = $this->getRQ(); $rq->init(); } @@ -433,7 +440,7 @@ public function testSetPortCoercesString() $rprop->setValue($rq, $base); $rq->setPort($portStr); $actual = $rprop->getValue($rq); - $this->assertInternalType('integer', $actual); + $this->assertIsInt($actual); } /** * Verify only valid ports @@ -461,10 +468,11 @@ public function testSetPortThrowOnInvalidPort($ports) $this->assertEquals($ports, $eports); } /** - * @expectedException Exception + * @expectException Exception */ public function testSetPortThrowOnInvalidCalculatedProtocol() { + $this->expectException('Exception'); $port = 2086; $rprop = new ReflectionProperty($this->cut, 'port'); $rprop->setAccessible(true); @@ -502,10 +510,11 @@ public function testLegacySetProtocolCallsSetProtocol() } /** * Verify throws on non 'http'|'https' - * @expectedException Exception + * @expectException Exception */ public function testSetProtocolThrowsOnInvalid() { + $this->expectException('Exception'); $rq = $this->getRQ(); $rq->setProtocol('foo'); } @@ -548,10 +557,11 @@ public function testLegacySetAuthTypeCallsSetAuthType() $rq->set_auth_type($o); } /** - * @expectedException Exception + * @expectException Exception */ public function testSetAuthTypeThrowsOnBadInput() { + $this->expectException('Exception'); $rprop = new ReflectionProperty($this->cut, 'auth_type'); $rprop->setAccessible(true); $rq = $this->getRQ(); @@ -568,6 +578,9 @@ public function testSetAuthType() $rq->setAuthType($expected); $actual = $rprop->getValue($rq); $this->assertEquals($expected, $actual); + $rq->setAuthType('token'); + $actual = $rprop->getValue($rq); + $this->assertEquals('token', $actual); } public function testLegacySetPasswordCallsSetPassword() { @@ -635,7 +648,14 @@ public function testSetHashCleansPrintChar() { $rq = $this->getRQ(); $rq->setHash("foo\r\nbar\r\n\n\r"); - $this->assertAttributeEquals('foobar', 'auth', $rq); + + $reflector = new ReflectionObject($rq); + $attribute = $reflector->getProperty('auth'); + $attribute->setAccessible(true); + $value = $attribute->getValue($rq); + $attribute->setAccessible(false); + + $this->assertEquals('foobar', $value); } public function testLegacySetUserCallsSetUser() { @@ -718,10 +738,11 @@ public function testLegacySetHttpClientCallsSetHttpClient() $rq->set_http_client($o); } /** - * @expectedException Exception + * @expectException Exception */ public function testSetHttpClientWillThrowOnInvalidInput() { + $this->expectException('Exception'); $rq = $this->getRQ(); $rq->setHttpClient('foo'); } @@ -828,10 +849,11 @@ public function testIsURLParamStrTrueForValidInput($data, $unstrict, $strict) $this->assertEquals($strict, $rq->isURLParamStr($data, true)); } /** - * @expectedException Exception + * @expectException Exception */ public function testBuildURLThrowsOnBadQueryObject() { + $this->expectException('Exception'); $vars = array( 'function' => 'version', 'host' => '1.1.1.1', @@ -920,7 +942,7 @@ public function testBuildURLReturnsURL($arraySet) } } if ($vars['expectException']) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); $rq->buildURL($vars['function']); } else { $actual = $rq->buildURL($vars['function']); @@ -1000,41 +1022,53 @@ public function testBuildAuthStrReturnsPasswordAuthStr() $actual = $rq->buildAuthStr(); $this->assertEquals($expected, $actual); } + public function testBuildAuthStrReturnsTokenAuthStr() + { + $user = 'jeb'; + $auth_type = 'token'; + $token = 'MYTOKENSTR'; + $rq = $this->getRQ(); + $rq->setAuthType($auth_type); + $rq->setUser($user); + $rq->setToken($token); + $expected = "Authorization: cpanel $user:$token\r\n"; + $actual = $rq->buildAuthStr(); + $this->assertEquals($expected, $actual); + } /** - * @expectedException Exception + * @expectException Exception */ public function testBuildAuthStrThrowsOnBadAuthType() { + $this->expectException('Exception'); $user = 'jeb'; $auth_type = 'badinput'; $auth = 'foobarbazblurg'; $rq = $this->getRQ(); - $rprop = new ReflectionProperty($this->cut, 'auth_type'); - $rprop->setAccessible(true); - $rprop->setValue($rq, $auth_type); - $rprop = new ReflectionProperty($this->cut, 'auth'); - $rprop->setAccessible(true); - $rprop->setValue($rq, $auth); - $rprop = new ReflectionProperty($this->cut, 'user'); - $rprop->setAccessible(true); - $rprop->setValue($rq, $user); + + $rq->setAuthType($auth_type); + $rq->setUser($user); + $rq->setHash($auth); + $expected = "Authorization: Basic " . base64_encode($user . ':' . $auth) . "\r\n"; $actual = $rq->buildAuthStr(); $this->assertEquals($expected, $actual); } /** - * @expectedException Exception + * @expectException Exception */ public function testExecThrowsOnBadInput() { + $this->expectException('Exception'); $rq = $this->getRQ(); $rq->exec(new stdClass()); } /** - * @expectedException Exception + * @expectException Exception */ public function testExecThrowsOnUndefinedQueryClient() { + $this->expectException('Exception'); $rq = $this->getRQ(); $rObj = $this->getRObj(); $rObj->setQuery(array( @@ -1043,10 +1077,11 @@ public function testExecThrowsOnUndefinedQueryClient() $rq->exec($rObj); } /** - * @expectedException Exception + * @expectException Exception */ public function testExecThrowsOnUndefinedQueryClientMethod() { + $this->expectException('Exception'); $rq = $this->getRQ(); $rObj = $this->getRObj(); $rObj->setQuery(array( @@ -1156,28 +1191,32 @@ public function testMakeQueryFixtureSanity() { list($rq, $rObj) = $this->getMakeQueryFixture(); $rq->makeQuery('version'); + $this->expectNotToPerformAssertions(); } /** - * @expectedException Exception + * @expectException Exception */ public function testMakeQueryThrowsOnEmptyInputFunctionVariable() { + $this->expectException('Exception'); list($rq, $rObj) = $this->getMakeQueryFixture(); $rq->makeQuery(''); } /** - * @expectedException Exception + * @expectException Exception */ public function testMakeQueryThrowsOnUndefinedPrivateUser() { + $this->expectException('Exception'); list($rq, $rObj) = $this->getMakeQueryFixture(false); $rq->makeQuery('version'); } /** - * @expectedException Exception + * @expectException Exception */ public function testMakeQueryThrowsOnUndefinedPrivateAuth() { + $this->expectException('Exception'); list($rq, $rObj) = $this->getMakeQueryFixture(null, null, false); $rq->makeQuery('version'); } @@ -1230,12 +1269,14 @@ public function testMakeQueryCallsGetResponseObject() list($rq, $rObj) = $this->getMakeQueryFixture(null, null, null, $methods); $rq->expects($this->any())->method('getResponseObject')->will($this->returnValue($rObj)); $rq->makeQuery('version'); + $this->expectNotToPerformAssertions(); } /** - * @expectedException Exception + * @expectException Exception */ public function testMakeQueryWillThrowOnBadResponseObject() { + $this->expectException('Exception'); $methods = array( 'curlExec', 'exec', @@ -1319,10 +1360,11 @@ public function testAddCurlPostFieldsParams() $this->assertEquals($expected, $actual); } /** - * @expectedException Exception + * @expectException Exception */ public function testAddCurlPostFieldsThrowOnInvalidResource() { + $this->expectException('Exception'); $rq = $this->getRQ(); $rmeth = new ReflectionMethod($this->cut, 'addCurlPostFields'); $rmeth->setAccessible(true); @@ -1334,13 +1376,14 @@ public function testAddCurlPostFieldsReturnsString() $rmeth = new ReflectionMethod($this->cut, 'addCurlPostFields'); $rmeth->setAccessible(true); $actual = $rmeth->invoke($rq, curl_init(), '', 'what=ever'); - $this->assertInternalType('string', $actual); + $this->assertIsString($actual); } /** - * @expectedException Exception + * @expectException Exception */ public function testBuildCurlHeadersThrowsOnBadInput() { + $this->expectException('Exception'); $user = 'foo'; $pass = 'bar'; $postdata = 'what=ever'; @@ -1379,7 +1422,7 @@ public function testBuildCurlHeadersReturnsArray() $rmeth = new ReflectionMethod($this->cut, 'buildCurlHeaders'); $rmeth->setAccessible(true); $actual = $rmeth->invoke($rq, $curl, $rObj); - $this->assertInternalType('array', $actual); + $this->assertIsArray($actual); } public function testBuildCurlHeadersDoesNotAlterURLForPOST() { @@ -1481,30 +1524,33 @@ public function testBuildCurlHeadersAltersURLForGET() $this->assertEquals("{$url}?{$postdata}", $rObj->query->url); } /** - * @expectedException Exception + * @expectException Exception */ public function testCurlExecRequiresResource() { + $this->expectException('Exception'); $rq = $this->getRQ(); $rmeth = new ReflectionMethod($this->cut, 'curlExec'); $rmeth->setAccessible(true); $actual = $rmeth->invoke($rq, new stdClass()); } /** - * @expectedException Exception + * @expectException Exception */ public function testCurlExecThrowsOnBadCall() { + $this->expectException('Exception'); $rq = $this->getRQ(); $rmeth = new ReflectionMethod($this->cut, 'curlExec'); $rmeth->setAccessible(true); $actual = $rmeth->invoke($rq, curl_init()); } /** - * @expectedException Exception + * @expectException Exception */ public function testCurlExecThrowsOnBadCallDetailsRObj() { + $this->expectException('Exception'); $postdata = 'what=ever'; $url = 'blurg'; $rq = $this->getRQ(); @@ -1517,10 +1563,11 @@ public function testCurlExecThrowsOnBadCallDetailsRObj() $actual = $rmeth->invoke($rq, curl_init()); } /** - * @expectedException Exception + * @expectException Exception */ public function testCurlQueryThrowsOnBadInput() { + $this->expectException('Exception'); $rObj = $this->getRObj(); $rq = $this->getRQ(array( 'buildCurlHeaders' @@ -1528,10 +1575,11 @@ public function testCurlQueryThrowsOnBadInput() $rq->curlQuery(new stdClass()); } /** - * @expectedException Exception + * @expectException Exception */ public function testCurlQueryThrowsOnBadCall() { + $this->expectException('Exception'); $rObj = $this->getRObj(); $rq = $this->getRQ(array( 'buildCurlHeaders' @@ -1552,7 +1600,7 @@ public function testCurlQueryCallsCurlExec() } public function testCurlQueryAttemptsToLogData() { - $listner = $this->getMock('Cpanel_Listner_Subject_Logger', array( + $listner = $this->_makeMock('Cpanel_Listner_Subject_Logger', array( 'log' )); $listner->expects($this->once())->method('log'); @@ -1583,10 +1631,11 @@ public function testCurlQueryCallsBuildCurlHeaders() $rq->curlQuery($rObj); } /** - * @expectedException Exception + * @expectException Exception */ public function testFopenQueryThrowsOnBadInput() { + $this->expectException('Exception'); $url = 'http://1.1.1.1:2086/xml-api/version'; $proto = 'http'; $rObj = $this->getRObj(); @@ -1601,10 +1650,11 @@ public function testFopenQueryThrowsOnBadInput() $rq->fopenQuery(new stdClass()); } /** - * @expectedException Exception + * @expectException Exception */ public function testBuildFopenContextOptsThrowsOnBadInput() { + $this->expectException('Exception'); $rq = $this->getRQ(); $rmeth = new ReflectionMethod($this->cut, 'buildFopenContextOpts'); $rmeth->setAccessible(true); @@ -1617,7 +1667,7 @@ public function testBuildFopenContextOptsReturnsArray() $rmeth = new ReflectionMethod($this->cut, 'buildFopenContextOpts'); $rmeth->setAccessible(true); $actual = $rmeth->invoke($rq, $rObj); - $this->assertInternalType('array', $actual); + $this->assertIsArray($actual); } public function testBuildFopenContextExercisesOptsValues() { @@ -1699,7 +1749,7 @@ public function testFopenQueryCallsGetProtocol($url, $proto, $valid) $rq->expects($this->once())->method('getProtocol')->will($this->returnValue($proto)); $rq->expects($this->any())->method('fopenExec')->will($this->returnValue($this->anything())); if (!$valid) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $rq->fopenQuery($rObj); } @@ -1718,12 +1768,14 @@ public function testFopenQueryCallsBuildFopenContextOpts() $rq->expects($this->any())->method('fopenExec')->will($this->returnValue($this->anything())); $rq->expects($this->any())->method('buildFopenContextOpts')->with($rObj)->will($this->returnValue(array())); $rq->fopenQuery($rObj); + $this->expectNotToPerformAssertions(); } /** - * @expectedException Exception + * @expectException Exception */ public function testFopenExecThrowsOnInvalidStreamContext() { + $this->expectException('Exception'); $url = 'https://1.1.1.1:2087/xml-api/version'; $context = ''; $rq = $this->getRQ(); @@ -1732,10 +1784,11 @@ public function testFopenExecThrowsOnInvalidStreamContext() $rmeth->invoke($rq, $url, false, $context); } /** - * @expectedException Exception + * @expectException Exception */ public function testFopenExecThrowsOnNonURL() { + $this->expectException('Exception'); $url = 'https://'; $context = stream_context_create(array()); $rq = $this->getRQ(); @@ -1806,10 +1859,11 @@ public function testMagicCallSetsNonPrivateNonSetterVariableToCpanelObjectStore( $actual = $rq->set_foo($arr['foo']); } /** - * @expectedException Exception + * @expectException Exception */ public function testMagicCallThrowsOnNonGetOrSetMethodCall() { + $this->expectException('Exception'); $rq = $this->getRQ(array( 'setOptions', 'getOption', diff --git a/Cpanel/Tests/Cpanel/Query/Live/AbstractTest.php b/Cpanel/Tests/Cpanel/Query/Live/AbstractTest.php index 5c560b1..f4301c7 100644 --- a/Cpanel/Tests/Cpanel/Query/Live/AbstractTest.php +++ b/Cpanel/Tests/Cpanel/Query/Live/AbstractTest.php @@ -1,4 +1,7 @@ getMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); + $m = $this->_makeMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); return $m; } /** @@ -70,16 +73,16 @@ public function getRObj($mock = false, $methods = array(), $args = array(), $moc if (empty($methods)) { $methods = null; } - return $this->getMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); + return $this->_makeMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); } return new Cpanel_Query_Object(); } // public static function setUpBeforeClass() - public function setUp() + public function setUp(): void { self::startMSS(); } - public function tearDown() + public function tearDown(): void { self::stopMSS(); } @@ -112,7 +115,7 @@ public static function startMSS() self::fail('Socket file does not exist: ' . $socketfile); } } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { if (!empty(self::$fakeResources)) { foreach (self::$fakeResources as $name => $fh) { @@ -250,10 +253,11 @@ public function testCanInstantiateClean() $obj->__destruct(); } /** - * @expectedException Exception + * @expectException Exception */ public function testConstructThrowsOnBadInput() { + $this->expectException('Exception'); $lq = $this->getLQ(); $rmeth = new ReflectionMethod($this->cut, '__construct'); $rmeth->invoke($lq, new stdClass()); @@ -347,20 +351,22 @@ public function testOpenCpanelHandleInvokesPrivateIntJSONMode() $this->assertTrue($condition); } /** - * @expectedException Exception + * @expectException Exception */ public function testPrivateIntJSONModeThrowsIfNotConnected() { + $this->expectException('Exception'); $lq = $this->getLQ(); $rmeth = new ReflectionMethod($lq, '_initJSONMode'); $rmeth->setAccessible(true); $rmeth->invoke($lq); } /** - * @expectedException Exception + * @expectException Exception */ public function testOpenCpanelHandleThrowsOnBadSocketfile() { + $this->expectException('Exception'); $lq = $this->getLQ(); putenv('CPANEL_PHPCONNECT_SOCKET='); $lq->openCpanelHandle(); @@ -369,19 +375,25 @@ public function testOpenCpanelHandleThrowsOnBadSocketfile() * looks like this test passed due to warn by fsockopen, and not the scripted * exception throw * @todo consider reworking or removing; might be untestable - * @expectedException Exception + * @expectException Exception */ public function testOpenCpanelHandleThrowsOnBadfsockopen() { $lq = $this->getLQ(); - putenv('CPANEL_PHPCONNECT_SOCKET=/dev/null'); - $lq->openCpanelHandle(); + try { + putenv('CPANEL_PHPCONNECT_SOCKET=/dev/null'); + $lq->openCpanelHandle(); + } catch ( Exception $e ) { + $this->assertEquals('fsockopen(): unable to connect to unix:///dev/null:-1 (Socket operation on non-socket)',$e->getMessage()); + } + } /** - * @expectedException Exception + * @expectException Exception */ public function testSetResponseObjectThrowsOnBadInput() { + $this->expectException('Exception'); $lq = $this->getLQ(); $lq->setResponseObject(new stdClass()); } @@ -416,7 +428,7 @@ public function testSafeClose() $rprop = new ReflectionProperty($this->real_cut, '_cpanelfh'); $rprop->setAccessible(true); $actual = $rprop->getValue($lq); - $this->assertInternalType('resource', $actual); + $this->assertIsResource($actual); $rmeth = new ReflectionMethod($this->real_cut, '_write'); $rmeth->setAccessible(true); $rmeth->invoke($lq, Cpanel_Tests_MockSocketServer::C_ENABLE_JSON); @@ -427,10 +439,11 @@ public function testSafeClose() $this->assertNull($actual); } /** - * @expectedException mockException + * @expectException mockException */ public function testExecCallsOpenCpanelHandleIfNotConnected() { + $this->expectException('mockException'); $lq = $this->getLQ(array( 'openCpanelHandle' )); @@ -456,12 +469,15 @@ public function testExecTakesCodeInputString() $lq = $this->getLQ(); $lq->setResponseObject($this->getRObj()); $lq->exec($code, 1); + // no assertions, not no exceptions either + $this->expectNotToPerformAssertions(); } /** - * @expectedException Exception + * @expectException Exception */ public function testExecRequiresResponseObjectBeSet() { + $this->expectException('Exception'); $code = Cpanel_Tests_MockSocketServer::C_ENABLE_JSON; $lq = $this->getLQ(array( 'getResponseObject' @@ -470,10 +486,11 @@ public function testExecRequiresResponseObjectBeSet() $lq->exec($code, 1); } /** - * @expectedException Exception + * @expectException Exception */ public function testExecTakesCodeThrowOnBadInput() { + $this->expectException('Exception'); $code = Cpanel_Tests_MockSocketServer::C_ENABLE_JSON; $lq = $this->getLQ(); $lq->setResponseObject($this->getRObj()); @@ -482,10 +499,11 @@ public function testExecTakesCodeThrowOnBadInput() ), 1); } /** - * @expectedException Exception + * @expectException Exception */ public function testExecThrowsOnEmptyComputedCodeString() { + $this->expectException('Exception'); $rObj = $this->getRObj(true, array( 'getResponseFormatType' )); @@ -547,10 +565,11 @@ public function testMakeQueryInputArguments() $this->assertEquals($args, $actual); } /** - * @expectedException Exception + * @expectException Exception */ public function testMakeQueryOptionalArgsMustBeArray() { + $this->expectException('Exception'); $lq = $this->getLQ(array( 'exec' )); @@ -599,10 +618,11 @@ public function testMakeQueryCallsExecWithResponseObject() )); } /** - * @expectedException Exception + * @expectException Exception */ public function testMagicCallWillAlwaysThrow() { + $this->expectException('Exception'); $lq = $this->getLQ(); $lq->getBlah(); } diff --git a/Cpanel/Tests/Cpanel/Query/ObjectTest.php b/Cpanel/Tests/Cpanel/Query/ObjectTest.php index 6facd6a..1cc1999 100644 --- a/Cpanel/Tests/Cpanel/Query/ObjectTest.php +++ b/Cpanel/Tests/Cpanel/Query/ObjectTest.php @@ -1,4 +1,7 @@ getMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); + $m = $this->_makeMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); return $m; } public function getParser($mock = false, $methods = array(), $args = array(), $mockName = '', $callConst = true, $callClone = true, $callA = true) @@ -52,7 +55,7 @@ public function getParser($mock = false, $methods = array(), $args = array(), $m if (empty($methods)) { $methods = null; } - return $this->getMock($this->p, $methods, $args, $mockName, $callConst, $callClone, $callA); + return $this->_makeMock($this->p, $methods, $args, $mockName, $callConst, $callClone, $callA); } return new $this->p(); } @@ -160,10 +163,20 @@ public function testQueryObjectProperties($name, $visibility, $defaultValue = '' $this->assertTrue($prop->isPrivate()); break; } + + $reflector = new ReflectionObject($rObj); + $attribute = $reflector->getProperty($name); + $attribute->setAccessible(true); + $value = $attribute->getValue($rObj); + $attribute->setAccessible(false); + if (is_object($defaultValue)) { - $this->assertAttributeInstanceOf(get_class($defaultValue), $name, $rObj); + $class = get_class($defaultValue); + $this->assertInstanceOf(get_class($defaultValue), $value); } elseif ($defaultValue !== '') { - $this->assertAttributeEquals($defaultValue, $name, $rObj); + $this->assertEquals($defaultValue, $value); + }else{ + $this->assertEquals($defaultValue, $value); } } public function testSetResponseFormatTypeStoresFT() @@ -204,10 +217,11 @@ public function testSetResponseFormatTypeAttemptToReusePreviouslyStoredParser() $rObj->setResponseFormatType('foo'); } /** - * @expectedException Exception + * @expectException Exception */ public function testSetResponseFormatTypeThrowForPreviouslyStoredParserCanNotParse() { + $this->expectException('Exception'); $rObj = $this->getRObj(array( 'setResponseParser', 'getValidParser' @@ -224,10 +238,11 @@ public function testSetResponseFormatTypeThrowForPreviouslyStoredParserCanNotPar $rObj->setResponseFormatType('foo'); } /** - * @expectedException Exception + * @expectException Exception */ public function testSetResponseFormatTypeThrowsOnBadInterface() { + $this->expectException('Exception'); $rObj = $this->getRObj(array( 'setResponseParser', 'getValidParser' @@ -294,10 +309,11 @@ public function testGetValidParserWillLoadCustomParser() $this->assertInstanceOf(get_class($p), $actual); } /** - * @expectedException Exception + * @expectException Exception */ public function testGetValidParserThrowOnBadCustomParser() { + $this->expectException('Exception'); $rObj = new $this->cut(); $p = 'fooBarBaz'; //need to suppress warnings as the Zend autoload with call include_once() @@ -308,10 +324,11 @@ public function testGetValidParserThrowOnBadCustomParser() $actual = @$rObj->getValidParser($p); } /** - * @expectedException Exception + * @expectException Exception */ public function testGetValidParserThrowOnCustomParserWhichDoesNotImplementParserInterface() { + $this->expectException('Exception'); $rObj = new $this->cut(); $p = 'stdClass'; //need to suppress warnings as the Zend autoload with call include_once() @@ -363,10 +380,11 @@ public function testSetResponseParserEnforcesPrivatePinterface() $this->assertEquals($p, $rprop->getValue($rObj)); } /** - * @expectedException Exception + * @expectException Exception */ public function testSetResponseParserEnforcesPrivatePinterfaceFailTest() { + $this->expectException('Exception'); $rObj = new $this->cut(); $p = new stdClass(); $rprop = new ReflectionProperty($this->cut, '_pinterface'); @@ -459,7 +477,7 @@ public function testSetResponseUsesUnderlyingSetOptionsOnPrivateResponse() { $rObj = new $this->cut(); $arg = $this->getParsedDataArray(); - $container = $this->getMock('Cpanel_Core_Object', array( + $container = $this->_makeMock('Cpanel_Core_Object', array( 'setOptions' )); $container->expects($this->once())->method('setOptions')->with($arg); @@ -629,7 +647,7 @@ public function testSetQueryUsesUnderlyingContainer() { $rObj = new $this->cut(); $arg = $this->getParsedDataArray(); - $container = $this->getMock('Cpanel_Core_Object', array( + $container = $this->_makeMock('Cpanel_Core_Object', array( 'setOptions' )); $container->expects($this->once())->method('setOptions')->with($arg); @@ -670,7 +688,7 @@ public function testSetRawResponseLogsToListnerIfAvaliableAndInDebugLogMode() { $foo = 'raw response string'; $expected = "Storing RawResponse:\n$foo"; - $l = $this->getMock('Cpanel_Listner_Subject_Logger', array( + $l = $this->_makeMock('Cpanel_Listner_Subject_Logger', array( 'log' )); $l->expects($this->once())->method('log')->with('debug', $expected)->will($this->returnValue($this->anything())); @@ -703,7 +721,7 @@ public function testProtectedParseWithParserUnderNormalConditions() $this->assertEquals($this->getParsedDataArray(), $actual); } /** - * @expectedException Exception + * @expectException Exception * @depends testSetRawResponseDoesSomething * @depends testSetResponseErrorStoresStringInPrivateResponseErrors * @depends testSetResponseUsesUnderlyingSetOptionsOnPrivateResponse @@ -714,6 +732,7 @@ public function testProtectedParseWithParserUnderNormalConditions() */ public function testProtectedParseThrowsOnParserNotImplementingPrivatePinterface() { + $this->expectException('Exception'); $raw = $this->getRawJsonData(); $rObj = new $this->cut(); $rObj->setRawResponse($raw); @@ -752,7 +771,7 @@ public function testParseUnderSetsErrorOnParseErrorAndHasArray() $expected = array(); $this->assertEquals($expected, $actual); $errstr = implode(',', $rObj->getResponseErrors()); - $this->assertContains($rObj::ERROR_RESPONSE, $errstr); + $this->assertStringContainsString($rObj::ERROR_RESPONSE, $errstr); } /** * @depends testParseUnderNormalConditions diff --git a/Cpanel/Tests/Cpanel/Service/Adapter/CpanelapiTest.php b/Cpanel/Tests/Cpanel/Service/Adapter/CpanelapiTest.php index 0951b62..fb266cc 100644 --- a/Cpanel/Tests/Cpanel/Service/Adapter/CpanelapiTest.php +++ b/Cpanel/Tests/Cpanel/Service/Adapter/CpanelapiTest.php @@ -1,10 +1,13 @@ getMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); + $m = $this->_makeMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); return $m; } /** @@ -55,7 +58,7 @@ public function getRObj($mock = false, $methods = array(), $args = array(), $moc if (empty($methods)) { $methods = null; } - return $this->getMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); + return $this->_makeMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); } return new Cpanel_Query_Object(); } @@ -64,11 +67,6 @@ public function testConstantDRFT() $classname = $this->cut; $this->assertEquals($this->DRFT, $classname::DRFT); } - public function testPrivateValidRFT() - { - $a = new $this->cut(); - $this->assertAttributeEquals($this->_validRFT, '_validRFT', $a); - } public function testConstructArgs() { $rmeth = new ReflectionMethod($this->cut, '__construct'); @@ -129,23 +127,12 @@ public function rftData() public function testSetAdapterResponseFormatType($type, $expectE) { if ($expectE) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $a = $this->getA(null, array(), '', false); $a->setAdapterResponseFormatType($type); - } - /** - * @depends testSetAdapterResponseFormatType - */ - public function testConstructWillSetVars() - { - list($h, $u, $p, $RFT) = $this->constructVars(); - $a = new $this->cut($h, $u, $p, $RFT); - $this->assertAttributeEquals($h, 'host', $a); - $this->assertAttributeEquals($p, 'auth', $a); - $this->assertAttributeEquals('pass', 'auth_type', $a); - $this->assertAttributeEquals($u, 'user', $a); - $this->assertAttributeEquals($RFT, '_adapterResponseFormatType', $a); + // no assertions, not no exceptions either + $this->expectNotToPerformAssertions(); } public function testConstructSanitizesRFT() { @@ -155,14 +142,6 @@ public function testConstructSanitizesRFT() $a->expects($this->once())->method('setAdapterResponseFormatType'); $a->__construct(); } - /** - * @depends testConstantDRFT - */ - public function testConstructWillSeRFTByDefault() - { - $a = new $this->cut(); - $this->assertAttributeEquals($this->DRFT, '_adapterResponseFormatType', $a); - } public function testGetAdapterResponseFormatTypeFetchesStored() { list($h, $u, $p, $RFT) = $this->constructVars(); @@ -285,7 +264,6 @@ public function apiQueryData2() ); } /** - * @depends testConstructWillSetVars * @dataProvider apiQueryData * @paramsunknown_type $user * @paramsunknown_type $mod @@ -296,7 +274,7 @@ public function apiQueryData2() public function testLegacyApi1UnderscoreQueryRequiresInput($user = '', $mod = '', $func = '', $args = '', $expectE = 0) { if ($expectE) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $a = $this->getA(array( 'makeQuery' @@ -304,9 +282,10 @@ public function testLegacyApi1UnderscoreQueryRequiresInput($user = '', $mod = '' $rObj = $this->getRObj(); $a->setResponseObject($rObj); $a->api1_query($user, $mod, $func, $args); + // no assertions, not no exceptions either + $this->expectNotToPerformAssertions(); } /** - * @depends testConstructWillSetVars * @dataProvider apiQueryData * @paramsunknown_type $user * @paramsunknown_type $mod @@ -317,7 +296,7 @@ public function testLegacyApi1UnderscoreQueryRequiresInput($user = '', $mod = '' public function testLegacyApi2UnderscoreQueryRequiresInput($user = '', $mod = '', $func = '', $args = '', $expectE = 0) { if ($expectE) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $a = $this->getA(array( 'makeQuery' @@ -325,6 +304,8 @@ public function testLegacyApi2UnderscoreQueryRequiresInput($user = '', $mod = '' $rObj = $this->getRObj(); $a->setResponseObject($rObj); $a->api2_query($user, $mod, $func, $args); + // no assertions, not no exceptions either + $this->expectNotToPerformAssertions(); } /** * @depends testLegacyApi2UnderscoreQueryRequiresInput diff --git a/Cpanel/Tests/Cpanel/Service/Adapter/LiveapiTest.php b/Cpanel/Tests/Cpanel/Service/Adapter/LiveapiTest.php index dddab40..5154677 100644 --- a/Cpanel/Tests/Cpanel/Service/Adapter/LiveapiTest.php +++ b/Cpanel/Tests/Cpanel/Service/Adapter/LiveapiTest.php @@ -1,5 +1,8 @@ getMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); + $m = $this->_makeMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); return $m; } /** @@ -53,16 +56,16 @@ public function getRObj($mock = false, $methods = array(), $args = array(), $moc if (empty($methods)) { $methods = null; } - return $this->getMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); + return $this->_makeMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); } return new Cpanel_Query_Object(); } // public static function setUpBeforeClass() - public function setUp() + public function setUp(): void { self::startMSS(); } - public function tearDown() + public function tearDown(): void { self::stopMSS(); } @@ -95,7 +98,7 @@ public static function startMSS() self::fail('Socket file does not exist: ' . $socketfile); } } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { if (!empty(self::$fakeResources)) { foreach (self::$fakeResources as $name => $fh) { @@ -263,10 +266,11 @@ public function testConstructOptionallyTakesRFTAndStoresIt() $this->assertContains('foo', $rprop->getValue($live)); } /** - * @expectedException Exception + * @expectException Exception */ public function testSetAdapterResponseFormatTypeThrowOnUnknownType() { + $this->expectException('Exception'); $live = $this->getLive(); $live->setAdapterResponseFormatType('FooBarFooey'); } @@ -299,6 +303,8 @@ public function testSetAdapterResponseFormatTypeWorksOnCustom() $live = $this->getLive(); $live->registerAdapterResponseFormatType('BarBazChewie'); $live->setAdapterResponseFormatType('BarBazChewie'); + // no assertions, not no exceptions either + $this->expectNotToPerformAssertions(); } public function testMakeQueryMethodExistsForCUT() { diff --git a/Cpanel/Tests/Cpanel/Service/Adapter/WHMapiTest.php b/Cpanel/Tests/Cpanel/Service/Adapter/WHMapiTest.php index bd9c3f3..801e0a2 100644 --- a/Cpanel/Tests/Cpanel/Service/Adapter/WHMapiTest.php +++ b/Cpanel/Tests/Cpanel/Service/Adapter/WHMapiTest.php @@ -1,10 +1,13 @@ getMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); + $m = $this->_makeMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); return $m; } /** @@ -55,7 +58,7 @@ public function getRObj($mock = false, $methods = array(), $args = array(), $moc if (empty($methods)) { $methods = null; } - return $this->getMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); + return $this->_makeMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); } return new Cpanel_Query_Object(); } @@ -64,11 +67,6 @@ public function testConstantDRFT() $classname = $this->cut; $this->assertEquals($this->DRFT, $classname::DRFT); } - public function testPrivateValidRFT() - { - $a = new $this->cut(); - $this->assertAttributeEquals($this->_validRFT, '_validRFT', $a); - } public function testConstructArgs() { $rmeth = new ReflectionMethod($this->cut, '__construct'); @@ -129,23 +127,12 @@ public function rftData() public function testSetAdapterResponseFormatType($type, $expectE) { if ($expectE) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $a = $this->getA(null, array(), '', false); $a->setAdapterResponseFormatType($type); - } - /** - * @depends testSetAdapterResponseFormatType - */ - public function testConstructWillSetVars() - { - list($h, $u, $p, $RFT) = $this->constructVars(); - $a = new $this->cut($h, $u, $p, $RFT); - $this->assertAttributeEquals($h, 'host', $a); - $this->assertAttributeEquals($p, 'auth', $a); - $this->assertAttributeEquals('pass', 'auth_type', $a); - $this->assertAttributeEquals($u, 'user', $a); - $this->assertAttributeEquals($RFT, '_adapterResponseFormatType', $a); + // no assertions, not no exceptions either + $this->expectNotToPerformAssertions(); } public function testConstructSanitizesRFT() { @@ -155,14 +142,6 @@ public function testConstructSanitizesRFT() $a->expects($this->once())->method('setAdapterResponseFormatType'); $a->__construct(); } - /** - * @depends testConstantDRFT - */ - public function testConstructWillSeRFTByDefault() - { - $a = new $this->cut(); - $this->assertAttributeEquals($this->DRFT, '_adapterResponseFormatType', $a); - } public function testGetAdapterResponseFormatTypeFetchesStored() { list($h, $u, $p, $RFT) = $this->constructVars(); @@ -285,7 +264,6 @@ public function apiQueryData2() ); } /** - * @depends testConstructWillSetVars * @dataProvider apiQueryData * @paramsunknown_type $user * @paramsunknown_type $mod @@ -296,7 +274,7 @@ public function apiQueryData2() public function testLegacyApi1UnderscoreQueryRequiresInput($user = '', $mod = '', $func = '', $args = '', $expectE = 0) { if ($expectE) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $a = $this->getA(array( 'makeQuery' @@ -304,9 +282,10 @@ public function testLegacyApi1UnderscoreQueryRequiresInput($user = '', $mod = '' $rObj = $this->getRObj(); $a->setResponseObject($rObj); $a->api1_query($user, $mod, $func, $args); + // no assertions, not no exceptions either + $this->expectNotToPerformAssertions(); } /** - * @depends testConstructWillSetVars * @dataProvider apiQueryData * @paramsunknown_type $user * @paramsunknown_type $mod @@ -317,7 +296,7 @@ public function testLegacyApi1UnderscoreQueryRequiresInput($user = '', $mod = '' public function testLegacyApi2UnderscoreQueryRequiresInput($user = '', $mod = '', $func = '', $args = '', $expectE = 0) { if ($expectE) { - $this->setExpectedException('Exception'); + $this->expectException('Exception'); } $a = $this->getA(array( 'makeQuery' @@ -325,6 +304,8 @@ public function testLegacyApi2UnderscoreQueryRequiresInput($user = '', $mod = '' $rObj = $this->getRObj(); $a->setResponseObject($rObj); $a->api2_query($user, $mod, $func, $args); + // no assertions, not no exceptions either + $this->expectNotToPerformAssertions(); } /** * @depends testLegacyApi2UnderscoreQueryRequiresInput diff --git a/Cpanel/Tests/Cpanel/Service/WHMTest.php b/Cpanel/Tests/Cpanel/Service/WHMTest.php index 275ec6c..58267fb 100644 --- a/Cpanel/Tests/Cpanel/Service/WHMTest.php +++ b/Cpanel/Tests/Cpanel/Service/WHMTest.php @@ -1,10 +1,13 @@ getMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); + $m = $this->_makeMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); return $m; } public function getOptsArray() @@ -229,7 +232,7 @@ public function testDirectURLQuerySetsOutputFormatForRObj($uri, $RFT, $formdata, { $opts = $this->getOptsArray(); $whm = new $this->cut($opts); - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_WHMapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_WHMapi', array( 'makeQuery' )); $mockAdapter->expects($this->once())->method('makeQuery'); @@ -249,7 +252,7 @@ public function testDirectURLQuerySetsQueryOptionsForRObj($uri, $RFT, $formdata, { $opts = $this->getOptsArray(); $whm = new $this->cut($opts); - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_WHMapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_WHMapi', array( 'makeQuery' )); $mockAdapter->expects($this->once())->method('makeQuery'); @@ -276,7 +279,7 @@ public function testDirectURLQueryPassesURLToAdapterMakeQuery($uri, $RFT, $formd { $opts = $this->getOptsArray(); $whm = new $this->cut($opts); - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_WHMapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_WHMapi', array( 'makeQuery' )); $mockAdapter->expects($this->once())->method('makeQuery')->will($this->returnArgument(0)); @@ -295,7 +298,7 @@ public function testDirectURLQueryPassesFormdataToAdapterMakeQuery($uri, $RFT, $ { $opts = $this->getOptsArray(); $whm = new $this->cut($opts); - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_WHMapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_WHMapi', array( 'makeQuery' )); $mockAdapter->expects($this->once())->method('makeQuery')->will($this->returnArgument(1)); @@ -315,7 +318,7 @@ public function testMagicCallMethodOnAdapterWithArg0() 'blah' => 'baz' ); $expected0 = 'functionName'; - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_WHMapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_WHMapi', array( 'xmlapi_query' )); $mockAdapter->expects($this->once())->method('xmlapi_query')->will($this->returnArgument(0)); @@ -335,7 +338,7 @@ public function testMagicCallMethodOnAdapterWithArg1() 'blah' => 'baz' ); $expected0 = 'functionName'; - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_WHMapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_WHMapi', array( 'xmlapi_query' )); $mockAdapter->expects($this->once())->method('xmlapi_query')->will($this->returnArgument(1)); diff --git a/Cpanel/Tests/Cpanel/Service/cPanelTest.php b/Cpanel/Tests/Cpanel/Service/cPanelTest.php index 9b84ce0..d3737e9 100644 --- a/Cpanel/Tests/Cpanel/Service/cPanelTest.php +++ b/Cpanel/Tests/Cpanel/Service/cPanelTest.php @@ -1,10 +1,13 @@ getMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); + $m = $this->_makeMock($this->cut, $methods, $args, $mockName, $callConst, $callClone, $callA); return $m; } /** @@ -48,7 +51,7 @@ public function getRObj($mock = false, $methods = array(), $args = array(), $moc if (empty($methods)) { $methods = null; } - return $this->getMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); + return $this->_makeMock($this->qa, $methods, $args, $mockName, $callConst, $callClone, $callA); } return new Cpanel_Query_Object(); } @@ -289,7 +292,7 @@ public function testDirectURLQuerySetsOutputFormatForRObj($uri, $RFT, $formdata, { $opts = $this->getOptsArray(); $cp = new $this->cut($opts); - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_Cpanelapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_Cpanelapi', array( 'makeQuery' )); $mockAdapter->expects($this->once())->method('makeQuery'); @@ -309,7 +312,7 @@ public function testDirectURLQuerySetsQueryOptionsForRObj($uri, $RFT, $formdata, { $opts = $this->getOptsArray(); $cp = new $this->cut($opts); - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_Cpanelapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_Cpanelapi', array( 'makeQuery' )); $mockAdapter->expects($this->once())->method('makeQuery'); @@ -336,7 +339,7 @@ public function testDirectURLQueryPassesURLToAdapterMakeQuery($uri, $RFT, $formd { $opts = $this->getOptsArray(); $cp = new $this->cut($opts); - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_Cpanelapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_Cpanelapi', array( 'makeQuery' )); $mockAdapter->expects($this->once())->method('makeQuery')->will($this->returnArgument(0)); @@ -355,7 +358,7 @@ public function testDirectURLQueryPassesFormdataToAdapterMakeQuery($uri, $RFT, $ { $opts = $this->getOptsArray(); $cp = new $this->cut($opts); - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_Cpanelapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_Cpanelapi', array( 'makeQuery' )); $mockAdapter->expects($this->once())->method('makeQuery')->will($this->returnArgument(1)); @@ -375,7 +378,7 @@ public function testMagicCallMethodOnAdapterWithArg0() 'blah' => 'baz' ); $expected0 = 'functionName'; - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_Cpanelapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_Cpanelapi', array( 'xmlapi_query' )); $mockAdapter->expects($this->once())->method('xmlapi_query')->will($this->returnArgument(0)); @@ -395,7 +398,7 @@ public function testMagicCallMethodOnAdapterWithArg1() 'blah' => 'baz' ); $expected0 = 'functionName'; - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_Cpanelapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_Cpanelapi', array( 'xmlapi_query' )); $mockAdapter->expects($this->once())->method('xmlapi_query')->will($this->returnArgument(1)); @@ -419,7 +422,7 @@ public function testApi1RequestEnforcesCheckParams() 'two', 'three' ); - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_Cpanelapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_Cpanelapi', array( 'api1_query' )); $mockAdapter->expects($this->any())->method('api1_query'); @@ -448,7 +451,7 @@ public function testApi1RequestInitializesAdapter() 'two', 'three' ); - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_Cpanelapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_Cpanelapi', array( 'api1_query' )); $mockAdapter->expects($this->any())->method('api1_query'); @@ -485,7 +488,7 @@ public function testApi1RequestCallsRemoteAdapterApi1Query() ); $userInfo = posix_getpwuid(posix_geteuid()); $account = (array_key_exists('user', $opts)) ? $opts['user'] : $userInfo['name']; - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_Cpanelapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_Cpanelapi', array( 'api1_query' )); $mockAdapter->expects($this->once())->method('api1_query')->with($account, $mf['module'], $mf['function'], $args); @@ -516,7 +519,7 @@ public function testApi1RequestWillNotInitializeLocalAdapter() ); $this->setLocalEnviro(); $adapterName = 'Cpanel_Service_Adapter_Liveapi'; - $mockAdapter = $this->getMock($adapterName, array( + $mockAdapter = $this->_makeMock($adapterName, array( 'openCpanelHandle', 'makeQuery' )); @@ -552,7 +555,7 @@ public function testApi1RequestCallsLocalAdapterMakeQuery() ); $this->setLocalEnviro(); $adapterName = 'Cpanel_Service_Adapter_Liveapi'; - $mockAdapter = $this->getMock($adapterName, array( + $mockAdapter = $this->_makeMock($adapterName, array( 'openCpanelHandle', 'makeQuery' )); @@ -586,7 +589,7 @@ public function testApi2RequestEnforcesCheckParams() 'two' => 'two', 'three' => 'three' ); - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_Cpanelapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_Cpanelapi', array( 'api2_query' )); $mockAdapter->expects($this->any())->method('api2_query'); @@ -615,7 +618,7 @@ public function testAp21RequestInitializesAdapter() 'two' => 'two', 'three' => 'three' ); - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_Cpanelapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_Cpanelapi', array( 'api2_query' )); $mockAdapter->expects($this->any())->method('api2_query'); @@ -652,7 +655,7 @@ public function testApi2RequestCallsRemoteAdapterApi2Query() ); $userInfo = posix_getpwuid(posix_geteuid()); $account = (array_key_exists('user', $opts)) ? $opts['user'] : $userInfo['name']; - $mockAdapter = $this->getMock('Cpanel_Service_Adapter_Cpanelapi', array( + $mockAdapter = $this->_makeMock('Cpanel_Service_Adapter_Cpanelapi', array( 'api2_query' )); $mockAdapter->expects($this->once())->method('api2_query')->with($account, $mf['module'], $mf['function'], $args); @@ -683,7 +686,7 @@ public function testApi2RequestWillNotInitializeLocalAdapter() ); $this->setLocalEnviro(); $adapterName = 'Cpanel_Service_Adapter_Liveapi'; - $mockAdapter = $this->getMock($adapterName, array( + $mockAdapter = $this->_makeMock($adapterName, array( 'openCpanelHandle', 'makeQuery' )); @@ -719,7 +722,7 @@ public function testApi2RequestCallsLocalAdapterMakeQuery() ); $this->setLocalEnviro(); $adapterName = 'Cpanel_Service_Adapter_Liveapi'; - $mockAdapter = $this->getMock($adapterName, array( + $mockAdapter = $this->_makeMock($adapterName, array( 'openCpanelHandle', 'makeQuery' )); diff --git a/Cpanel/Tests/TestHelper.php b/Cpanel/Tests/TestHelper.php index a9b9966..5dbe626 100644 --- a/Cpanel/Tests/TestHelper.php +++ b/Cpanel/Tests/TestHelper.php @@ -6,7 +6,7 @@ * * Added Cpanel directory to include path and loads the Cpanel Autoloader * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -17,7 +17,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -35,9 +35,9 @@ * @category Cpanel * @package Cpanel_Test * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/Cpanel/Util/Autoload.php b/Cpanel/Util/Autoload.php index 0667490..ecfb919 100644 --- a/Cpanel/Util/Autoload.php +++ b/Cpanel/Util/Autoload.php @@ -2,7 +2,7 @@ /** * Cpanel * - * Copyright (c) 2011, cPanel, Inc. + * Copyright (c) 2011, cPanel, L.L.C. * All rights reserved. * http://cpanel.net * @@ -13,7 +13,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of cPanel, Inc. nor the + * * Neither the name of cPanel, L.L.C. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -31,9 +31,9 @@ * @category Cpanel * @package Cpanel_Util * @author David Neimeyer - * @copyright Copyright (c) 2011, cPanel, Inc., All rights Reserved. (http://cpanel.net) + * @copyright Copyright (c) 2011, cPanel, L.L.C., All rights Reserved. (http://cpanel.net) * @license http://sdk.cpanel.net/license/bsd.html BSD License - * @version 0.1.0 + * @version 0.2.0 * @link http://sdk.cpanel.net * @since 0.1.0 */ diff --git a/README.markdown b/README.markdown index 1f765c9..25e2b2f 100644 --- a/README.markdown +++ b/README.markdown @@ -55,7 +55,7 @@ Code: The cPanel PHP library is a foundation for developers to build applications and scripts that interact with cPanel systems. -_Version 0.1.0 is compatible with PHP >= 5.2_ +_Version 0.2.0 is compatible with PHP >= 7.3_ The library is divided into components. The follow list itemizes a few of the components, and their description, that are in the library: @@ -97,7 +97,7 @@ Examples of how to code with the PublicAPI client class can be found: document * In detail: The examples directory, _Cpanel/Examples/_ within the repository -_Version 0.1.0 is compatible with PHP >= 5.2_ +_Version 0.2.0 is compatible with PHP >= 7.3_ ## Examples Directory @@ -119,11 +119,16 @@ rely on it. Unit tests for the cPanel PHP library and the PublicAPI client class are included in the _Cpanel/Tests/_ directory. They are written for use with -[PHPUnit][PHPUnit_mainpage] >= 3.5 These test will require PHP 5.3 or +[PHPUnit][PHPUnit_mainpage] >= 8 These test will require PHP 7.3 or greater, as they use specific Reflection functions that allow for assertions to be made on properties and methods whose visibility is _private_ or _protected_. +Using Composer, you can run the unit tests with the following incantation: + +Code: + ~/vendor/bin/phpunit --bootstrap ~/vendor/autoload.php --bootstrap phpunit.bootstrap.php Cpanel/Tests + [XML-API_github]: http://github.com/CpanelInc/xmlapi-php "XML-API client class on GitHub" [xmlapi_version]: http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/DisplaycPanelWHMVersion "XML-API 'version'" [PHPUnit_mainpage]: http://www.phpunit.de \ No newline at end of file diff --git a/phpunit.bootstrap.php b/phpunit.bootstrap.php new file mode 100644 index 0000000..8eeaf62 --- /dev/null +++ b/phpunit.bootstrap.php @@ -0,0 +1,37 @@ +getMockBuilder($className); + $mock->setMethods($methods); + $mock->setConstructorArgs($args); + $mock->setMockClassName($mockName); + if($callConst){ + $mock->enableOriginalConstructor(); + }else{ + $mock->disableOriginalConstructor(); + } + if($callClone){ + $mock->enableOriginalClone(); + }else{ + $mock->disableOriginalClone(); + } + if($callA){ + $mock->enableAutoload(); + }else{ + $mock->disableAutoload(); + } + return $mock->getMock(); + + } + +}