diff --git a/.gitignore b/.gitignore index 964595f2..2862a05b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,10 @@ logs # ignore test results phpunit-test-results + +*.log + +coverage.xml + +# ignore phpdoc +output/ diff --git a/.travis.yml b/.travis.yml index 74f49a5b..c0225320 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,14 +9,27 @@ php: # - nightly before_install: - nvm install 6.11 -install: + - sudo apt-get install graphviz +install: + # fix for jms/serializer 1.7.1 not being able to run on 5.4 + - if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.4" ]]; then composer require jms/serializer; fi - composer install - npm install before_script: - npm start 1>&2 - sleep 3 + - npm run lint script: - - ./vendor/bin/phpunit --coverage-clover=coverage.xml - + - npm run test:coverage + - npm run document-check && if [[ `cat "output/checkstyle.xml" | grep " + + PHPCS Ignore Rule + + + 0 + + + 0 + + + 0 + + \ No newline at end of file diff --git a/src/Parse/HttpClients/ParseCurl.php b/src/Parse/HttpClients/ParseCurl.php index 4c62cd7e..3b850f37 100644 --- a/src/Parse/HttpClients/ParseCurl.php +++ b/src/Parse/HttpClients/ParseCurl.php @@ -1,23 +1,23 @@ + * Class ParseCurl | Parse/HttpClients/ParseCurl.php */ namespace Parse\HttpClients; - use Parse\ParseException; /** - * Class ParseCurl + * Class ParseCurl - Wrapper for abstracted curl usage + * + * @author Ben Friedman * @package Parse\HttpClients */ class ParseCurl { /** * Curl handle + * * @var resource */ private $curl; @@ -27,11 +27,9 @@ class ParseCurl */ public function init() { - if($this->curl === null) { + if ($this->curl === null) { $this->curl = curl_init(); - } - } /** @@ -42,9 +40,8 @@ public function init() */ public function exec() { - if(!isset($this->curl)) { + if (!isset($this->curl)) { throw new ParseException('You must call ParseCurl::init first'); - } return curl_exec($this->curl); @@ -59,13 +56,11 @@ public function exec() */ public function setOption($option, $value) { - if(!isset($this->curl)) { + if (!isset($this->curl)) { throw new ParseException('You must call ParseCurl::init first'); - } curl_setopt($this->curl, $option, $value); - } /** @@ -76,13 +71,11 @@ public function setOption($option, $value) */ public function setOptionsArray($options) { - if(!isset($this->curl)) { + if (!isset($this->curl)) { throw new ParseException('You must call ParseCurl::init first'); - } curl_setopt_array($this->curl, $options); - } /** @@ -94,13 +87,11 @@ public function setOptionsArray($options) */ public function getInfo($info) { - if(!isset($this->curl)) { + if (!isset($this->curl)) { throw new ParseException('You must call ParseCurl::init first'); - } return curl_getinfo($this->curl, $info); - } /** @@ -111,13 +102,11 @@ public function getInfo($info) */ public function getError() { - if(!isset($this->curl)) { + if (!isset($this->curl)) { throw new ParseException('You must call ParseCurl::init first'); - } return curl_error($this->curl); - } /** @@ -128,13 +117,11 @@ public function getError() */ public function getErrorCode() { - if(!isset($this->curl)) { + if (!isset($this->curl)) { throw new ParseException('You must call ParseCurl::init first'); - } return curl_errno($this->curl); - } /** @@ -142,9 +129,8 @@ public function getErrorCode() */ public function close() { - if(!isset($this->curl)) { + if (!isset($this->curl)) { throw new ParseException('You must call ParseCurl::init first'); - } // close our handle @@ -152,7 +138,5 @@ public function close() // unset our curl handle $this->curl = null; - } - -} \ No newline at end of file +} diff --git a/src/Parse/HttpClients/ParseCurlHttpClient.php b/src/Parse/HttpClients/ParseCurlHttpClient.php index 035350b4..93f1be7a 100644 --- a/src/Parse/HttpClients/ParseCurlHttpClient.php +++ b/src/Parse/HttpClients/ParseCurlHttpClient.php @@ -1,59 +1,65 @@ + * Class ParseCurlHttpClient | Parse/HttpClients/ParseCurlHttpClient.php */ namespace Parse\HttpClients; - use Parse\ParseException; /** - * Class ParseCurlHttpClient + * Class ParseCurlHttpClient - Curl http client + * + * @author Ben Friedman * @package Parse\HttpClients */ class ParseCurlHttpClient implements ParseHttpable { /** * Curl handle + * * @var ParseCurl */ private $parseCurl; /** * Request Headers + * * @var array */ private $headers = array(); /** * Response headers + * * @var array */ private $responseHeaders = array(); /** * Response code + * * @var int */ private $responseCode = 0; /** * Content type of our response + * * @var string|null */ private $responseContentType; /** * cURL error code + * * @var int */ private $curlErrorCode; /** * cURL error message + * * @var string */ private $curlErrorMessage; @@ -70,16 +76,18 @@ class ParseCurlHttpClient implements ParseHttpable /** * Response from our request + * * @var string */ private $response; - + /** + * ParseCurlHttpClient constructor. + */ public function __construct() { - if(!isset($this->parseCurl)) { + if (!isset($this->parseCurl)) { $this->parseCurl = new ParseCurl(); - } } @@ -92,7 +100,6 @@ public function __construct() public function addRequestHeader($key, $value) { $this->headers[$key] = $value; - } /** @@ -104,13 +111,11 @@ private function buildRequestHeaders() { // coalesce our header key/value pairs $headers = []; - foreach($this->headers as $key => $value) { + foreach ($this->headers as $key => $value) { $headers[] = $key.': '.$value; - } return $headers; - } /** @@ -121,7 +126,6 @@ private function buildRequestHeaders() public function getResponseHeaders() { return $this->responseHeaders; - } /** @@ -132,7 +136,6 @@ public function getResponseHeaders() public function getResponseStatusCode() { return $this->responseCode; - } /** @@ -143,7 +146,6 @@ public function getResponseStatusCode() public function getResponseContentType() { return $this->responseContentType; - } /** @@ -161,7 +163,6 @@ public function setup() CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, )); - } /** @@ -176,34 +177,29 @@ public function setup() public function send($url, $method = 'GET', $data = array()) { - if($method == "GET" && !empty($data)) { + if ($method == "GET" && !empty($data)) { // handle get $url .= '?'.http_build_query($data, null, '&'); - - } else if($method == "POST") { + } elseif ($method == "POST") { // handle post $this->parseCurl->setOptionsArray(array( CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $data )); - - } else if($method == "PUT") { + } elseif ($method == "PUT") { // handle put $this->parseCurl->setOptionsArray(array( CURLOPT_CUSTOMREQUEST => $method, CURLOPT_POSTFIELDS => $data )); - - } else if($method == "DELETE") { + } elseif ($method == "DELETE") { // handle delete $this->parseCurl->setOption(CURLOPT_CUSTOMREQUEST, $method); - } - if(count($this->headers) > 0) { + if (count($this->headers) > 0) { // set our custom request headers $this->parseCurl->setOption(CURLOPT_HTTPHEADER, $this->buildRequestHeaders()); - } // set url @@ -239,7 +235,6 @@ public function send($url, $method = 'GET', $data = array()) $this->headers = array(); return $response; - } /** @@ -264,23 +259,19 @@ private function getHeadersArray($headerContent) // sepearate our header components $headerComponents = explode("\n", $rawHeaders); - foreach($headerComponents as $component) { + foreach ($headerComponents as $component) { if (strpos($component, ': ') === false) { // set our http_code $headers['http_code'] = $component; - - } else { // set this header key/value pair list($key, $value) = explode(': ', $component); $headers[$key] = $value; - } } // return our completed headers return $headers; - } @@ -292,7 +283,6 @@ private function getHeadersArray($headerContent) public function setConnectionTimeout($timeout) { $this->parseCurl->setOption(CURLOPT_CONNECTTIMEOUT, $timeout); - } /** @@ -303,7 +293,6 @@ public function setConnectionTimeout($timeout) public function setTimeout($timeout) { $this->parseCurl->setOption(CURLOPT_TIMEOUT, $timeout); - } /** @@ -315,7 +304,6 @@ public function setCAFile($caFile) { // name of a file holding one or more certificates to verify the peer with $this->parseCurl->setOption(CURLOPT_CAINFO, $caFile); - } /** @@ -326,7 +314,6 @@ public function setCAFile($caFile) public function getErrorCode() { return $this->curlErrorCode; - } /** @@ -337,7 +324,6 @@ public function getErrorCode() public function getErrorMessage() { return $this->curlErrorMessage; - } /** @@ -351,19 +337,15 @@ private function getHeaderSize() // This corrects a Curl bug where header size does not account // for additional Proxy headers. - if ( $this->needsCurlProxyFix() ) { - + if ($this->needsCurlProxyFix()) { // Additional way to calculate the request body size. if (preg_match('/Content-Length: (\d+)/', $this->response, $match)) { $headerSize = mb_strlen($this->response) - $match[1]; - } elseif (stripos($this->response, self::CONNECTION_ESTABLISHED) !== false) { $headerSize += mb_strlen(self::CONNECTION_ESTABLISHED); - } } return $headerSize; - } /** @@ -378,7 +360,5 @@ private function needsCurlProxyFix() $version = $versionDat['version_number']; return $version < self::CURL_PROXY_QUIRK_VER; - } - } diff --git a/src/Parse/HttpClients/ParseHttpable.php b/src/Parse/HttpClients/ParseHttpable.php index 760369df..79c6404f 100644 --- a/src/Parse/HttpClients/ParseHttpable.php +++ b/src/Parse/HttpClients/ParseHttpable.php @@ -1,13 +1,16 @@ + * Class ParseHttpable | Parse/HttpClients/ParseHttpable.php */ namespace Parse\HttpClients; - +/** + * Class ParseHttpable - Interface for an HTTPable client + * + * @author Ben Friedman + * @package Parse\HttpClients + */ interface ParseHttpable { /** @@ -88,5 +91,4 @@ public function setup(); * @return string */ public function send($url, $method = 'GET', $data = array()); - -} \ No newline at end of file +} diff --git a/src/Parse/HttpClients/ParseStream.php b/src/Parse/HttpClients/ParseStream.php index 86d0ad28..1d4faa0f 100644 --- a/src/Parse/HttpClients/ParseStream.php +++ b/src/Parse/HttpClients/ParseStream.php @@ -1,19 +1,20 @@ + * Class ParseStream | Parse/HttpClients/ParseStream.php */ namespace Parse\HttpClients; /** - * Class ParseStream + * Class ParseStream - Wrapper for abstracted stream usage + * + * @author Ben Friedman * @package Parse\HttpClients */ class ParseStream { /** + * Stream context * * @var resource */ @@ -21,18 +22,21 @@ class ParseStream /** * Response headers + * * @var array|null */ private $responseHeaders; /** * Error message + * * @var string */ private $errorMessage; /** * Error code + * * @var int */ private $errorCode; @@ -45,7 +49,6 @@ class ParseStream public function createContext($options) { $this->stream = stream_context_create($options); - } /** @@ -59,20 +62,17 @@ public function get($url) try { // get our response $response = file_get_contents($url, false, $this->stream); - - } catch(\Exception $e) { + } catch (\Exception $e) { // set our error message/code and return false $this->errorMessage = $e->getMessage(); $this->errorCode = $e->getCode(); return false; - } // set response headers $this->responseHeaders = $http_response_header; return $response; - } /** @@ -83,7 +83,6 @@ public function get($url) public function getResponseHeaders() { return $this->responseHeaders; - } /** @@ -94,7 +93,6 @@ public function getResponseHeaders() public function getErrorMessage() { return $this->errorMessage; - } /** @@ -105,7 +103,5 @@ public function getErrorMessage() public function getErrorCode() { return $this->errorCode; - } - -} \ No newline at end of file +} diff --git a/src/Parse/HttpClients/ParseStreamHttpClient.php b/src/Parse/HttpClients/ParseStreamHttpClient.php index 60d61617..8ac30fdf 100644 --- a/src/Parse/HttpClients/ParseStreamHttpClient.php +++ b/src/Parse/HttpClients/ParseStreamHttpClient.php @@ -1,82 +1,97 @@ + * Class ParseStreamHttpClient | Parse/HttpClients/ParseStreamHttpClient.php */ namespace Parse\HttpClients; - use Parse\ParseException; +/** + * Class ParseStreamHttpClient - Stream http client + * + * @author Ben Friedman + * @package Parse\HttpClients + */ class ParseStreamHttpClient implements ParseHttpable { /** * Stream handle + * * @var ParseStream */ private $parseStream; /** * Request Headers + * * @var array */ private $headers = array(); /** * Response headers + * * @var array */ private $responseHeaders = array(); /** * Response code + * * @var int */ private $responseCode = 0; /** * Content type of our response + * * @var string|null */ private $responseContentType; /** * Stream error code + * * @var int */ private $streamErrorCode; /** * Stream error message + * * @var string */ private $streamErrorMessage; /** * Options to pass to our stream + * * @var array */ private $options = array(); /** * Optional CA file to verify our peers with + * * @var string */ private $caFile; /** * Response from our request + * * @var string */ private $response; + /** + * ParseStreamHttpClient constructor. + */ public function __construct() { - if(!isset($this->parseStream)) { + if (!isset($this->parseStream)) { $this->parseStream = new ParseStream(); - } } @@ -91,7 +106,6 @@ public function __construct() public function addRequestHeader($key, $value) { $this->headers[$key] = $value; - } /** @@ -102,7 +116,6 @@ public function addRequestHeader($key, $value) public function getResponseHeaders() { return $this->responseHeaders; - } /** @@ -113,7 +126,6 @@ public function getResponseHeaders() public function getResponseStatusCode() { return $this->responseCode; - } /** @@ -124,7 +136,6 @@ public function getResponseStatusCode() public function getResponseContentType() { return $this->responseContentType; - } /** @@ -136,22 +147,22 @@ private function buildRequestHeaders() { // coalesce our header key/value pairs $headers = []; - foreach($this->headers as $key => $value) { - if($key == 'Expect' && $value == '') { + foreach ($this->headers as $key => $value) { + if ($key == 'Expect' && $value == '') { // drop this pair continue; - } // add this header key/value pair $headers[] = $key.': '.$value; - } return implode("\r\n", $headers); - } + /** + * Sets up ssl related options for the stream context + */ public function setup() { // setup ssl options @@ -161,22 +172,28 @@ public function setup() 'allow_self_signed' => true, // All root certificates are self-signed 'follow_location' => 1 ); - } + /** + * Sends an HTTP request + * + * @param string $url Url to send this request to + * @param string $method Method to send this request via + * @param array $data Data to send in this request + * @return string + * @throws ParseException + */ public function send($url, $method = 'GET', $data = array()) { // verify this url - if(preg_match('/\s/', trim($url))) { + if (preg_match('/\s/', trim($url))) { throw new ParseException('Url may not contain spaces for stream client: '.$url); - } - if(isset($this->caFile)) { + if (isset($this->caFile)) { // set CA file as well $this->options['ssl']['cafile'] = $this->caFile; - } // add additional options for this request @@ -185,28 +202,23 @@ public function send($url, $method = 'GET', $data = array()) 'ignore_errors' => true ); - if(isset($this->timeout)) { + if (isset($this->timeout)) { $this->options['http']['timeout'] = $this->timeout; - } - if(isset($data) && $data != "{}") { + if (isset($data) && $data != "{}") { if ($method == "GET") { // handle GET $query = http_build_query($data, null, '&'); $this->options['http']['content'] = $query; $this->addRequestHeader('Content-type', 'application/x-www-form-urlencoded'); - - } else if ($method == "POST") { + } elseif ($method == "POST") { // handle POST $this->options['http']['content'] = $data; - - } else if ($method == "PUT") { + } elseif ($method == "PUT") { // handle PUT $this->options['http']['content'] = $data; - } - } // set headers @@ -225,21 +237,17 @@ public function send($url, $method = 'GET', $data = array()) // set an error and code $this->streamErrorMessage = $this->parseStream->getErrorMessage(); $this->streamErrorCode = $this->parseStream->getErrorCode(); - } else { - // set our response headers $this->responseHeaders = self::formatHeaders($rawHeaders); // get and set content type, if present - if(isset($this->responseHeaders['Content-Type'])) { + if (isset($this->responseHeaders['Content-Type'])) { $this->responseContentType = $this->responseHeaders['Content-Type']; - } // set our http status code $this->responseCode = self::getStatusCodeFromHeader($this->responseHeaders['http_code']); - } // clear options @@ -249,7 +257,6 @@ public function send($url, $method = 'GET', $data = array()) $this->headers = array(); return $response; - } /** @@ -267,17 +274,14 @@ public static function formatHeaders(array $rawHeaders) if (strpos($line, ':') === false) { // set our http status code $headers['http_code'] = $line; - } else { // set this header entry list ($key, $value) = explode(': ', $line); $headers[$key] = $value; - } } return $headers; - } /** * Extracts the Http status code from the given header @@ -290,7 +294,6 @@ public static function getStatusCodeFromHeader($header) { preg_match('{HTTP/\d\.\d\s+(\d+)\s+.*}', $header, $match); return (int) $match[1]; - } /** @@ -301,7 +304,6 @@ public static function getStatusCodeFromHeader($header) public function getErrorCode() { return $this->streamErrorCode; - } /** @@ -312,9 +314,13 @@ public function getErrorCode() public function getErrorMessage() { return $this->streamErrorMessage; - } + /** + * Sets a connection timeout. UNUSED in the stream client. + * + * @param int $timeout Timeout to set + */ public function setConnectionTimeout($timeout) { // do nothing @@ -328,7 +334,6 @@ public function setConnectionTimeout($timeout) public function setCAFile($caFile) { $this->caFile = $caFile; - } /** @@ -339,8 +344,5 @@ public function setCAFile($caFile) public function setTimeout($timeout) { $this->timeout = $timeout; - } - - -} \ No newline at end of file +} diff --git a/src/Parse/Internal/AddOperation.php b/src/Parse/Internal/AddOperation.php index 1be9c7bb..43787ca8 100755 --- a/src/Parse/Internal/AddOperation.php +++ b/src/Parse/Internal/AddOperation.php @@ -1,4 +1,7 @@ + * @package Parse\Internal */ class AddOperation implements FieldOperation { diff --git a/src/Parse/Internal/AddUniqueOperation.php b/src/Parse/Internal/AddUniqueOperation.php index 64b1fef7..4311f6e1 100755 --- a/src/Parse/Internal/AddUniqueOperation.php +++ b/src/Parse/Internal/AddUniqueOperation.php @@ -1,4 +1,7 @@ + * @package Parse\Internal */ class AddUniqueOperation implements FieldOperation { @@ -126,6 +130,13 @@ public function _apply($oldValue, $obj, $key) return $oldValue; } + /** + * Checks if a parse object is contained in a given array of values + * + * @param ParseObject $parseObject ParseObject to check for existence of + * @param array $oldValue Array to check if ParseObject is present in + * @return bool + */ private function isParseObjectInArray($parseObject, $oldValue) { foreach ($oldValue as $object) { diff --git a/src/Parse/Internal/DeleteOperation.php b/src/Parse/Internal/DeleteOperation.php index 4bf14e97..670ac0b9 100755 --- a/src/Parse/Internal/DeleteOperation.php +++ b/src/Parse/Internal/DeleteOperation.php @@ -1,4 +1,7 @@ + * @package Parse\Internal */ class DeleteOperation implements FieldOperation { diff --git a/src/Parse/Internal/Encodable.php b/src/Parse/Internal/Encodable.php index 5264aa97..c3ccc0f5 100644 --- a/src/Parse/Internal/Encodable.php +++ b/src/Parse/Internal/Encodable.php @@ -1,4 +1,7 @@ + * @package Parse\Internal */ interface Encodable { diff --git a/src/Parse/Internal/FieldOperation.php b/src/Parse/Internal/FieldOperation.php index e70b542d..9b396b46 100755 --- a/src/Parse/Internal/FieldOperation.php +++ b/src/Parse/Internal/FieldOperation.php @@ -1,4 +1,7 @@ + * @package Parse\Internal */ interface FieldOperation extends Encodable { diff --git a/src/Parse/Internal/IncrementOperation.php b/src/Parse/Internal/IncrementOperation.php index c9f553d4..ab03d781 100755 --- a/src/Parse/Internal/IncrementOperation.php +++ b/src/Parse/Internal/IncrementOperation.php @@ -1,4 +1,7 @@ + * @package Parse\Internal */ class IncrementOperation implements FieldOperation { diff --git a/src/Parse/Internal/ParseRelationOperation.php b/src/Parse/Internal/ParseRelationOperation.php index 0ee52405..3d8e434c 100644 --- a/src/Parse/Internal/ParseRelationOperation.php +++ b/src/Parse/Internal/ParseRelationOperation.php @@ -1,4 +1,7 @@ + * @package Parse\Internal */ class ParseRelationOperation implements FieldOperation { @@ -35,6 +39,13 @@ class ParseRelationOperation implements FieldOperation */ private $relationsToRemove = []; + /** + * ParseRelationOperation constructor. + * + * @param ParseObject[] $objectsToAdd ParseObjects to add + * @param ParseObject[] $objectsToRemove ParseObjects to remove + * @throws Exception + */ public function __construct($objectsToAdd, $objectsToRemove) { $this->targetClassName = null; @@ -63,9 +74,8 @@ public function __construct($objectsToAdd, $objectsToRemove) */ private function checkAndAssignClassName($objects) { - if(!is_array($objects)) { + if (!is_array($objects)) { $objects = [$objects]; - } foreach ($objects as $object) { @@ -259,6 +269,11 @@ public function _encode() return empty($addRelation['objects']) ? $removeRelation : $addRelation; } + /** + * Gets the className of the target objects. + * + * @return null|string + */ public function _getTargetClass() { return $this->targetClassName; diff --git a/src/Parse/Internal/RemoveOperation.php b/src/Parse/Internal/RemoveOperation.php index 7728c754..bee46f58 100644 --- a/src/Parse/Internal/RemoveOperation.php +++ b/src/Parse/Internal/RemoveOperation.php @@ -1,4 +1,7 @@ + * @package Parse\Internal */ class RemoveOperation implements FieldOperation { @@ -106,9 +110,8 @@ public function _apply($oldValue, $obj, $key) return []; } - if(!is_array($oldValue)) { + if (!is_array($oldValue)) { $oldValue = [$oldValue]; - } $newValue = []; diff --git a/src/Parse/Internal/SetOperation.php b/src/Parse/Internal/SetOperation.php index 994242b3..27caae48 100755 --- a/src/Parse/Internal/SetOperation.php +++ b/src/Parse/Internal/SetOperation.php @@ -1,4 +1,7 @@ + * @package Parse\Internal */ class SetOperation implements FieldOperation { diff --git a/src/Parse/ParseACL.php b/src/Parse/ParseACL.php index 48d7a276..500bbb91 100644 --- a/src/Parse/ParseACL.php +++ b/src/Parse/ParseACL.php @@ -1,4 +1,7 @@ + * @package Parse */ class ParseACL implements Encodable { const PUBLIC_KEY = '*'; /** + * Array of permissions by id + * * @var array */ private $permissionsById = []; /** + * Whether this ACL is shared + * * @var bool */ private $shared = false; /** + * The last known current user + * * @var ParseUser */ private static $lastCurrentUser = null; /** + * An ACL with defaults set with the current user + * * @var ParseACL */ private static $defaultACLWithCurrentUser = null; /** + * An ACL with defaults set + * * @var ParseACL */ private static $defaultACL = null; /** + * Whether the default acl uses the current user or not + * * @var bool */ private static $defaultACLUsesCurrentUser = false; @@ -119,6 +135,11 @@ public function _setShared($shared) $this->shared = $shared; } + /** + * Returns an associate array encoding of this ParseACL instance. + * + * @return mixed + */ public function _encode() { if (empty($this->permissionsById)) { diff --git a/src/Parse/ParseAggregateException.php b/src/Parse/ParseAggregateException.php index 543468a0..3b3e235a 100644 --- a/src/Parse/ParseAggregateException.php +++ b/src/Parse/ParseAggregateException.php @@ -1,14 +1,23 @@ + * @package Parse */ class ParseAggregateException extends ParseException { + /** + * Collection of error values + * + * @var array + */ private $errors; /** diff --git a/src/Parse/ParseAnalytics.php b/src/Parse/ParseAnalytics.php index 7b9a43bb..72c19a1c 100644 --- a/src/Parse/ParseAnalytics.php +++ b/src/Parse/ParseAnalytics.php @@ -1,13 +1,17 @@ + * @package Parse */ class ParseAnalytics { @@ -62,6 +66,12 @@ public static function track($name, $dimensions = []) ); } + /** + * Encodes and returns the given data as a json object + * + * @param array $data Data to encode + * @return string + */ public static function _toSaveJSON($data) { return json_encode( diff --git a/src/Parse/ParseApp.php b/src/Parse/ParseApp.php index 8117c10f..12ac6736 100644 --- a/src/Parse/ParseApp.php +++ b/src/Parse/ParseApp.php @@ -1,20 +1,59 @@ + * @package Parse */ class ParseBytes implements Encodable { @@ -48,12 +52,22 @@ public static function createFromBase64Data($base64Data) return $bytes; } + /** + * Decodes and unpacks a given base64 encoded array of data + * + * @param $base64Data + */ private function setBase64Data($base64Data) { $byteArray = unpack('C*', base64_decode($base64Data)); $this->setByteArray($byteArray); } + /** + * Sets a new byte array + * + * @param array $byteArray Byte array to set + */ private function setByteArray(array $byteArray) { $this->byteArray = $byteArray; diff --git a/src/Parse/ParseClient.php b/src/Parse/ParseClient.php index 6fd38c1c..9c55a14f 100755 --- a/src/Parse/ParseClient.php +++ b/src/Parse/ParseClient.php @@ -1,4 +1,7 @@ + * @package Parse */ final class ParseClient { @@ -20,14 +24,14 @@ final class ParseClient * * @var string */ - private static $serverURL = 'https://api.parse.com/'; + private static $serverURL = null; /** * The mount path for the current parse server * * @var string */ - private static $mountPath = "1/"; + private static $mountPath = null; /** * The application id. @@ -107,11 +111,11 @@ final class ParseClient private static $caFile; /** - * Constant for version string to include with requests. + * Constant for version string to include with requests. Currently 1.2.9. * * @var string */ - const VERSION_STRING = 'php1.2.8'; + const VERSION_STRING = 'php1.2.9'; /** * Parse\Client::initialize, must be called before using Parse features. @@ -124,8 +128,13 @@ final class ParseClient * * @throws Exception */ - public static function initialize($app_id, $rest_key, $master_key, $enableCurlExceptions = true, $account_key = null) - { + public static function initialize( + $app_id, + $rest_key, + $master_key, + $enableCurlExceptions = true, + $account_key = null + ) { if (!ParseObject::hasRegisteredSubclass('_User')) { ParseUser::registerSubclass(); } @@ -138,7 +147,7 @@ public static function initialize($app_id, $rest_key, $master_key, $enableCurlEx ParseInstallation::registerSubclass(); } - if(!ParseObject::hasRegisteredSubclass('_PushStatus')) { + if (!ParseObject::hasRegisteredSubclass('_PushStatus')) { ParsePushStatus::registerSubclass(); } @@ -165,24 +174,43 @@ public static function initialize($app_id, $rest_key, $master_key, $enableCurlEx * @throws \Exception * */ - public static function setServerURL($serverURL, $mountPath) { + public static function setServerURL($serverURL, $mountPath) + { if (!$serverURL) { throw new Exception('Invalid Server URL.'); } - if( !$mountPath) { + if (!$mountPath) { throw new Exception('Invalid Mount Path.'); } - self::$serverURL = rtrim($serverURL,'/'); - self::$mountPath = trim($mountPath,'/') . '/'; + self::$serverURL = rtrim($serverURL, '/'); + self::$mountPath = trim($mountPath, '/') . '/'; // check if mount path is root - if(self::$mountPath == "/") { + if (self::$mountPath == "/") { // root path should have no mount path self::$mountPath = ""; } } + /** + * Clears the existing server url. + * Used primarily for testing purposes. + */ + public static function _clearServerURL() + { + self::$serverURL = null; + } + + /** + * Clears the existing mount path. + * Used primarily for testing purposes. + */ + public static function _clearMountPath() + { + self::$mountPath = null; + } + /** * Sets the Http client to use for requests * @@ -191,7 +219,6 @@ public static function setServerURL($serverURL, $mountPath) { public static function setHttpClient(ParseHttpable $httpClient) { self::$httpClient = $httpClient; - } /** @@ -204,13 +231,10 @@ public static function getHttpClient() if (static::$httpClient) { // use existing client return static::$httpClient; - } else { // default to cURL/stream return function_exists('curl_init') ? new ParseCurlHttpClient() : new ParseStreamHttpClient(); - } - } /** @@ -219,7 +243,6 @@ public static function getHttpClient() public static function clearHttpClient() { self::$httpClient = null; - } /** @@ -230,7 +253,6 @@ public static function clearHttpClient() public static function setCAFile($caFile) { self::$caFile = $caFile; - } /** @@ -323,6 +345,10 @@ public static function _decode($data) return new ParseGeoPoint($data['latitude'], $data['longitude']); } + if ($typeString === 'Polygon') { + return new ParsePolygon($data['coordinates']); + } + if ($typeString === 'Object') { $output = ParseObject::create($data['className']); $output->_mergeAfterFetch($data); @@ -399,18 +425,19 @@ public static function _request( // setup $httpClient->setup(); - if(isset(self::$caFile)) { + if (isset(self::$caFile)) { // set CA file $httpClient->setCAFile(self::$caFile); - } + // verify the server url and mount path have been set + self::assertServerInitialized(); + if ($appRequest) { // ** 'app' requests are not available in open source parse-server self::assertAppInitialized(); $httpClient->addRequestHeader('X-Parse-Account-Key', self::$accountKey); - } else { self::assertParseInitialized(); @@ -422,25 +449,20 @@ public static function _request( if ($sessionToken) { // add our current session token $httpClient->addRequestHeader('X-Parse-Session-Token', $sessionToken); - } if ($useMasterKey) { // pass master key $httpClient->addRequestHeader('X-Parse-Master-Key', self::$masterKey); - - } else if(isset(self::$restKey)) { + } elseif (isset(self::$restKey)) { // pass REST key $httpClient->addRequestHeader('X-Parse-REST-API-Key', self::$restKey); - } if (self::$forceRevocableSession) { // indicate we are using revocable sessions $httpClient->addRequestHeader('X-Parse-Revocable-Session', '1'); - } - } /* @@ -453,22 +475,19 @@ public static function _request( // create request url $url = self::$serverURL . '/' . self::$mountPath.ltrim($relativeUrl, '/'); - if($method === 'POST' || $method === 'PUT') { + if ($method === 'POST' || $method === 'PUT') { // add content type to the request $httpClient->addRequestHeader('Content-type', $contentType); - } if (!is_null(self::$connectionTimeout)) { // set connection timeout $httpClient->setConnectionTimeout(self::$connectionTimeout); - } if (!is_null(self::$timeout)) { // set request/response timeout $httpClient->setTimeout(self::$timeout); - } // send our request @@ -479,28 +498,24 @@ public static function _request( if (strpos($contentType, 'text/html') !== false) { throw new ParseException('Bad Request', -1); - } - if($httpClient->getErrorCode()) { - if(self::$enableCurlExceptions) { + if ($httpClient->getErrorCode()) { + if (self::$enableCurlExceptions) { throw new ParseException($httpClient->getErrorMessage(), $httpClient->getErrorCode()); - } else { return false; - } } $decoded = json_decode($response, true); - if(!isset($decoded) && $response !== '') { + if (!isset($decoded) && $response !== '') { throw new ParseException( 'Bad Request. Could not decode Response: '. '('.json_last_error().') '.self::getLastJSONErrorMsg(), -1 ); - } if (isset($decoded['error'])) { @@ -515,11 +530,9 @@ public static function _request( if ($returnHeaders) { $decoded['_headers'] = $httpClient->getResponseHeaders(); - } return $decoded; - } /** @@ -543,12 +556,10 @@ private static function getLastJSONErrorMsg() $error = json_last_error(); return isset($error_strings[$error]) ? $error_strings[$error] : 'Unknown error'; - } // use existing function return json_last_error_msg(); - } /** @@ -584,23 +595,54 @@ public static function _unsetStorage() self::$storage = null; } + /** + * Asserts that the server and mount path have been initialized + * + * @throws Exception + */ + private static function assertServerInitialized() + { + if (self::$serverURL === null) { + throw new Exception( + 'Missing a valid server url. '. + 'You must call ParseClient::setServerURL(\'https://your.parse-server.com\', \'/parse\') '. + ' before making any requests.' + ); + } + + if (self::$mountPath === null) { + throw new Exception( + 'Missing a valid mount path. '. + 'You must call ParseClient::setServerURL(\'https://your.parse-server.com\', \'/parse\') '. + ' before making any requests.' + ); + } + } + + /** + * Asserts that the sdk has been initialized with a valid application id + * + * @throws Exception + */ private static function assertParseInitialized() { if (self::$applicationId === null) { throw new Exception( - 'You must call Parse::initialize() before making any requests.' + 'You must call ParseClient::initialize() before making any requests.' ); } } /** + * Asserts that the sdk has been initialized with a valid account key + * * @throws Exception */ private static function assertAppInitialized() { if (self::$accountKey === null || empty(self::$accountKey)) { throw new Exception( - 'You must call Parse::initialize(..., $accountKey) before making any app requests. '. + 'You must call ParseClient::initialize(..., $accountKey) before making any app requests. '. 'Your account key must not be null or empty.' ); } diff --git a/src/Parse/ParseCloud.php b/src/Parse/ParseCloud.php index 6170cbd5..c6805892 100644 --- a/src/Parse/ParseCloud.php +++ b/src/Parse/ParseCloud.php @@ -1,11 +1,15 @@ + * @package Parse */ class ParseCloud { diff --git a/src/Parse/ParseConfig.php b/src/Parse/ParseConfig.php index cee2be6d..dd089ace 100644 --- a/src/Parse/ParseConfig.php +++ b/src/Parse/ParseConfig.php @@ -1,18 +1,27 @@ + * @package Parse */ class ParseConfig { + /** + * Current configuration data + * + * @var array + */ private $currentConfig; /** - * Creates. + * ParseConfig constructor. */ public function __construct() { @@ -20,6 +29,12 @@ public function __construct() $this->setConfig($result['params']); } + /** + * Gets a config value + * + * @param string $key Key of value to get + * @return mixed + */ public function get($key) { if (isset($this->currentConfig[$key])) { @@ -27,6 +42,12 @@ public function get($key) } } + /** + * Gets a config value with html characters encoded + * + * @param string $key Key of value to get + * @return string + */ public function escape($key) { if (isset($this->currentConfig[$key])) { @@ -34,14 +55,23 @@ public function escape($key) } } + /** + * Sets the config + * + * @param array $config Config to set + */ protected function setConfig($config) { $this->currentConfig = $config; } + /** + * Gets the current config + * + * @return array + */ public function getConfig() { return $this->currentConfig; - } } diff --git a/src/Parse/ParseException.php b/src/Parse/ParseException.php index 35ce91e2..2f46c886 100644 --- a/src/Parse/ParseException.php +++ b/src/Parse/ParseException.php @@ -1,13 +1,17 @@ + * @package Parse */ class ParseException extends Exception { diff --git a/src/Parse/ParseFile.php b/src/Parse/ParseFile.php index 0573a140..9c455b07 100755 --- a/src/Parse/ParseFile.php +++ b/src/Parse/ParseFile.php @@ -1,13 +1,17 @@ + * @package Parse */ class ParseFile implements Encodable { @@ -99,7 +103,6 @@ public function delete($useMasterKey = true) null, $useMasterKey ); - } /** @@ -109,16 +112,14 @@ public function delete($useMasterKey = true) */ public function getMimeType() { - if(isset($this->mimeType)) { + if (isset($this->mimeType)) { // return the mime type return $this->mimeType; - } else { // return an inferred mime type instead $fileParts = explode('.', $this->getName()); $extension = array_pop($fileParts); return $this->getMimeTypeForExtension($extension); - } } @@ -231,9 +232,14 @@ private function upload($useMasterKey = false) false, $mimeType ); - } + /** + * Attempts to download and return the contents of a ParseFile's url + * + * @return mixed + * @throws ParseException + */ private function download() { $rest = curl_init(); @@ -255,6 +261,12 @@ private function download() return $response; } + /** + * Returns the mimetype for a given extension + * + * @param string $extension Extension to return type for + * @return string + */ private function getMimeTypeForExtension($extension) { $knownTypes = [ diff --git a/src/Parse/ParseGeoPoint.php b/src/Parse/ParseGeoPoint.php index 7000ea4c..50a8ca8e 100755 --- a/src/Parse/ParseGeoPoint.php +++ b/src/Parse/ParseGeoPoint.php @@ -1,13 +1,17 @@ + * @package Parse */ class ParseGeoPoint implements Encodable { @@ -57,8 +61,8 @@ public function getLatitude() public function setLatitude($lat) { if (is_numeric($lat) && !is_float($lat)) { - $lat = (float)$lat; - } + $lat = (float)$lat; + } if ($lat > 90.0 || $lat < -90.0) { throw new ParseException('Latitude must be within range [-90.0, 90.0]'); } @@ -85,8 +89,8 @@ public function getLongitude() public function setLongitude($lon) { if (is_numeric($lon) && !is_float($lon)) { - $lon = (float)$lon; - } + $lon = (float)$lon; + } if ($lon > 180.0 || $lon < -180.0) { throw new ParseException( 'Longitude must be within range [-180.0, 180.0]' diff --git a/src/Parse/ParseHooks.php b/src/Parse/ParseHooks.php index 650a19f4..a15b5265 100644 --- a/src/Parse/ParseHooks.php +++ b/src/Parse/ParseHooks.php @@ -1,11 +1,15 @@ + * @package Parse */ class ParseHooks { diff --git a/src/Parse/ParseInstallation.php b/src/Parse/ParseInstallation.php index 49227d19..82705795 100644 --- a/src/Parse/ParseInstallation.php +++ b/src/Parse/ParseInstallation.php @@ -1,14 +1,23 @@ + * @package Parse */ class ParseInstallation extends ParseObject { + /** + * Parse Class name + * + * @var string + */ public static $parseClassName = '_Installation'; /** @@ -19,7 +28,6 @@ class ParseInstallation extends ParseObject public function getInstallationId() { return $this->get('installationId'); - } /** @@ -30,7 +38,6 @@ public function getInstallationId() public function getDeviceToken() { return $this->get('deviceToken'); - } /** @@ -41,7 +48,6 @@ public function getDeviceToken() public function getChannels() { return $this->get('channels'); - } /** @@ -52,7 +58,6 @@ public function getChannels() public function getDeviceType() { return $this->get('deviceType'); - } /** @@ -63,7 +68,6 @@ public function getDeviceType() public function getPushType() { return $this->get('pushType'); - } /** @@ -74,7 +78,6 @@ public function getPushType() public function getGCMSenderId() { return $this->get('GCMSenderId'); - } /** @@ -85,7 +88,6 @@ public function getGCMSenderId() public function getTimeZone() { return $this->get('timeZone'); - } /** @@ -96,7 +98,6 @@ public function getTimeZone() public function getLocaleIdentifier() { return $this->get('localeIdentifier'); - } /** @@ -107,7 +108,6 @@ public function getLocaleIdentifier() public function getBadge() { return $this->get('badge'); - } /** @@ -118,7 +118,6 @@ public function getBadge() public function getAppVersion() { return $this->get('appVersion'); - } /** @@ -129,7 +128,6 @@ public function getAppVersion() public function getAppName() { return $this->get('appName'); - } /** @@ -140,7 +138,6 @@ public function getAppName() public function getAppIdentifier() { return $this->get('appIdentifier'); - } /** @@ -151,7 +148,5 @@ public function getAppIdentifier() public function getParseVersion() { return $this->get('parseVersion'); - } - } diff --git a/src/Parse/ParseMemoryStorage.php b/src/Parse/ParseMemoryStorage.php index 1dd096e7..e4694f0e 100644 --- a/src/Parse/ParseMemoryStorage.php +++ b/src/Parse/ParseMemoryStorage.php @@ -1,30 +1,58 @@ + * @package Parse */ class ParseMemoryStorage implements ParseStorageInterface { /** + * Memory storage + * * @var array */ private $storage = []; + /** + * Sets a key-value pair in storage. + * + * @param string $key The key to set + * @param mixed $value The value to set + * + * @return void + */ public function set($key, $value) { $this->storage[$key] = $value; } + /** + * Remove a key from storage. + * + * @param string $key The key to remove. + * + * @return void + */ public function remove($key) { unset($this->storage[$key]); } + /** + * Gets the value for a key from storage. + * + * @param string $key The key to get the value for + * + * @return mixed + */ public function get($key) { if (isset($this->storage[$key])) { @@ -34,22 +62,40 @@ public function get($key) return; } + /** + * Clear all the values in storage. + * + * @return null + */ public function clear() { $this->storage = []; } + /** + * Save the data, if necessary. Not implemented. + */ public function save() { // No action required. return; } + /** + * Get all keys in storage. + * + * @return array + */ public function getKeys() { return array_keys($this->storage); } + /** + * Get all key-value pairs from storage. + * + * @return array + */ public function getAll() { return $this->storage; diff --git a/src/Parse/ParseObject.php b/src/Parse/ParseObject.php index 7a3bb203..c2811394 100644 --- a/src/Parse/ParseObject.php +++ b/src/Parse/ParseObject.php @@ -1,4 +1,7 @@ + * @package Parse */ class ParseObject implements Encodable { @@ -230,7 +234,6 @@ public function getAllKeys() public function has($key) { return isset($this->estimatedData[$key]); - } /** @@ -260,7 +263,7 @@ public function isDirty() * Detects if the object (and optionally the child objects) has unsaved * changes. * - * @param $considerChildren + * @param bool $considerChildren Whether to consider children when checking for dirty state * * @return bool */ @@ -271,6 +274,11 @@ protected function _isDirty($considerChildren) ($considerChildren && $this->hasDirtyChildren()); } + /** + * Determines whether this object has child objects that are dirty + * + * @return bool + */ private function hasDirtyChildren() { $result = false; @@ -460,6 +468,12 @@ public function isDataAvailable() return $this->hasBeenFetched; } + /** + * Returns whether or not data is available for a given key + * + * @param string $key Key to check availability of + * @return bool + */ private function _isDataAvailable($key) { return $this->isDataAvailable() || isset($this->dataAvailability[$key]); @@ -544,6 +558,13 @@ public static function fetchAll(array $objects, $useMasterKey = false) return static::updateWithFetchedResults($objects, $results); } + /** + * Creates an array of object ids from a given array of ParseObjects + * + * @param array $objects Objects to create id array from + * @return array + * @throws ParseException + */ private static function toObjectIdArray(array $objects) { $objectIds = []; @@ -565,6 +586,14 @@ private static function toObjectIdArray(array $objects) return $objectIds; } + /** + * Merges an existing array of objects with their fetched counterparts + * + * @param array $objects Original objects to update + * @param array $fetched Fetched object data to update with + * @return array + * @throws ParseException + */ private static function updateWithFetchedResults(array $objects, array $fetched) { $fetchedObjectsById = []; @@ -812,7 +841,9 @@ private static function destroyBatch(array $objects, $useMasterKey = false) foreach ($objects as $object) { $data[] = [ 'method' => 'DELETE', - 'path' => '/'.ParseClient::getMountPath().'classes/'.$object->getClassName().'/'.$object->getObjectId(), + 'path' => '/'.ParseClient::getMountPath(). + 'classes/'.$object->getClassName(). + '/'.$object->getObjectId(), ]; } $sessionToken = null; @@ -940,7 +971,9 @@ private function getSaveJSON() * * @return void */ - public function beforeSave(){} + public function beforeSave() + { + } /** * Save Object to Parse. @@ -1112,7 +1145,6 @@ function ($obj) use ( $unsavedFiles[] = $obj; } } - } ); } @@ -1267,7 +1299,7 @@ public function setACL($acl) } /** - * Get ACL assigned to the object. + * Get the ACL assigned to the object. * * @return ParseACL */ @@ -1276,6 +1308,12 @@ public function getACL() return $this->getACLWithCopy(true); } + /** + * Internally retrieves the ACL assigned to this object, conditionally returning a copy of the existing one + * + * @param bool $mayCopy Whether to return a copy of this acl or not + * @return ParseACL + */ private function getACLWithCopy($mayCopy) { if (!isset($this->estimatedData['ACL'])) { diff --git a/src/Parse/ParsePolygon.php b/src/Parse/ParsePolygon.php new file mode 100755 index 00000000..f5582748 --- /dev/null +++ b/src/Parse/ParsePolygon.php @@ -0,0 +1,88 @@ + + * @package Parse + */ +class ParsePolygon implements Encodable +{ + /** + * The coordinates. + * + * @var array + */ + private $coordinates; + + /** + * Create a Parse Polygon object. + * + * @param array $coords GeoPoints or Coordinates. + */ + public function __construct($coords) + { + $this->setCoordinates($coords); + } + + /** + * Set the Coordinates value for this Polygon. + * + * @param array $coords GeoPoints or Coordinates. + * + * @throws ParseException + */ + public function setCoordinates($coords) + { + if (!is_array($coords)) { + throw new ParseException('Coordinates must be an Array'); + } + if (count($coords) < 3) { + throw new ParseException('Polygon must have at least 3 GeoPoints or Points'); + } + $points = []; + foreach ($coords as $coord) { + $geoPoint; + if ($coord instanceof ParseGeoPoint) { + $geoPoint = $coord; + } elseif (is_array($coord) && count($coord) === 2) { + $geoPoint = new ParseGeoPoint($coord[0], $coord[1]); + } else { + throw new ParseException('Coordinates must be an Array of GeoPoints or Points'); + } + $points[] = [$geoPoint->getLatitude(), $geoPoint->getLongitude()]; + } + $this->coordinates = $points; + } + + /** + * Returns the Coordinates value for this Polygon. + * + * @return array + */ + public function getCoordinates() + { + return $this->coordinates; + } + + /** + * Encode to associative array representation. + * + * @return array + */ + public function _encode() + { + return [ + '__type' => 'Polygon', + 'coordinates' => $this->coordinates, + ]; + } +} diff --git a/src/Parse/ParsePush.php b/src/Parse/ParsePush.php index 4bc23469..f6000364 100644 --- a/src/Parse/ParsePush.php +++ b/src/Parse/ParsePush.php @@ -1,13 +1,17 @@ + * @package Parse */ class ParsePush { @@ -91,7 +95,6 @@ public static function hasStatus($response) isset($response['_headers']) && isset($response['_headers']['X-Parse-Push-Status-Id']) ); - } /** @@ -102,18 +105,16 @@ public static function hasStatus($response) */ public static function getStatus($response) { - if(!isset($response['_headers'])) { + if (!isset($response['_headers'])) { // missing headers return null; - } $headers = $response['_headers']; - if(!isset($headers['X-Parse-Push-Status-Id'])) { + if (!isset($headers['X-Parse-Push-Status-Id'])) { // missing push status id return null; - } // get our push status id @@ -121,6 +122,5 @@ public static function getStatus($response) // return our push status if it exists return ParsePushStatus::getFromId($pushStatusId); - } } diff --git a/src/Parse/ParsePushStatus.php b/src/Parse/ParsePushStatus.php index e4ef9090..17662fbe 100644 --- a/src/Parse/ParsePushStatus.php +++ b/src/Parse/ParsePushStatus.php @@ -1,14 +1,23 @@ + * @package Parse */ class ParsePushStatus extends ParseObject { + /** + * Parse Class name + * + * @var string + */ public static $parseClassName = '_PushStatus'; // possible push status values from parse server @@ -34,13 +43,10 @@ public static function getFromId($id) // return the associated PushStatus object $query = new ParseQuery(self::$parseClassName); return $query->get($id, true); - } catch (ParseException $pe) { // no push found return null; - } - } /** @@ -51,7 +57,6 @@ public static function getFromId($id) public function getPushTime() { return new \DateTime($this->get("pushTime")); - } /** @@ -73,7 +78,6 @@ public function getPushQuery() $query->_setConditions($queryConditions); return $query; - } /** @@ -84,7 +88,6 @@ public function getPushQuery() public function getPushPayload() { return json_decode($this->get("payload"), true); - } /** @@ -95,7 +98,6 @@ public function getPushPayload() public function getPushSource() { return $this->get("source"); - } /** @@ -106,7 +108,6 @@ public function getPushSource() public function getPushStatus() { return $this->get("status"); - } /** @@ -117,7 +118,6 @@ public function getPushStatus() public function isScheduled() { return $this->getPushStatus() === self::STATUS_SCHEDULED; - } /** @@ -128,7 +128,6 @@ public function isScheduled() public function isPending() { return $this->getPushStatus() === self::STATUS_PENDING; - } /** @@ -139,7 +138,6 @@ public function isPending() public function isRunning() { return $this->getPushStatus() === self::STATUS_RUNNING; - } /** @@ -150,7 +148,6 @@ public function isRunning() public function hasSucceeded() { return $this->getPushStatus() === self::STATUS_SUCCEEDED; - } /** @@ -161,7 +158,6 @@ public function hasSucceeded() public function hasFailed() { return $this->getPushStatus() === self::STATUS_FAILED; - } /** @@ -172,7 +168,6 @@ public function hasFailed() public function getPushesSent() { return $this->get("numSent"); - } /** @@ -183,7 +178,6 @@ public function getPushesSent() public function getPushHash() { return $this->get("pushHash"); - } /** @@ -194,6 +188,5 @@ public function getPushHash() public function getPushesFailed() { return $this->get("numFailed"); - } -} \ No newline at end of file +} diff --git a/src/Parse/ParseQuery.php b/src/Parse/ParseQuery.php index e2854b66..2dd1122e 100755 --- a/src/Parse/ParseQuery.php +++ b/src/Parse/ParseQuery.php @@ -1,13 +1,17 @@ + * @package Parse */ class ParseQuery { @@ -142,20 +146,16 @@ private function addCondition($key, $condition, $value) */ public function _setConditions($conditions) { - if(!is_array($conditions)) { + if (!is_array($conditions)) { throw new ParseException("Conditions must be in an array"); - } // iterate over and add each condition - foreach($conditions as $key => $entry) { - foreach($entry as $condition => $value) { + foreach ($conditions as $key => $entry) { + foreach ($entry as $condition => $value) { $this->addCondition($key, $condition, $value); - } - } - } /** @@ -645,6 +645,26 @@ public function withinPolygon($key, $points) return $this; } + /** + * Add a constraint to the query that requires a particular key's + * coordinates that contains a ParseGeoPoint + * + * @param string $key The key of the ParsePolygon + * @param ParseGeoPoint $point The point that will be contained. + * + * @return ParseQuery Returns this query, so you can chain this call. + */ + public function polygonContains($key, $point) + { + $this->addCondition( + $key, + '$geoIntersects', + ['$point' => $point] + ); + + return $this; + } + /** * Add a constraint to the query that requires a particular key's value to * be contained in the provided list of values. diff --git a/src/Parse/ParseRelation.php b/src/Parse/ParseRelation.php index 6cb24f3e..90fd2bb4 100644 --- a/src/Parse/ParseRelation.php +++ b/src/Parse/ParseRelation.php @@ -1,15 +1,18 @@ + * @package Parse */ class ParseRelation { diff --git a/src/Parse/ParseRole.php b/src/Parse/ParseRole.php index 6fbea262..6b22c8fb 100644 --- a/src/Parse/ParseRole.php +++ b/src/Parse/ParseRole.php @@ -1,14 +1,23 @@ + * @package Parse */ class ParseRole extends ParseObject { + /** + * Parse Class name + * + * @var string + */ public static $parseClassName = '_Role'; /** @@ -104,16 +113,14 @@ public function save($useMasterKey = false) 'Roles must have a name.' ); } - if($this->getObjectId() === null) { + if ($this->getObjectId() === null) { // Not yet saved, verify this name is not taken // ParseServer does not validate duplicate role names as of parse-server v2.3.2 $query = new ParseQuery('_Role'); $query->equalTo('name', $this->getName()); - if($query->count(true) > 0) { + if ($query->count(true) > 0) { throw new ParseException("Cannot add duplicate role name of '{$this->getName()}'"); - } - } return parent::save($useMasterKey); diff --git a/src/Parse/ParseSchema.php b/src/Parse/ParseSchema.php index 1bbbdba2..4e801142 100644 --- a/src/Parse/ParseSchema.php +++ b/src/Parse/ParseSchema.php @@ -1,4 +1,7 @@ + * @package Parse */ class ParseSchema { + /** + * String data type + * + * @var string + */ public static $STRING = 'String'; + + /** + * Number data type + * + * @var string + */ public static $NUMBER = 'Number'; + + /** + * Boolean data type + * + * @var string + */ public static $BOOLEAN = 'Boolean'; + + /** + * Date data type + * + * @var string + */ public static $DATE = 'Date'; + + /** + * File data type + * + * @var string + */ public static $FILE = 'File'; + + /** + * GeoPoint data type + * + * @var string + */ public static $GEO_POINT = 'GeoPoint'; + + /** + * Array data type + * + * @var string + */ public static $ARRAY = 'Array'; + + /** + * Object data type + * + * @var string + */ public static $OBJECT = 'Object'; + + /** + * Pointer data type + * + * @var string + */ public static $POINTER = 'Pointer'; + + /** + * Relation data type + * + * @var string + */ public static $RELATION = 'Relation'; /** @@ -43,7 +106,7 @@ class ParseSchema /** * Force to use master key in Schema Methods. * - * @see https://parse.com/docs/rest/guide#schemas + * @see http://docs.parseplatform.org/rest/guide/#schema * * @var bool */ diff --git a/src/Parse/ParseSession.php b/src/Parse/ParseSession.php index d16a920a..974d7afa 100644 --- a/src/Parse/ParseSession.php +++ b/src/Parse/ParseSession.php @@ -1,16 +1,30 @@ + * @package Parse */ class ParseSession extends ParseObject { + /** + * Parse Class name + * + * @var string + */ public static $parseClassName = '_Session'; + /** + * Session token string + * + * @var null|string + */ private $_sessionToken = null; /** diff --git a/src/Parse/ParseSessionStorage.php b/src/Parse/ParseSessionStorage.php index 36e1255a..cb9844d7 100644 --- a/src/Parse/ParseSessionStorage.php +++ b/src/Parse/ParseSessionStorage.php @@ -1,11 +1,15 @@ + * @package Parse */ class ParseSessionStorage implements ParseStorageInterface { @@ -16,6 +20,10 @@ class ParseSessionStorage implements ParseStorageInterface */ private $storageKey = 'parseData'; + /** + * ParseSessionStorage constructor. + * @throws ParseException + */ public function __construct() { if (session_status() !== PHP_SESSION_ACTIVE) { @@ -28,16 +36,38 @@ public function __construct() } } + /** + * Sets a key-value pair in storage. + * + * @param string $key The key to set + * @param mixed $value The value to set + * + * @return void + */ public function set($key, $value) { $_SESSION[$this->storageKey][$key] = $value; } + /** + * Remove a key from storage. + * + * @param string $key The key to remove. + * + * @return void + */ public function remove($key) { unset($_SESSION[$this->storageKey][$key]); } + /** + * Gets the value for a key from storage. + * + * @param string $key The key to get the value for + * + * @return mixed + */ public function get($key) { if (isset($_SESSION[$this->storageKey][$key])) { @@ -47,22 +77,40 @@ public function get($key) return; } + /** + * Clear all the values in storage. + * + * @return void + */ public function clear() { $_SESSION[$this->storageKey] = []; } + /** + * Save the data, if necessary. Not implemented. + */ public function save() { // No action required. PHP handles persistence for $_SESSION. return; } + /** + * Get all keys in storage. + * + * @return array + */ public function getKeys() { return array_keys($_SESSION[$this->storageKey]); } + /** + * Get all key-value pairs from storage. + * + * @return array + */ public function getAll() { return $_SESSION[$this->storageKey]; diff --git a/src/Parse/ParseStorageInterface.php b/src/Parse/ParseStorageInterface.php index 1578762a..ffbc2e04 100644 --- a/src/Parse/ParseStorageInterface.php +++ b/src/Parse/ParseStorageInterface.php @@ -1,11 +1,15 @@ + * @package Parse */ interface ParseStorageInterface { diff --git a/src/Parse/ParseUser.php b/src/Parse/ParseUser.php index 69da94a0..01579940 100644 --- a/src/Parse/ParseUser.php +++ b/src/Parse/ParseUser.php @@ -1,14 +1,23 @@ + * @package Parse */ class ParseUser extends ParseObject { + /** + * Parse Class name + * + * @var string + */ public static $parseClassName = '_User'; /** @@ -192,9 +201,11 @@ public static function logInWithTwitter( $screen_name, $consumer_key, $consumer_secret = null, + //@codingStandardsIgnoreLine $auth_token, - $auth_token_secret) - { + $auth_token_secret + ) { + if (!$id) { throw new ParseException('Cannot log in Twitter user without an id.'); } @@ -247,9 +258,15 @@ public static function loginWithAnonymous() */ $uuid_parts = str_split(md5(mt_rand()), 4); $authData = [ - 'id' => $uuid_parts[0].$uuid_parts[1].'-'.$uuid_parts[2].'-'.$uuid_parts[3].'-'.$uuid_parts[4].'-'.$uuid_parts[5].$uuid_parts[6].$uuid_parts[7], + 'id' => $uuid_parts[0]. + $uuid_parts[1].'-'. + $uuid_parts[2].'-'. + $uuid_parts[3].'-'. + $uuid_parts[4].'-'. + $uuid_parts[5]. + $uuid_parts[6]. + $uuid_parts[7], ]; - return self::logInWith('anonymous', $authData); } @@ -291,11 +308,13 @@ public function linkWithFacebook( $id, $access_token, $expiration_date = null, - $useMasterKey = false) - { + $useMasterKey = false + ) { + if (!$this->getObjectId()) { throw new ParseException( - 'Cannot link an unsaved user, use ParseUser::logInWithFacebook'); + 'Cannot link an unsaved user, use ParseUser::logInWithFacebook' + ); } if (!$id) { throw new ParseException('Cannot link Facebook user without an id.'); @@ -338,10 +357,12 @@ public function linkWithTwitter( $screen_name, $consumer_key, $consumer_secret = null, + //@codingStandardsIgnoreLine $auth_token, $auth_token_secret, - $useMasterKey = false) - { + $useMasterKey = false + ) { + if (!$this->getObjectId()) { throw new ParseException('Cannot link an unsaved user, use ParseUser::logInWithTwitter'); } @@ -383,8 +404,9 @@ public function linkWithTwitter( /** * Link the user with a service. * - * @param string $serviceName the name of the service - * @param array $authData the array of auth data for $serviceName + * @param string $serviceName the name of the service + * @param array $authData the array of auth data for $serviceName + * @param bool $useMasterKey Whether or not to use the master key, default is false * * @return ParseUser */ @@ -566,6 +588,9 @@ public static function requestPasswordReset($email) ParseClient::_request('POST', 'requestPasswordReset', null, $json); } + /** + * Sets the current user to null. Used internally for testing purposes. + */ public static function _clearCurrentUserVariable() { static::$currentUser = null; diff --git a/tests/Parse/AddOperationTest.php b/tests/Parse/AddOperationTest.php index 3ff30827..3804593a 100644 --- a/tests/Parse/AddOperationTest.php +++ b/tests/Parse/AddOperationTest.php @@ -8,7 +8,6 @@ namespace Parse\Test; - use Parse\Internal\AddOperation; use Parse\Internal\DeleteOperation; use Parse\Internal\SetOperation; @@ -32,7 +31,6 @@ public function testAddOperation() $addOp = new AddOperation($objects); $this->assertEquals($objects, $addOp->getValue()); - } /** @@ -40,10 +38,11 @@ public function testAddOperation() */ public function testBadObjects() { - $this->setExpectedException('\Parse\ParseException', - 'AddOperation requires an array.'); + $this->setExpectedException( + '\Parse\ParseException', + 'AddOperation requires an array.' + ); new AddOperation('not an array'); - } /** @@ -76,7 +75,6 @@ public function testMergePrevious() 'key2' => 'value2', 'key1' => 'value1' ], $merged->getValue(), 'Value was not as expected'); - } /** @@ -84,12 +82,13 @@ public function testMergePrevious() */ public function testInvalidMerge() { - $this->setExpectedException('\Parse\ParseException', - 'Operation is invalid after previous operation.'); + $this->setExpectedException( + '\Parse\ParseException', + 'Operation is invalid after previous operation.' + ); $addOp = new AddOperation([ 'key1' => 'value1' ]); $addOp->_mergeWithPrevious(new \DateTime()); - } -} \ No newline at end of file +} diff --git a/tests/Parse/AddUniqueOperationTest.php b/tests/Parse/AddUniqueOperationTest.php index 629fbbba..0a96f5fc 100644 --- a/tests/Parse/AddUniqueOperationTest.php +++ b/tests/Parse/AddUniqueOperationTest.php @@ -8,7 +8,6 @@ namespace Parse\Test; - use Parse\Internal\AddUniqueOperation; use Parse\Internal\DeleteOperation; use Parse\Internal\IncrementOperation; @@ -42,7 +41,6 @@ public function testAddUniqueOp() $addUnique = new AddUniqueOperation($objects); $this->assertEquals($objects, $addUnique->getValue()); - } /** @@ -50,10 +48,11 @@ public function testAddUniqueOp() */ public function testBadObjects() { - $this->setExpectedException('\Parse\ParseException', - 'AddUniqueOperation requires an array.'); + $this->setExpectedException( + '\Parse\ParseException', + 'AddUniqueOperation requires an array.' + ); $addUnique = new AddUniqueOperation('not-an-array'); - } /** @@ -73,7 +72,6 @@ public function testEncode() '__op' => 'AddUnique', 'objects' => ParseClient::_encode($objects, true) ], $encoded); - } /** @@ -106,7 +104,6 @@ public function testMergePrevious() 'key2' => 'value2', 'value1' ], $merged->getValue(), 'Value was not as expected'); - } /** @@ -114,13 +111,14 @@ public function testMergePrevious() */ public function testInvalidMerge() { - $this->setExpectedException('\Parse\ParseException', - 'Operation is invalid after previous operation.'); + $this->setExpectedException( + '\Parse\ParseException', + 'Operation is invalid after previous operation.' + ); $addOp = new AddUniqueOperation([ 'key1' => 'value1' ]); $addOp->_mergeWithPrevious(new IncrementOperation()); - } /** @@ -160,6 +158,5 @@ public function testApply() ]); $oldValue = $addOp->_apply($obj1, null, null); $this->assertEquals($obj1, $oldValue[0]); - } -} \ No newline at end of file +} diff --git a/tests/Parse/Helper.php b/tests/Parse/Helper.php index e3528e2d..fc69a9b9 100644 --- a/tests/Parse/Helper.php +++ b/tests/Parse/Helper.php @@ -51,7 +51,6 @@ public static function setUp() ); self::setServerURL(); self::setHttpClient(); - } public static function setHttpClient() @@ -64,20 +63,18 @@ public static function setHttpClient() // ParseStreamHttpClient // - if(function_exists('curl_init')) { + if (function_exists('curl_init')) { // cURL client ParseClient::setHttpClient(new ParseCurlHttpClient()); - } else { // stream client ParseClient::setHttpClient(new ParseStreamHttpClient()); } - } public static function setServerURL() { - ParseClient::setServerURL('http://localhost:1337','parse'); + ParseClient::setServerURL('http://localhost:1337', 'parse'); } public static function tearDown() @@ -104,6 +101,5 @@ public static function setUpWithoutCURLExceptions() false, self::$accountKey ); - } -} \ No newline at end of file +} diff --git a/tests/Parse/IncrementOperationTest.php b/tests/Parse/IncrementOperationTest.php index 76601971..0ec29f42 100644 --- a/tests/Parse/IncrementOperationTest.php +++ b/tests/Parse/IncrementOperationTest.php @@ -8,7 +8,6 @@ namespace Parse\Test; - use Parse\Internal\AddOperation; use Parse\Internal\DeleteOperation; use Parse\Internal\IncrementOperation; @@ -29,7 +28,6 @@ public function testIncrementOperation() { $addOp = new IncrementOperation(32); $this->assertEquals(32, $addOp->getValue()); - } /** @@ -54,7 +52,6 @@ public function testMergePrevious() $merged = $addOp->_mergeWithPrevious(new IncrementOperation(32)); $this->assertTrue($merged instanceof IncrementOperation); $this->assertEquals(33, $merged->getValue(), 'Value was not as expected'); - } /** @@ -62,10 +59,11 @@ public function testMergePrevious() */ public function testInvalidMerge() { - $this->setExpectedException('\Parse\ParseException', - 'Operation is invalid after previous operation.'); + $this->setExpectedException( + '\Parse\ParseException', + 'Operation is invalid after previous operation.' + ); $addOp = new IncrementOperation(); $addOp->_mergeWithPrevious(new AddOperation(['key' => 'value'])); - } -} \ No newline at end of file +} diff --git a/tests/Parse/ParseACLTest.php b/tests/Parse/ParseACLTest.php index 71208eff..9bc31ebf 100644 --- a/tests/Parse/ParseACLTest.php +++ b/tests/Parse/ParseACLTest.php @@ -28,10 +28,10 @@ public function tearDown() Helper::tearDown(); } - public function testIsSharedDefault() { + public function testIsSharedDefault() + { $acl = new ParseACL(); $this->assertFalse($acl->_isShared()); - } /** @@ -375,17 +375,18 @@ public function testIncludedObjectsGetACLs() $this->assertFalse($objectAgain->getACL()->getPublicWriteAccess()); } - public function testNullDefaultACL() { + public function testNullDefaultACL() + { // verify null acl returns itself ParseACL::setDefaultACL(null, true); $this->assertNull(ParseACL::_getDefaultACL()); - } /** * @group default-acls */ - public function testDefaultACL() { + public function testDefaultACL() + { // setup default acl $defaultACL = new ParseACL(); $defaultACL->setPublicReadAccess(false); @@ -399,7 +400,7 @@ public function testDefaultACL() { $this->assertTrue($acl->_isShared()); // verify empty - $this->assertEquals(new \stdClass(),$acl->_encode()); + $this->assertEquals(new \stdClass(), $acl->_encode()); // login as new user $user = new ParseUser(); @@ -420,7 +421,6 @@ public function testDefaultACL() { ParseUser::logOut(); $user->destroy(true); - } public function testIncludedObjectsGetACLWithDefaultACL() @@ -453,50 +453,57 @@ public function testIncludedObjectsGetACLWithDefaultACL() /** * @group acl-invalid */ - public function testCreatingACLWithInvalidId() { - $this->setExpectedException('\Exception', - 'Tried to create an ACL with an invalid userId.'); + public function testCreatingACLWithInvalidId() + { + $this->setExpectedException( + '\Exception', + 'Tried to create an ACL with an invalid userId.' + ); ParseACL::_createACLFromJSON([ 1234 => 'write' ]); - } /** * @group acl-invalid */ - public function testCreatingWithBadAccessType() { - $this->setExpectedException('\Exception', - 'Tried to create an ACL with an invalid permission type.'); + public function testCreatingWithBadAccessType() + { + $this->setExpectedException( + '\Exception', + 'Tried to create an ACL with an invalid permission type.' + ); ParseACL::_createACLFromJSON([ 'id' => [ 'not-valid' => true ] ]); - } /** * @group acl-invalid */ - public function testCreatingWithInvalidPermissionValue() { - $this->setExpectedException('\Exception', - 'Tried to create an ACL with an invalid permission value.'); + public function testCreatingWithInvalidPermissionValue() + { + $this->setExpectedException( + '\Exception', + 'Tried to create an ACL with an invalid permission value.' + ); ParseACL::_createACLFromJSON([ 'id' => [ 'write' => 'not-valid' ] ]); - } /** * @group acl-user-notallowed */ - public function testSettingPermissionForUserNotAllowed() { + public function testSettingPermissionForUserNotAllowed() + { // add 'userid' $acl = new ParseACL(); $acl->setPublicReadAccess(false); @@ -516,13 +523,13 @@ public function testSettingPermissionForUserNotAllowed() { 'read' => true ] ], $permissions); - } /** * @group removing-from-acl */ - public function testRemovingFromAcl() { + public function testRemovingFromAcl() + { // add 'userid' $acl = new ParseACL(); $acl->setPublicReadAccess(false); @@ -551,49 +558,57 @@ public function testRemovingFromAcl() { // verify acl is now empty, should be an instance of stdClass $permissions = $acl->_encode(); $this->assertEquals(new \stdClass(), $permissions, 'ACL not empty after removing last user.'); - } - public function testSettingUserReadAccessWithoutId() { - $this->setExpectedException('\Exception', - 'cannot setReadAccess for a user with null id'); + public function testSettingUserReadAccessWithoutId() + { + $this->setExpectedException( + '\Exception', + 'cannot setReadAccess for a user with null id' + ); $acl = new ParseACL(); $acl->setUserReadAccess(new ParseUser(), true); - } - public function testGettingUserReadAccessWithoutId() { - $this->setExpectedException('\Exception', - 'cannot getReadAccess for a user with null id'); + public function testGettingUserReadAccessWithoutId() + { + $this->setExpectedException( + '\Exception', + 'cannot getReadAccess for a user with null id' + ); $acl = new ParseACL(); $acl->getUserReadAccess(new ParseUser()); - } - public function testSettingUserWriteAccessWithoutId() { - $this->setExpectedException('\Exception', - 'cannot setWriteAccess for a user with null id'); + public function testSettingUserWriteAccessWithoutId() + { + $this->setExpectedException( + '\Exception', + 'cannot setWriteAccess for a user with null id' + ); $acl = new ParseACL(); $acl->setUserWriteAccess(new ParseUser(), true); - } - public function testGettingUserWriteAccessWithoutId() { - $this->setExpectedException('\Exception', - 'cannot getWriteAccess for a user with null id'); + public function testGettingUserWriteAccessWithoutId() + { + $this->setExpectedException( + '\Exception', + 'cannot getWriteAccess for a user with null id' + ); $acl = new ParseACL(); $acl->getUserWriteAccess(new ParseUser()); - } /** * @group test-role-access */ - public function testRoleAccess() { + public function testRoleAccess() + { $acl = new ParseACL(); // Create a role @@ -624,19 +639,21 @@ public function testRoleAccess() { $this->assertFalse($acl->getRoleWriteAccess($role)); $role->destroy(true); - } - public function testUnsavedRoleAdded() { - $this->setExpectedException('\Exception', - 'Roles must be saved to the server before they can be used in an ACL.'); + public function testUnsavedRoleAdded() + { + $this->setExpectedException( + '\Exception', + 'Roles must be saved to the server before they can be used in an ACL.' + ); $acl = new ParseACL(); $acl->setRoleReadAccess(new ParseRole(), true); - } - public function testRoleAccessWithName() { + public function testRoleAccessWithName() + { $acl = new ParseACL(); // Read Access $this->assertFalse($acl->getRoleReadAccessWithName('role')); @@ -659,6 +676,5 @@ public function testRoleAccessWithName() { // set back to false $acl->setRoleWriteAccessWithName('role', false); $this->assertFalse($acl->getRoleWriteAccessWithName('role')); - } } diff --git a/tests/Parse/ParseAnalyticsTest.php b/tests/Parse/ParseAnalyticsTest.php index 500868e4..b76faa06 100644 --- a/tests/Parse/ParseAnalyticsTest.php +++ b/tests/Parse/ParseAnalyticsTest.php @@ -78,21 +78,21 @@ public function testTrackEventDimensions() $this->assertAnalyticsValidation('testDate', $params, $expected); } - public function testBadKeyDimension() { + public function testBadKeyDimension() + { $this->setExpectedException( '\Exception', 'Dimensions expected string keys and values.' ); ParseAnalytics::track('event', [1=>'good-value']); - } - public function testBadValueDimension() { + public function testBadValueDimension() + { $this->setExpectedException( '\Exception', 'Dimensions expected string keys and values.' ); ParseAnalytics::track('event', ['good-key'=>1]); - } } diff --git a/tests/Parse/ParseAppTest.php b/tests/Parse/ParseAppTest.php index 564c8f24..6de8fa69 100755 --- a/tests/Parse/ParseAppTest.php +++ b/tests/Parse/ParseAppTest.php @@ -14,8 +14,10 @@ public static function setUpBeforeClass() public function testFetchingApps() { - $this->setExpectedException('Parse\ParseException', - 'unauthorized'); + $this->setExpectedException( + 'Parse\ParseException', + 'unauthorized' + ); self::_createApp(self::_getNewName()); self::_createApp(self::_getNewName()); @@ -26,8 +28,10 @@ public function testFetchingApps() public function testFetchSingleApp() { - $this->setExpectedException('Parse\ParseException', - 'unauthorized'); + $this->setExpectedException( + 'Parse\ParseException', + 'unauthorized' + ); $app_created = self::_createApp(self::_getNewName()); @@ -46,8 +50,10 @@ public function testFetchNotFound() public function testCreateApp() { - $this->setExpectedException('Parse\ParseException', - 'unauthorized'); + $this->setExpectedException( + 'Parse\ParseException', + 'unauthorized' + ); $app_name = self::_getNewName(); @@ -64,8 +70,10 @@ public function testCreateApp() public function testNameAlreadyInAccount() { - $this->setExpectedException('Parse\ParseException', - 'unauthorized'); + $this->setExpectedException( + 'Parse\ParseException', + 'unauthorized' + ); $app_name = self::_getNewName(); @@ -81,8 +89,10 @@ public function testNameAlreadyInAccount() public function testUpdateApp() { - $this->setExpectedException('Parse\ParseException', - 'unauthorized'); + $this->setExpectedException( + 'Parse\ParseException', + 'unauthorized' + ); $app_name = self::_getNewName(); $updated_name = self::_getNewName(); diff --git a/tests/Parse/ParseClientTest.php b/tests/Parse/ParseClientTest.php index eacfe0ee..8f838051 100644 --- a/tests/Parse/ParseClientTest.php +++ b/tests/Parse/ParseClientTest.php @@ -8,7 +8,6 @@ namespace Parse\Test; - use Parse\HttpClients\ParseCurlHttpClient; use Parse\HttpClients\ParseStreamHttpClient; use Parse\ParseClient; @@ -31,8 +30,6 @@ public function setUp() { Helper::setServerURL(); Helper::setHttpClient(); - - } public function tearDown() @@ -41,16 +38,16 @@ public function tearDown() // unset CA file ParseClient::setCAFile(null); - } /** * @group client-not-initialized */ - public function testParseNotInitialized() { + public function testParseNotInitialized() + { $this->setExpectedException( '\Exception', - 'You must call Parse::initialize() before making any requests.' + 'You must call ParseClient::initialize() before making any requests.' ); ParseClient::initialize( @@ -63,16 +60,16 @@ public function testParseNotInitialized() { '', '' ); - - } /** * @group client-not-initialized */ - public function testAppNotNotInitialized() { - $this->setExpectedException('\Exception', - 'You must call Parse::initialize(..., $accountKey) before making any app requests. '. + public function testAppNotNotInitialized() + { + $this->setExpectedException( + '\Exception', + 'You must call ParseClient::initialize(..., $accountKey) before making any app requests. '. 'Your account key must not be null or empty.' ); @@ -90,13 +87,13 @@ public function testAppNotNotInitialized() { false, true ); - } /** * @group client-init */ - public function testInitialize() { + public function testInitialize() + { // unregister associated sub classes ParseUser::_unregisterSubclass(); @@ -122,13 +119,13 @@ public function testInitialize() { // verify storage is now set $this->assertNotNull(ParseClient::getStorage()); - } /** * @group client-storage */ - public function testStorage() { + public function testStorage() + { // unset storage ParseClient::_unsetStorage(); @@ -143,8 +140,10 @@ public function testStorage() { ); $storage = ParseClient::getStorage(); - $this->assertTrue($storage instanceof ParseMemoryStorage, - 'Not an instance of ParseMemoryStorage'); + $this->assertTrue( + $storage instanceof ParseMemoryStorage, + 'Not an instance of ParseMemoryStorage' + ); /* TODO can't get session storage test to pass properly // unset storage @@ -180,69 +179,78 @@ public function testStorage() { /** * @group client-test */ - public function testSetServerURL() { + public function testSetServerURL() + { // add extra slashes to test removal ParseClient::setServerURL('https://example.com//', '//parse//'); // verify APIUrl $this->assertEquals( 'https://example.com/parse/', - ParseClient::getAPIUrl()); + ParseClient::getAPIUrl() + ); // verify mount path $this->assertEquals( 'parse/', ParseClient::getMountPath() ); - } /** * @group client-test */ - public function testRootMountPath() { + public function testRootMountPath() + { ParseClient::setServerURL('https://example.com', '/'); $this->assertEquals( '', ParseClient::getMountPath(), - 'Mount path was not reduced to an empty sequence for root'); - + 'Mount path was not reduced to an empty sequence for root' + ); } /** * @group client-test */ - public function testBadServerURL() { - $this->setExpectedException('\Exception', - 'Invalid Server URL.'); + public function testBadServerURL() + { + $this->setExpectedException( + '\Exception', + 'Invalid Server URL.' + ); ParseClient::setServerURL(null, 'parse'); - } /** * @group client-test */ - public function testBadMountPath() { - $this->setExpectedException('\Exception', - 'Invalid Mount Path.'); + public function testBadMountPath() + { + $this->setExpectedException( + '\Exception', + 'Invalid Mount Path.' + ); ParseClient::setServerURL('https://example.com', null); - } /** * @group encoding-error */ - public function testEncodingError() { - $this->setExpectedException('\Exception', - 'Invalid type encountered.'); + public function testEncodingError() + { + $this->setExpectedException( + '\Exception', + 'Invalid type encountered.' + ); ParseClient::_encode(new Helper(), false); - } /** * @group client-decoding */ - public function testDecodingStdClass() { + public function testDecodingStdClass() + { $obj = new \stdClass(); $obj->property = 'value'; @@ -252,13 +260,13 @@ public function testDecodingStdClass() { $emptyClass = new \stdClass(); $this->assertEquals($emptyClass, ParseClient::_decode($emptyClass)); - } /** * @group timeouts */ - public function testCurlTimeout() { + public function testCurlTimeout() + { ParseClient::setTimeout(3000); @@ -273,13 +281,13 @@ public function testCurlTimeout() { // clear timeout ParseClient::setTimeout(null); - } /** * @group timeouts */ - public function testCurlConnectionTimeout() { + public function testCurlConnectionTimeout() + { ParseClient::setConnectionTimeout(3000); // perform a standard save @@ -293,13 +301,13 @@ public function testCurlConnectionTimeout() { // clear timeout ParseClient::setConnectionTimeout(null); - } /** * @group timeouts */ - public function testStreamTimeout() { + public function testStreamTimeout() + { ParseClient::setHttpClient(new ParseStreamHttpClient()); @@ -316,13 +324,13 @@ public function testStreamTimeout() { // clear timeout ParseClient::setTimeout(null); - } /** * @group timeouts */ - public function testStreamConnectionTimeout() { + public function testStreamConnectionTimeout() + { ParseClient::setHttpClient(new ParseStreamHttpClient()); @@ -339,32 +347,33 @@ public function testStreamConnectionTimeout() { // clear timeout ParseClient::setConnectionTimeout(null); - } /** * @group no-curl-exceptions */ - public function testNoCurlExceptions() { + public function testNoCurlExceptions() + { Helper::setUpWithoutCURLExceptions(); ParseClient::setServerURL('http://404.example.com', 'parse'); $result = ParseClient::_request( 'GET', 'not-a-real-endpoint-to-reach', - null); + null + ); $this->assertFalse($result); // put back Helper::setUp(); - } /** * @group curl-exceptions */ - public function testCurlException() { + public function testCurlException() + { ParseClient::setHttpClient(new ParseCurlHttpClient()); @@ -374,14 +383,15 @@ public function testCurlException() { ParseClient::_request( 'GET', 'not-a-real-endpoint-to-reach', - null); - + null + ); } /** * @group stream-exceptions */ - public function testStreamException() { + public function testStreamException() + { ParseClient::setHttpClient(new ParseStreamHttpClient()); @@ -391,8 +401,8 @@ public function testStreamException() { ParseClient::_request( 'GET', 'not-a-real-endpoint-to-reach', - null); - + null + ); } /** @@ -406,8 +416,10 @@ public function testStreamException() { */ public function testBadStreamRequest() { - $this->setExpectedException('\Parse\ParseException', - "Bad Request"); + $this->setExpectedException( + '\Parse\ParseException', + "Bad Request" + ); ParseClient::setHttpClient(new ParseStreamHttpClient()); @@ -415,7 +427,8 @@ public function testBadStreamRequest() ParseClient::_request( 'GET', '', - null); + null + ); } /** @@ -423,8 +436,10 @@ public function testBadStreamRequest() */ public function testCurlBadRequest() { - $this->setExpectedException('\Parse\ParseException', - "Bad Request"); + $this->setExpectedException( + '\Parse\ParseException', + "Bad Request" + ); ParseClient::setHttpClient(new ParseCurlHttpClient()); @@ -432,8 +447,8 @@ public function testCurlBadRequest() ParseClient::_request( 'GET', '', - null); - + null + ); } /** @@ -447,16 +462,13 @@ public function testGetDefaultHttpClient() // get default client $default = ParseClient::getHttpClient(); - if(function_exists('curl_init')) { + if (function_exists('curl_init')) { // should be a curl client $this->assertTrue($default instanceof ParseCurlHttpClient); - } else { // should be a stream client $this->assertTrue($default instanceof ParseStreamHttpClient); - } - } /** @@ -470,15 +482,17 @@ public function testCurlCAFile() // not a real ca file, just testing setting ParseClient::setCAFile("not-real-ca-file"); - $this->setExpectedException('\Parse\ParseException', - "Bad Request"); + $this->setExpectedException( + '\Parse\ParseException', + "Bad Request" + ); ParseClient::setServerURL('http://example.com', '/'); ParseClient::_request( 'GET', '', - null); - + null + ); } /** @@ -492,15 +506,49 @@ public function testStreamCAFile() // not a real ca file, just testing setting ParseClient::setCAFile("not-real-ca-file"); - $this->setExpectedException('\Parse\ParseException', - "Bad Request"); + $this->setExpectedException( + '\Parse\ParseException', + "Bad Request" + ); ParseClient::setServerURL('http://example.com', '/'); ParseClient::_request( 'GET', '', - null); + null + ); + } + /** + * @group api-not-set + */ + public function testURLNotSet() + { + $this->setExpectedException( + '\Exception', + 'Missing a valid server url. '. + 'You must call ParseClient::setServerURL(\'https://your.parse-server.com\', \'/parse\') '. + ' before making any requests.' + ); + + ParseClient::_clearServerURL(); + (new ParseObject('TestingClass'))->save(); + } + + /** + * @group api-not-set + */ + public function testMountPathNotSet() + { + $this->setExpectedException( + '\Exception', + 'Missing a valid mount path. '. + 'You must call ParseClient::setServerURL(\'https://your.parse-server.com\', \'/parse\') '. + ' before making any requests.' + ); + + ParseClient::_clearMountPath(); + (new ParseObject('TestingClass'))->save(); } /** @@ -508,8 +556,10 @@ public function testStreamCAFile() */ public function testBadApiResponse() { - $this->setExpectedException('\Parse\ParseException', - 'Bad Request. Could not decode Response: (4) Syntax error'); + $this->setExpectedException( + '\Parse\ParseException', + 'Bad Request. Could not decode Response: (4) Syntax error' + ); $httpClient = ParseClient::getHttpClient(); @@ -533,7 +583,5 @@ public function testBadApiResponse() // attempt to save, which should not fire our given code $obj = new ParseObject('TestingClass'); $obj->save(); - } - -} \ No newline at end of file +} diff --git a/tests/Parse/ParseCloudTest.php b/tests/Parse/ParseCloudTest.php index cb039aca..0c362f72 100644 --- a/tests/Parse/ParseCloudTest.php +++ b/tests/Parse/ParseCloudTest.php @@ -17,27 +17,27 @@ public static function setUpBeforeClass() public function tearDown() { $user = ParseUser::getCurrentUser(); - if(isset($user)) { + if (isset($user)) { ParseUser::logOut(); $user->destroy(true); - } } /** * @group cloud-code */ - public function testFunctionCall() { + public function testFunctionCall() + { $response = ParseCloud::run('bar', [ 'key1' => 'value2', 'key2' => 'value1' ]); $this->assertEquals('Foo', $response); - } - public function testFunctionCallWithUser() { + public function testFunctionCallWithUser() + { $user = new ParseUser(); $user->setUsername("someuser"); $user->setPassword("somepassword"); @@ -52,15 +52,17 @@ public function testFunctionCallWithUser() { ParseUser::logOut(); $user->destroy(true); - } /** * @group cloud-code */ - public function testFunctionCallException() { - $this->setExpectedException('\Parse\ParseException', - 'bad stuff happened'); + public function testFunctionCallException() + { + $this->setExpectedException( + '\Parse\ParseException', + 'bad stuff happened' + ); ParseCloud::run('bar', [ 'key1' => 'value1', @@ -80,7 +82,6 @@ public function testFunctionsWithObjectParamsFails() $params = ['key1' => $obj]; $this->setExpectedException('\Exception', 'ParseObjects not allowed'); ParseCloud::run('foo', $params); - } /** @@ -89,8 +90,10 @@ public function testFunctionsWithObjectParamsFails() public function testFunctionsWithGeoPointParamsDoNotThrow() { $params = ['key1' => new ParseGeoPoint(50, 50)]; - $this->setExpectedException('Parse\ParseException', - 'Invalid function: "unknown_function"'); + $this->setExpectedException( + 'Parse\ParseException', + 'Invalid function: "unknown_function"' + ); ParseCloud::run('unknown_function', $params); } @@ -100,8 +103,10 @@ public function testFunctionsWithGeoPointParamsDoNotThrow() public function testUnknownFunctionFailure() { $params = ['key1' => 'value1']; - $this->setExpectedException('Parse\ParseException', - 'Invalid function: "unknown_function"'); + $this->setExpectedException( + 'Parse\ParseException', + 'Invalid function: "unknown_function"' + ); ParseCloud::run('unknown_function', $params); } } diff --git a/tests/Parse/ParseConfigTest.php b/tests/Parse/ParseConfigTest.php index 8fefaa23..c232d6c6 100644 --- a/tests/Parse/ParseConfigTest.php +++ b/tests/Parse/ParseConfigTest.php @@ -18,7 +18,6 @@ public function testDefaultConfig() { $config = new ParseConfig(); $this->assertEquals([], $config->getConfig()); - } /** @@ -35,13 +34,13 @@ public function testGetConfig() // check html value $this->assertEquals('', $config->get('another')); - } /** * @group parse-config */ - public function testEscapeConfig() { + public function testEscapeConfig() + { $config = new ConfigMock(); // check html encoded value @@ -52,6 +51,5 @@ public function testEscapeConfig() { // check normal value $this->assertEquals('bar', $config->escape('foo')); - } } diff --git a/tests/Parse/ParseCurlHttpClientTest.php b/tests/Parse/ParseCurlHttpClientTest.php index cb163b27..667b841a 100644 --- a/tests/Parse/ParseCurlHttpClientTest.php +++ b/tests/Parse/ParseCurlHttpClientTest.php @@ -8,7 +8,6 @@ namespace Parse\Test; - use Parse\HttpClients\ParseCurlHttpClient; class ParseCurlHttpClientTest extends \PHPUnit_Framework_TestCase @@ -20,6 +19,5 @@ public function testResponseStatusCode() $client->send("http://example.com"); $this->assertEquals(200, $client->getResponseStatusCode()); - } -} \ No newline at end of file +} diff --git a/tests/Parse/ParseCurlTest.php b/tests/Parse/ParseCurlTest.php index f92b6396..cd37d38b 100644 --- a/tests/Parse/ParseCurlTest.php +++ b/tests/Parse/ParseCurlTest.php @@ -8,7 +8,6 @@ namespace Parse\Test; - use Parse\HttpClients\ParseCurl; use Parse\ParseException; @@ -16,71 +15,78 @@ class ParseCurlTest extends \PHPUnit_Framework_TestCase { public function testBadExec() { - $this->setExpectedException('\Parse\ParseException', - 'You must call ParseCurl::init first'); + $this->setExpectedException( + '\Parse\ParseException', + 'You must call ParseCurl::init first' + ); $parseCurl = new ParseCurl(); $parseCurl->exec(); - } public function testBadSetOption() { - $this->setExpectedException('\Parse\ParseException', - 'You must call ParseCurl::init first'); + $this->setExpectedException( + '\Parse\ParseException', + 'You must call ParseCurl::init first' + ); $parseCurl = new ParseCurl(); $parseCurl->setOption(1, 1); - } public function testBadSetOptionsArray() { - $this->setExpectedException('\Parse\ParseException', - 'You must call ParseCurl::init first'); + $this->setExpectedException( + '\Parse\ParseException', + 'You must call ParseCurl::init first' + ); $parseCurl = new ParseCurl(); $parseCurl->setOptionsArray([]); - } public function testBadGetInfo() { - $this->setExpectedException('\Parse\ParseException', - 'You must call ParseCurl::init first'); + $this->setExpectedException( + '\Parse\ParseException', + 'You must call ParseCurl::init first' + ); $parseCurl = new ParseCurl(); $parseCurl->getInfo(1); - } public function testBadGetError() { - $this->setExpectedException('\Parse\ParseException', - 'You must call ParseCurl::init first'); + $this->setExpectedException( + '\Parse\ParseException', + 'You must call ParseCurl::init first' + ); $parseCurl = new ParseCurl(); $parseCurl->getError(); - } public function testBadErrorCode() { - $this->setExpectedException('\Parse\ParseException', - 'You must call ParseCurl::init first'); + $this->setExpectedException( + '\Parse\ParseException', + 'You must call ParseCurl::init first' + ); $parseCurl = new ParseCurl(); $parseCurl->getErrorCode(); - } public function testBadClose() { - $this->setExpectedException('\Parse\ParseException', - 'You must call ParseCurl::init first'); + $this->setExpectedException( + '\Parse\ParseException', + 'You must call ParseCurl::init first' + ); $parseCurl = new ParseCurl(); $parseCurl->close(); - } -} \ No newline at end of file +} diff --git a/tests/Parse/ParseFileTest.php b/tests/Parse/ParseFileTest.php index 81e0c8f9..58174c09 100644 --- a/tests/Parse/ParseFileTest.php +++ b/tests/Parse/ParseFileTest.php @@ -67,11 +67,12 @@ public function testParseFileDownload() */ public function testParseFileDownloadUnsaved() { - $this->setExpectedException('\Parse\ParseException', - 'Cannot retrieve data for unsaved ParseFile.'); + $this->setExpectedException( + '\Parse\ParseException', + 'Cannot retrieve data for unsaved ParseFile.' + ); $file = ParseFile::createFromData(null, 'file.txt'); $file->getData(); - } /** @@ -79,11 +80,12 @@ public function testParseFileDownloadUnsaved() */ public function testParsefileDeleteUnsaved() { - $this->setExpectedException('\Parse\ParseException', - 'Cannot delete file that has not been saved.'); + $this->setExpectedException( + '\Parse\ParseException', + 'Cannot delete file that has not been saved.' + ); $file = ParseFile::createFromData('a test file', 'file.txt'); $file->delete(); - } /** @@ -94,7 +96,6 @@ public function testParseFileDownloadBadURL() $this->setExpectedException('\Parse\ParseException', '', 6); $file = ParseFile::_createFromServer('file.txt', 'http://404.example.com'); $file->getData(); - } /** diff --git a/tests/Parse/ParseGeoBoxTest.php b/tests/Parse/ParseGeoBoxTest.php index b831f22e..6417ca09 100644 --- a/tests/Parse/ParseGeoBoxTest.php +++ b/tests/Parse/ParseGeoBoxTest.php @@ -63,7 +63,8 @@ public function testGeoBox() /* , should fail because it crosses the dateline try { $results = $query->find(); - $this->assertTrue(false, 'Query should fail because it crosses dateline, with results:'.json_encode($results[0])); + $this->assertTrue(false, 'Query should fail because it crosses + dateline with results:'.json_encode($results[0])); } catch (ParseException $e) { } */ diff --git a/tests/Parse/ParseHooksTest.php b/tests/Parse/ParseHooksTest.php index ba1b2fb5..bdcf38c8 100644 --- a/tests/Parse/ParseHooksTest.php +++ b/tests/Parse/ParseHooksTest.php @@ -44,7 +44,6 @@ public function testSingleFunction() ], $function); self::$hooks->deleteFunction('baz'); - } public function testSingleFunctionNotFound() @@ -82,8 +81,10 @@ public function testCreateFunctionAlreadyExists() try { self::$hooks->createFunction('baz', 'https://api.example.com/baz'); } catch (ParseException $ex) { - $this->assertEquals('function name: baz already exits', - $ex->getMessage()); + $this->assertEquals( + 'function name: baz already exits', + $ex->getMessage() + ); } self::$hooks->deleteFunction('baz'); @@ -122,9 +123,10 @@ public function testCreateTriggerAlreadyExists() self::$hooks->createTrigger('Game', 'beforeDelete', 'https://api.example.com/Game/beforeDelete'); $this->fail(); } catch (ParseException $ex) { - $this->assertEquals('class Game already has trigger beforeDelete', - $ex->getMessage()); - + $this->assertEquals( + 'class Game already has trigger beforeDelete', + $ex->getMessage() + ); } self::$hooks->deleteTrigger('Game', 'beforeDelete'); @@ -202,6 +204,5 @@ public function testFetchFunctions() self::$hooks->deleteFunction('func1'); self::$hooks->deleteFunction('func2'); self::$hooks->deleteFunction('func3'); - } } diff --git a/tests/Parse/ParseInstallationTest.php b/tests/Parse/ParseInstallationTest.php index bfef41c9..a1a50c6d 100644 --- a/tests/Parse/ParseInstallationTest.php +++ b/tests/Parse/ParseInstallationTest.php @@ -2,7 +2,6 @@ namespace Parse\Test; - use Parse\ParseException; use Parse\ParseInstallation; @@ -23,8 +22,10 @@ public function tearDown() */ public function testMissingIdentifyingField() { - $this->setExpectedException('\Parse\ParseException', - 'at least one ID field (deviceToken, installationId) must be specified in this operation'); + $this->setExpectedException( + '\Parse\ParseException', + 'at least one ID field (deviceToken, installationId) must be specified in this operation' + ); (new ParseInstallation())->save(); } @@ -34,13 +35,14 @@ public function testMissingIdentifyingField() */ public function testMissingDeviceType() { - $this->setExpectedException('\Parse\ParseException', - 'deviceType must be specified in this operation'); + $this->setExpectedException( + '\Parse\ParseException', + 'deviceType must be specified in this operation' + ); $installation = new ParseInstallation(); $installation->set('deviceToken', '12345'); $installation->save(); - } /** @@ -48,12 +50,13 @@ public function testMissingDeviceType() */ public function testClientsCannotFindWithoutMasterKey() { - $this->setExpectedException('\Parse\ParseException', - 'Clients aren\'t allowed to perform the find operation on the installation collection.'); + $this->setExpectedException( + '\Parse\ParseException', + 'Clients aren\'t allowed to perform the find operation on the installation collection.' + ); $query = ParseInstallation::query(); $query->first(); - } /** @@ -66,12 +69,13 @@ public function testClientsCannotDestroyWithoutMasterKey() $installation->set('deviceType', 'android'); $installation->save(); - $this->setExpectedException('\Parse\ParseException', - "Clients aren't allowed to perform the delete operation on the installation collection."); + $this->setExpectedException( + '\Parse\ParseException', + "Clients aren't allowed to perform the delete operation on the installation collection." + ); // try destroying, without using the master key $installation->destroy(); - } /** @@ -136,7 +140,5 @@ public function testInstallation() // cleanup $installation->destroy(true); - } - -} \ No newline at end of file +} diff --git a/tests/Parse/ParseMemoryStorageTest.php b/tests/Parse/ParseMemoryStorageTest.php index e30e8759..10f1f0b4 100644 --- a/tests/Parse/ParseMemoryStorageTest.php +++ b/tests/Parse/ParseMemoryStorageTest.php @@ -69,6 +69,5 @@ public function testSave() { // does nothing self::$parseStorage->save(); - } } diff --git a/tests/Parse/ParseObjectMock.php b/tests/Parse/ParseObjectMock.php index 53283533..053f55cd 100644 --- a/tests/Parse/ParseObjectMock.php +++ b/tests/Parse/ParseObjectMock.php @@ -8,10 +8,9 @@ namespace Parse\Test; - use Parse\ParseObject; class ParseObjectMock extends ParseObject { -} \ No newline at end of file +} diff --git a/tests/Parse/ParseObjectTest.php b/tests/Parse/ParseObjectTest.php index d00fdee3..086cd5db 100644 --- a/tests/Parse/ParseObjectTest.php +++ b/tests/Parse/ParseObjectTest.php @@ -108,7 +108,6 @@ public function testDeleteStream() $query = new ParseQuery('TestObject'); $this->setExpectedException('Parse\ParseException', 'Object not found'); $out = $query->get($obj->getObjectId()); - } public function testDeleteCurl() @@ -122,7 +121,6 @@ public function testDeleteCurl() $query = new ParseQuery('TestObject'); $this->setExpectedException('Parse\ParseException', 'Object not found'); $out = $query->get($obj->getObjectId()); - } public function testFind() @@ -810,7 +808,6 @@ public function testDestroyAll() ParseUser::logOut(); $user->destroy(true); - } public function testEmptyArray() @@ -958,7 +955,6 @@ public function testSaveAllStream() $query = new ParseQuery('TestObject'); $result = $query->find(); $this->assertEquals(90, count($result)); - } public function testSaveAllCurl() @@ -976,7 +972,6 @@ public function testSaveAllCurl() $query = new ParseQuery('TestObject'); $result = $query->find(); $this->assertEquals(90, count($result)); - } /** @@ -1063,9 +1058,11 @@ public function testFetchAll() public function testNoRegisteredSubclasses() { - $this->setExpectedException('\Exception', + $this->setExpectedException( + '\Exception', 'You must initialize the ParseClient using ParseClient::initialize '. - 'and your Parse API keys before you can begin working with Objects.'); + 'and your Parse API keys before you can begin working with Objects.' + ); ParseUser::_unregisterSubclass(); ParseRole::_unregisterSubclass(); ParseInstallation::_unregisterSubclass(); @@ -1073,20 +1070,20 @@ public function testNoRegisteredSubclasses() ParsePushStatus::_unregisterSubclass(); new ParseObject('TestClass'); - } public function testMissingClassName() { Helper::setUp(); - $this->setExpectedException('\Exception', + $this->setExpectedException( + '\Exception', 'You must specify a Parse class name or register the appropriate '. 'subclass when creating a new Object. Use ParseObject::create to '. - 'create a subclass object.'); + 'create a subclass object.' + ); new ParseObjectMock(); - } public function testSettingProperties() @@ -1095,16 +1092,16 @@ public function testSettingProperties() $obj->key = "value"; $this->assertEquals('value', $obj->get('key')); - } public function testSettingProtectedProperty() { - $this->setExpectedException('\Exception', - 'Protected field could not be set.'); + $this->setExpectedException( + '\Exception', + 'Protected field could not be set.' + ); $obj = new ParseObject('TestClass'); $obj->updatedAt = "value"; - } public function testGettingProperties() @@ -1112,7 +1109,6 @@ public function testGettingProperties() $obj = new ParseObject('TestClass'); $obj->key = "value"; $this->assertEquals('value', $obj->key); - } public function testNullValues() @@ -1131,7 +1127,6 @@ public function testNullValues() $this->assertNull($obj->get('key2')); $obj->destroy(); - } public function testIsset() @@ -1152,7 +1147,6 @@ public function testIsset() // null should return false $obj->set('key', null); $this->assertFalse(isset($obj->key), 'Failed on null'); - } public function testGetAllKeys() @@ -1169,7 +1163,6 @@ public function testGetAllKeys() 'key2' => 'value2', 'key3' => 'value3' ], $estimatedData); - } /** @@ -1232,16 +1225,16 @@ public function testDirtyChildren() $obj->destroy(); $obj2->destroy(); $obj3->destroy(); - } public function testSetNullKey() { - $this->setExpectedException('\Exception', - 'key may not be null.'); + $this->setExpectedException( + '\Exception', + 'key may not be null.' + ); $obj = new ParseObject('TestClass'); $obj->set(null, 'value'); - } public function testSetWithArrayValue() @@ -1252,16 +1245,16 @@ public function testSetWithArrayValue() ); $obj = new ParseObject('TestClass'); $obj->set('key', ['is-an-array' => 'yes']); - } public function testSetArrayNullKey() { - $this->setExpectedException('\Exception', - 'key may not be null.'); + $this->setExpectedException( + '\Exception', + 'key may not be null.' + ); $obj = new ParseObject('TestClass'); $obj->setArray(null, ['is-an-array' => 'yes']); - } public function testSetArrayWithNonArrayValue() @@ -1272,16 +1265,16 @@ public function testSetArrayWithNonArrayValue() ); $obj = new ParseObject('TestClass'); $obj->setArray('key', 'not-an-array'); - } public function testAsocSetArrayNullKey() { - $this->setExpectedException('\Exception', - 'key may not be null.'); + $this->setExpectedException( + '\Exception', + 'key may not be null.' + ); $obj = new ParseObject('TestClass'); $obj->setAssociativeArray(null, ['is-an-array' => 'yes']); - } public function testAsocSetArrayWithNonArrayValue() @@ -1292,7 +1285,6 @@ public function testAsocSetArrayWithNonArrayValue() ); $obj = new ParseObject('TestClass'); $obj->setAssociativeArray('key', 'not-an-array'); - } public function testRemovingNullKey() @@ -1303,7 +1295,6 @@ public function testRemovingNullKey() ); $obj = new ParseObject('TestClass'); $obj->remove(null, 'value'); - } public function testRevert() @@ -1316,19 +1307,19 @@ public function testRevert() $this->assertNull($obj->key1); $this->assertNull($obj->key2); - } public function testEmptyFetchAll() { $this->assertEmpty(ParseObject::fetchAll([])); - } public function testFetchAllMixedClasses() { - $this->setExpectedException('\Parse\ParseException', - 'All objects should be of the same class.'); + $this->setExpectedException( + '\Parse\ParseException', + 'All objects should be of the same class.' + ); $objs = []; $obj = new ParseObject('TestClass1'); @@ -1340,26 +1331,28 @@ public function testFetchAllMixedClasses() $objs[] = $obj; ParseObject::fetchAll($objs); - } public function testFetchAllUnsavedWithoutId() { - $this->setExpectedException('\Parse\ParseException', - 'All objects must have an ID.'); + $this->setExpectedException( + '\Parse\ParseException', + 'All objects must have an ID.' + ); $objs = []; $objs[] = new ParseObject('TestClass'); $objs[] = new ParseObject('TestClass'); ParseObject::fetchAll($objs); - } public function testFetchAllUnsavedWithId() { - $this->setExpectedException('\Parse\ParseException', - 'All objects must exist on the server.'); + $this->setExpectedException( + '\Parse\ParseException', + 'All objects must exist on the server.' + ); $objs = []; $objs[] = new ParseObject('TestClass', 'objectid1'); @@ -1381,7 +1374,6 @@ public function testRevertingUnsavedChangesViaFetch() $this->assertEquals('phpguy', $obj->montymxb); $obj->destroy(); - } public function testMergeFromServer() @@ -1405,14 +1397,12 @@ public function testMergeFromServer() $this->assertEquals('new value', $obj->get('key')); $obj->destroy(); - } public function testDestroyingUnsaved() { $obj = new ParseObject('TestClass'); $obj->destroy(); - } public function testEncodeWithArray() @@ -1422,15 +1412,15 @@ public function testEncodeWithArray() $encoded = json_decode($obj->_encode(), true); $this->assertEquals($encoded['arraykey'], ['value1','value2']); - } public function testToPointerWithoutId() { - $this->setExpectedException('\Exception', - "Can't serialize an unsaved Parse.Object"); + $this->setExpectedException( + '\Exception', + "Can't serialize an unsaved Parse.Object" + ); (new ParseObject('TestClass'))->_toPointer(); - } public function testGettingSharedACL() @@ -1445,15 +1435,15 @@ public function testGettingSharedACL() $this->assertTrue($copy !== $acl); $this->assertEquals($copy->_encode(), $acl->_encode()); - } public function testSubclassRegisterMissingParseClassName() { - $this->setExpectedException('\Exception', - 'Cannot register a subclass that does not have a parseClassName'); + $this->setExpectedException( + '\Exception', + 'Cannot register a subclass that does not have a parseClassName' + ); ParseObjectMock::registerSubclass(); - } public function testGetRegisteredSubclass() @@ -1464,13 +1454,14 @@ public function testGetRegisteredSubclass() $subclass = ParseObject::getRegisteredSubclass('Unknown'); $this->assertTrue($subclass instanceof ParseObject); $this->assertEquals('Unknown', $subclass->getClassName()); - } public function testGettingQueryForUnregisteredSubclass() { - $this->setExpectedException('\Exception', - 'Cannot create a query for an unregistered subclass.'); + $this->setExpectedException( + '\Exception', + 'Cannot create a query for an unregistered subclass.' + ); ParseObjectMock::query(); } @@ -1492,6 +1483,5 @@ public function testEncodeEncodable() $this->assertEquals($encoded['key1'], $encodable1->_encode()); $this->assertEquals($encoded['key2'][0], $encodable2->_encode()); - } } diff --git a/tests/Parse/ParsePolygonTest.php b/tests/Parse/ParsePolygonTest.php new file mode 100644 index 00000000..192b7ad7 --- /dev/null +++ b/tests/Parse/ParsePolygonTest.php @@ -0,0 +1,177 @@ +set('polygon', $polygon); + $obj->save(); + + // Query by open points + $query = new ParseQuery('TestObject'); + $query->equalTo('polygon', $polygon); + + $results = $query->find(); + $actualPolygon = $results[0]->get('polygon'); + + $this->assertEquals(1, count($results)); + $this->assertEquals($closedPoints, $actualPolygon->getCoordinates()); + + // Query by closed points + $polygon = new ParsePolygon($closedPoints); + $query = new ParseQuery('TestObject'); + $query->equalTo('polygon', $polygon); + + $results = $query->find(); + $actualPolygon = $results[0]->get('polygon'); + + $this->assertEquals(1, count($results)); + $this->assertEquals($closedPoints, $actualPolygon->getCoordinates()); + } + + public function testPolygonWithGeoPoints() + { + $p1 = new ParseGeoPoint(0, 0); + $p2 = new ParseGeoPoint(0, 1); + $p3 = new ParseGeoPoint(1, 1); + $p4 = new ParseGeoPoint(1, 0); + $p5 = new ParseGeoPoint(0, 0); + + $points = [$p1, $p2, $p3, $p4]; + $openPoints = [[0,0],[0,1],[1,1],[1,0]]; + $closedPoints = [[0,0],[0,1],[1,1],[1,0],[0,0]]; + $polygon = new ParsePolygon($points); + + $obj = ParseObject::create('TestObject'); + $obj->set('polygon', $polygon); + $obj->save(); + + // Query by open points + $query = new ParseQuery('TestObject'); + $query->equalTo('polygon', $polygon); + + $results = $query->find(); + $actualPolygon = $results[0]->get('polygon'); + + $this->assertEquals(1, count($results)); + $this->assertEquals($closedPoints, $actualPolygon->getCoordinates()); + + // Query by closed points + $polygon = new ParsePolygon($closedPoints); + $query = new ParseQuery('TestObject'); + $query->equalTo('polygon', $polygon); + + $results = $query->find(); + $actualPolygon = $results[0]->get('polygon'); + + $this->assertEquals(1, count($results)); + $this->assertEquals($closedPoints, $actualPolygon->getCoordinates()); + } + + public function testPolygonMinimum() + { + $this->setExpectedException( + '\Parse\ParseException', + 'Polygon must have at least 3 GeoPoints or Points' + ); + $polygon = new ParsePolygon([[0,0]]); + $obj = ParseObject::create('TestObject'); + $obj->set('polygon', $polygon); + $obj->save(); + } + + public function testPolygonInvalidInput() + { + $this->setExpectedException( + '\Parse\ParseException', + 'Coordinates must be an Array' + ); + $polygon = new ParsePolygon(1234); + $obj = ParseObject::create('TestObject'); + $obj->set('polygon', $polygon); + $obj->save(); + } + + public function testPolygonInvalidArray() + { + $this->setExpectedException( + '\Parse\ParseException', + 'Coordinates must be an Array of GeoPoints or Points' + ); + $polygon = new ParsePolygon([['str1'],['str2'],['str3']]); + $obj = ParseObject::create('TestObject'); + $obj->set('polygon', $polygon); + $obj->save(); + } + + public function testPolygonContains() + { + $points1 = [[0,0],[0,1],[1,1],[1,0]]; + $points2 = [[0,0],[0,2],[2,2],[2,0]]; + $points3 = [[10,10],[10,15],[15,15],[15,10],[10,10]]; + + $polygon1 = new ParsePolygon($points1); + $polygon2 = new ParsePolygon($points2); + $polygon3 = new ParsePolygon($points3); + + $obj1 = ParseObject::create('TestObject'); + $obj2 = ParseObject::create('TestObject'); + $obj3 = ParseObject::create('TestObject'); + + $obj1->set('polygon', $polygon1); + $obj2->set('polygon', $polygon2); + $obj3->set('polygon', $polygon3); + + ParseObject::saveAll([$obj1, $obj2, $obj3]); + + $point = new ParseGeoPoint(0.5, 0.5); + $query = new ParseQuery('TestObject'); + $query->polygonContains('polygon', $point); + $results = $query->find(); + $this->assertEquals(2, count($results)); + } + + public function testPolygonContainsInvalidInput() + { + $this->setExpectedException( + '\Parse\ParseException', + 'bad $geoIntersect value; $point should be GeoPoint' + ); + $points = [[0,0],[0,1],[1,1],[1,0]]; + $polygon = new ParsePolygon($points); + $obj = ParseObject::create('TestObject'); + $obj->set('polygon', $polygon); + $obj->save(); + + $query = new ParseQuery('TestObject'); + $query->polygonContains('polygon', 1234); + $results = $query->find(); + } +} diff --git a/tests/Parse/ParsePushTest.php b/tests/Parse/ParsePushTest.php index 0675cbe8..4b2a697c 100644 --- a/tests/Parse/ParsePushTest.php +++ b/tests/Parse/ParsePushTest.php @@ -20,7 +20,8 @@ public function tearDown() Helper::tearDown(); } - public function testNoMasterKey() { + public function testNoMasterKey() + { $this->setExpectedException('\Parse\ParseException'); ParsePush::send( @@ -37,8 +38,9 @@ public function testBasicPush() [ 'channels' => [''], 'data' => ['alert' => 'sample message'], - ] - , true); + ], + true + ); } /** @@ -46,15 +48,16 @@ public function testBasicPush() */ public function testMissingWhereAndChannels() { - $this->setExpectedException('\Parse\ParseException', - "Sending a push requires either \"channels\" or a \"where\" query."); + $this->setExpectedException( + '\Parse\ParseException', + "Sending a push requires either \"channels\" or a \"where\" query." + ); ParsePush::send([ 'data' => [ 'alert' => 'are we missing something?' ] ], true); - } /** @@ -62,8 +65,10 @@ public function testMissingWhereAndChannels() */ public function testWhereAndChannels() { - $this->setExpectedException('\Parse\ParseException', - "Channels and query can not be set at the same time."); + $this->setExpectedException( + '\Parse\ParseException', + "Channels and query can not be set at the same time." + ); $query = ParseInstallation::query(); $query->equalTo('key', 'value'); @@ -78,7 +83,6 @@ public function testWhereAndChannels() ], 'where' => $query ], true); - } public function testPushToQuery() @@ -89,9 +93,9 @@ public function testPushToQuery() [ 'data' => ['alert' => 'iPhone 5 is out!'], 'where' => $query, - ] - , true); - + ], + true + ); } public function testPushToQueryWithoutWhere() @@ -101,22 +105,24 @@ public function testPushToQueryWithoutWhere() [ 'data' => ['alert' => 'Done without conditions!'], 'where' => $query, - ] - , true); - + ], + true + ); } public function testNonQueryWhere() { - $this->setExpectedException('\Exception', - 'Where parameter for Parse Push must be of type ParseQuery'); + $this->setExpectedException( + '\Exception', + 'Where parameter for Parse Push must be of type ParseQuery' + ); ParsePush::send( [ 'data' => ['alert' => 'Will this really work?'], 'where' => 'not-a-query', - ] - , true); - + ], + true + ); } public function testPushDates() @@ -127,14 +133,17 @@ public function testPushDates() 'push_time' => new \DateTime(), 'expiration_time' => new \DateTime(), 'channels' => [], - ] - , true); + ], + true + ); } public function testExpirationTimeAndIntervalSet() { - $this->setExpectedException('\Exception', - 'Both expiration_time and expiration_interval can\'t be set.'); + $this->setExpectedException( + '\Exception', + 'Both expiration_time and expiration_interval can\'t be set.' + ); ParsePush::send( [ 'data' => ['alert' => 'iPhone 5 is out!'], @@ -142,9 +151,9 @@ public function testExpirationTimeAndIntervalSet() 'expiration_time' => new \DateTime(), 'expiration_interval' => 90, 'channels' => [], - ] - , true); - + ], + true + ); } /** @@ -156,12 +165,12 @@ public function testPushHasHeaders() [ 'channels' => [''], 'data' => ['alert' => 'sample message'], - ] - , true); + ], + true + ); // verify headers are present $this->assertArrayHasKey('_headers', $response); - } /** @@ -177,8 +186,9 @@ public function testGettingPushStatus() [ 'channels' => [''], 'data' => $payload, - ] - , true); + ], + true + ); // verify push status id is present $this->assertTrue(isset($response['_headers']['X-Parse-Push-Status-Id'])); @@ -192,8 +202,10 @@ public function testGettingPushStatus() $this->assertNotNull($pushStatus); // verify values - $this->assertTrue($pushStatus->getPushTime() instanceof \DateTime, - 'Push time was not as expected'); + $this->assertTrue( + $pushStatus->getPushTime() instanceof \DateTime, + 'Push time was not as expected' + ); $query = $pushStatus->getPushQuery(); $options = $query->_getOptions(); @@ -208,12 +220,18 @@ public function testGettingPushStatus() ], $options); // verify payload - $this->assertEquals($payload, $pushStatus->getPushPayload(), - 'Payload did not match'); + $this->assertEquals( + $payload, + $pushStatus->getPushPayload(), + 'Payload did not match' + ); // verify source - $this->assertEquals("rest", $pushStatus->getPushSource(), - 'Source was not rest'); + $this->assertEquals( + "rest", + $pushStatus->getPushSource(), + 'Source was not rest' + ); // verify not scheduled $this->assertFalse($pushStatus->isScheduled()); @@ -222,24 +240,33 @@ public function testGettingPushStatus() $this->assertFalse($pushStatus->isPending()); // verify 'running' - $this->assertTrue($pushStatus->isRunning(), - 'Push did not succeed'); + $this->assertTrue( + $pushStatus->isRunning(), + 'Push did not succeed' + ); // verify # sent & failed - $this->assertEquals(0, $pushStatus->getPushesSent(), - 'More than 0 pushes sent'); - $this->assertEquals(0, $pushStatus->getPushesFailed(), - 'More than 0 pushes failed'); + $this->assertEquals( + 0, + $pushStatus->getPushesSent(), + 'More than 0 pushes sent' + ); + $this->assertEquals( + 0, + $pushStatus->getPushesFailed(), + 'More than 0 pushes failed' + ); - $this->assertNotNull($pushStatus->getPushHash(), - 'Hash not present'); + $this->assertNotNull( + $pushStatus->getPushHash(), + 'Hash not present' + ); // verify we have neither failed or succeeded $this->assertFalse($pushStatus->hasFailed()); $this->assertFalse($pushStatus->hasSucceeded()); - } /** @@ -249,13 +276,11 @@ public function testGettingNonExistentPushStatus() { $pushStatus = ParsePushStatus::getFromId('not-a-real-id'); $this->assertNull($pushStatus); - } public function testDoesNotHaveStatus() { $this->assertFalse(ParsePush::hasStatus([])); - } public function testGetStatus() @@ -274,6 +299,5 @@ public function testGetStatus() 'X-Parse-Push-Status-Id' => 'not-a-real-id' ] ])); - } } diff --git a/tests/Parse/ParseQueryTest.php b/tests/Parse/ParseQueryTest.php index 73a680c0..48d1ee02 100644 --- a/tests/Parse/ParseQueryTest.php +++ b/tests/Parse/ParseQueryTest.php @@ -173,7 +173,6 @@ public function testEndsWithSingle() 'bar0', 'EndsWith function did not return the correct object.' ); - } public function testStartsWithSingle() @@ -212,9 +211,8 @@ public function testStartsWithMiddle() $user = ParseUser::getCurrentUser(); - if(isset($user)) { + if (isset($user)) { throw new ParseException($user->_encode()); - } $this->provideTestObjects(10); @@ -1604,13 +1602,12 @@ public function testOrderByUpdatedAtAsc() $numbers = [3, 1, 2]; $objects = []; - foreach($numbers as $num) { + foreach ($numbers as $num) { $obj = ParseObject::create('TestObject'); $obj->set('number', $num); $obj->save(); $objects[] = $obj; sleep(1); - } $objects[1]->set('number', 4); @@ -1642,13 +1639,12 @@ public function testOrderByUpdatedAtDesc() $numbers = [3, 1, 2]; $objects = []; - foreach($numbers as $num) { + foreach ($numbers as $num) { $obj = ParseObject::create('TestObject'); $obj->set('number', $num); $obj->save(); $objects[] = $obj; sleep(1); - } $objects[1]->set('number', 4); @@ -2213,7 +2209,8 @@ public function testRestrictedCount() $this->assertEquals(1, $count); } - public function testAscendingByArray() { + public function testAscendingByArray() + { $obj = new ParseObject('TestObject'); $obj->set('name', 'John'); $obj->set('country', 'US'); @@ -2238,18 +2235,18 @@ public function testAscendingByArray() { $this->assertEquals('Joel', $results[0]->name); $this->assertEquals('Bob', $results[1]->name); $this->assertEquals('John', $results[2]->name); - } public function testOrQueriesVaryingClasses() { - $this->setExpectedException('\Exception', - 'All queries must be for the same class'); + $this->setExpectedException( + '\Exception', + 'All queries must be for the same class' + ); ParseQuery::orQueries([ new ParseQuery('Class1'), new ParseQuery('Class2') ]); - } /** @@ -2275,11 +2272,12 @@ public function testSetConditions() public function testBadConditions() { - $this->setExpectedException('\Parse\ParseException', - "Conditions must be in an array"); + $this->setExpectedException( + '\Parse\ParseException', + "Conditions must be in an array" + ); $query = new ParseQuery('TestObject'); $query->_setConditions('not-an-array'); - } } diff --git a/tests/Parse/ParseRelationOperationTest.php b/tests/Parse/ParseRelationOperationTest.php index fe4b5a9f..12258c51 100644 --- a/tests/Parse/ParseRelationOperationTest.php +++ b/tests/Parse/ParseRelationOperationTest.php @@ -8,7 +8,6 @@ namespace Parse\Test; - use Parse\Internal\ParseRelationOperation; use Parse\ParseObject; use Parse\ParseRelation; @@ -30,10 +29,11 @@ public function tearDown() */ public function testMissingObjects() { - $this->setExpectedException('\Exception', - 'Cannot create a ParseRelationOperation with no objects.'); + $this->setExpectedException( + '\Exception', + 'Cannot create a ParseRelationOperation with no objects.' + ); new ParseRelationOperation(null, null); - } /** @@ -41,15 +41,16 @@ public function testMissingObjects() */ public function testMixedClasses() { - $this->setExpectedException('\Exception', - 'All objects in a relation must be of the same class.'); + $this->setExpectedException( + '\Exception', + 'All objects in a relation must be of the same class.' + ); $objects = []; $objects[] = new ParseObject('Class1'); $objects[] = new ParseObject('Class2'); new ParseRelationOperation($objects, null); - } /** @@ -66,11 +67,10 @@ public function testSingleObjects() $encoded = $op->_encode(); - $this->assertEquals('AddRelation' ,$encoded['ops'][0]['__op']); - $this->assertEquals('RemoveRelation' ,$encoded['ops'][1]['__op']); + $this->assertEquals('AddRelation', $encoded['ops'][0]['__op']); + $this->assertEquals('RemoveRelation', $encoded['ops'][1]['__op']); ParseObject::destroyAll([$addObj, $delObj]); - } /** @@ -78,17 +78,18 @@ public function testSingleObjects() */ public function testApplyDifferentClassRelation() { - $this->setExpectedException('\Exception', + $this->setExpectedException( + '\Exception', 'Related object object must be of class ' .'Class1, but DifferentClass' - .' was passed in.'); + .' was passed in.' + ); // create one op $addObj = new ParseObject('Class1'); $relOp1 = new ParseRelationOperation($addObj, null); $relOp1->_apply(new ParseRelation(null, null, 'DifferentClass'), null, null); - } /** @@ -96,12 +97,13 @@ public function testApplyDifferentClassRelation() */ public function testInvalidApply() { - $this->setExpectedException('\Exception', - 'Operation is invalid after previous operation.'); + $this->setExpectedException( + '\Exception', + 'Operation is invalid after previous operation.' + ); $addObj = new ParseObject('Class1'); $op = new ParseRelationOperation($addObj, null); $op->_apply('bad value', null, null); - } /** @@ -112,7 +114,6 @@ public function testMergeNone() $addObj = new ParseObject('Class1'); $op = new ParseRelationOperation($addObj, null); $this->assertEquals($op, $op->_mergeWithPrevious(null)); - } /** @@ -120,10 +121,12 @@ public function testMergeNone() */ public function testMergeDifferentClass() { - $this->setExpectedException('\Exception', + $this->setExpectedException( + '\Exception', 'Related object object must be of class ' .'Class1, but AnotherClass' - .' was passed in.'); + .' was passed in.' + ); $addObj = new ParseObject('Class1'); $op = new ParseRelationOperation($addObj, null); @@ -132,7 +135,6 @@ public function testMergeDifferentClass() $mergeOp = new ParseRelationOperation($diffObj, null); $this->assertEquals($op, $op->_mergeWithPrevious($mergeOp)); - } /** @@ -140,12 +142,13 @@ public function testMergeDifferentClass() */ public function testInvalidMerge() { - $this->setExpectedException('\Exception', - 'Operation is invalid after previous operation.'); + $this->setExpectedException( + '\Exception', + 'Operation is invalid after previous operation.' + ); $obj = new ParseObject('Class1'); $op = new ParseRelationOperation($obj, null); $op->_mergeWithPrevious('not a relational op'); - } /** @@ -160,6 +163,5 @@ public function testRemoveElementsFromArray() ParseRelationOperation::removeElementsFromArray('removeThis', $array); $this->assertEmpty($array); - } -} \ No newline at end of file +} diff --git a/tests/Parse/ParseRelationTest.php b/tests/Parse/ParseRelationTest.php index 7521c96e..83331b47 100644 --- a/tests/Parse/ParseRelationTest.php +++ b/tests/Parse/ParseRelationTest.php @@ -186,7 +186,6 @@ public function testSwitchingParent() $this->assertEquals(1, count($children)); $this->assertEquals('child3', $children[0]->get('name')); - } /** @@ -216,7 +215,5 @@ public function testBiDirectionalRelations() $child2->save(); $parent->save(); - } - } diff --git a/tests/Parse/ParseRoleTest.php b/tests/Parse/ParseRoleTest.php index 0ee7c347..f1efa6f9 100644 --- a/tests/Parse/ParseRoleTest.php +++ b/tests/Parse/ParseRoleTest.php @@ -91,10 +91,11 @@ public function testRoleNameUnique() $role = ParseRole::createRole('Admin', $this->aclPublic()); $role->save(); $role2 = ParseRole::createRole('Admin', $this->aclPublic()); - $this->setExpectedException('Parse\ParseException', - "Cannot add duplicate role name of 'Admin'"); + $this->setExpectedException( + 'Parse\ParseException', + "Cannot add duplicate role name of 'Admin'" + ); $role2->save(); - } /** @@ -164,7 +165,6 @@ public function testAddUserAfterFetch() $roleAgain->save(); ParseUser::logOut(); - } /** @@ -235,11 +235,12 @@ public function createEden() public function testSettingNonStringAsName() { - $this->setExpectedException('\Parse\ParseException', - "A role's name must be a string."); + $this->setExpectedException( + '\Parse\ParseException', + "A role's name must be a string." + ); $role = new ParseRole(); $role->setName(12345); - } /** @@ -247,11 +248,12 @@ public function testSettingNonStringAsName() */ public function testSavingWithoutName() { - $this->setExpectedException('\Parse\ParseException', - 'Roles must have a name.'); + $this->setExpectedException( + '\Parse\ParseException', + 'Roles must have a name.' + ); $role = new ParseRole(); $role->setACL(new ParseACL()); $role->save(); - } } diff --git a/tests/Parse/ParseSchemaTest.php b/tests/Parse/ParseSchemaTest.php index 3c13c3f8..004f699d 100644 --- a/tests/Parse/ParseSchemaTest.php +++ b/tests/Parse/ParseSchemaTest.php @@ -4,7 +4,7 @@ /** * ParseSchema Tests. * - * @see https://parse.com/docs/rest/guide#schemas + * @see http://docs.parseplatform.org/rest/guide/#schema * * @author Júlio César Gonçalves de Oliveira */ @@ -39,7 +39,6 @@ public function setUp() self::$schema = new ParseSchema('SchemaTest'); Helper::clearClass('_User'); Helper::setHttpClient(); - } public function tearDown() @@ -159,7 +158,6 @@ public function testUpdateSchemaStream() } $this->assertNotNull($result['fields']['quantity']); $this->assertNotNull($result['fields']['status']); - } public function testUpdateSchemaCurl() @@ -184,7 +182,6 @@ public function testUpdateSchemaCurl() } $this->assertNotNull($result['fields']['quantity']); $this->assertNotNull($result['fields']['status']); - } public function testUpdateWrongFieldType() @@ -205,8 +202,10 @@ public function testDeleteSchema() $deleteSchema->delete(); $getSchema = new ParseSchema('SchemaDeleteTest'); - $this->setExpectedException('Parse\ParseException', - 'Class SchemaDeleteTest does not exist.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Class SchemaDeleteTest does not exist.' + ); $getSchema->get(); } @@ -343,7 +342,6 @@ public function testBadSchemaGet() $schema = new ParseSchema(self::$badClassName); $schema->get(); - } /** @@ -360,7 +358,6 @@ public function testBadSchemaSave() $schema = new ParseSchema(self::$badClassName); $schema->save(); - } /** @@ -377,7 +374,6 @@ public function testBadSchemaUpdate() $schema = new ParseSchema(self::$badClassName); $schema->update(); - } /** @@ -394,7 +390,5 @@ public function testBadSchemaDelete() $schema = new ParseSchema(self::$badClassName); $schema->delete(); - } - } diff --git a/tests/Parse/ParseSessionStorageAltTest.php b/tests/Parse/ParseSessionStorageAltTest.php index 7d66a1f1..9ff0a1cf 100644 --- a/tests/Parse/ParseSessionStorageAltTest.php +++ b/tests/Parse/ParseSessionStorageAltTest.php @@ -8,7 +8,6 @@ namespace Parse\Test; - use Parse\ParseException; use Parse\ParseSessionStorage; @@ -19,9 +18,10 @@ class ParseSessionStorageAltTest extends \PHPUnit_Framework_TestCase */ public function testNoSessionActive() { - $this->setExpectedException('\Parse\ParseException', - 'PHP session_start() must be called first.'); + $this->setExpectedException( + '\Parse\ParseException', + 'PHP session_start() must be called first.' + ); new ParseSessionStorage(); - } -} \ No newline at end of file +} diff --git a/tests/Parse/ParseSessionStorageTest.php b/tests/Parse/ParseSessionStorageTest.php index 93185576..9e7cfa24 100644 --- a/tests/Parse/ParseSessionStorageTest.php +++ b/tests/Parse/ParseSessionStorageTest.php @@ -84,7 +84,6 @@ public function testSave() { // does nothing self::$parseStorage->save(); - } /** @@ -99,6 +98,5 @@ public function testRecreatingSessionStorage() new ParseSessionStorage(); $this->assertEmpty($_SESSION['parseData']); - } } diff --git a/tests/Parse/ParseStreamHttpClientTest.php b/tests/Parse/ParseStreamHttpClientTest.php index 2637afa8..9cd8eef5 100644 --- a/tests/Parse/ParseStreamHttpClientTest.php +++ b/tests/Parse/ParseStreamHttpClientTest.php @@ -8,7 +8,6 @@ namespace Parse\Test; - use Parse\HttpClients\ParseStreamHttpClient; use Parse\ParseClient; use Parse\ParseException; @@ -27,18 +26,19 @@ public function testGetResponse() $headers = $client->getResponseHeaders(); $this->assertEquals('HTTP/1.0 200 OK', $headers['http_code']); - } public function testInvalidUrl() { $url = 'http://example.com/lots of spaces here'; - $this->setExpectedException('\Parse\ParseException', + $this->setExpectedException( + '\Parse\ParseException', 'Url may not contain spaces for stream client: ' - .$url); + .$url + ); $client = new ParseStreamHttpClient(); $client->send($url); } -} \ No newline at end of file +} diff --git a/tests/Parse/ParseUserTest.php b/tests/Parse/ParseUserTest.php index ccd7a302..8f63d889 100644 --- a/tests/Parse/ParseUserTest.php +++ b/tests/Parse/ParseUserTest.php @@ -83,64 +83,82 @@ public function testLoginWrongPassword() public function testLoginWithFacebook() { - $this->setExpectedException('Parse\ParseException', - 'Facebook auth is invalid for this user.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Facebook auth is invalid for this user.' + ); $user = ParseUser::logInWithFacebook('asdf', 'zxcv'); } public function testLoginWithFacebookNoId() { - $this->setExpectedException('Parse\ParseException', - 'Cannot log in Facebook user without an id.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot log in Facebook user without an id.' + ); $user = ParseUser::logInWithFacebook(null, 'asdf'); } public function testLoginWithFacebookNoAccessToken() { - $this->setExpectedException('Parse\ParseException', - 'Cannot log in Facebook user without an access token.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot log in Facebook user without an access token.' + ); $user = ParseUser::logInWithFacebook('asdf', null); } public function testLoginWithTwitter() { - $this->setExpectedException('Parse\ParseException', - 'Twitter auth is invalid for this user.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Twitter auth is invalid for this user.' + ); $user = ParseUser::logInWithTwitter('asdf', 'asdf', 'asdf', null, 'bogus', 'bogus'); } public function testLoginWithTwitterNoId() { - $this->setExpectedException('Parse\ParseException', - 'Cannot log in Twitter user without an id.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot log in Twitter user without an id.' + ); $user = ParseUser::logInWithTwitter(null, 'asdf', 'asdf', null, 'bogus', 'bogus'); } public function testLoginWithTwitterNoScreenName() { - $this->setExpectedException('Parse\ParseException', - 'Cannot log in Twitter user without Twitter screen name.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot log in Twitter user without Twitter screen name.' + ); $user = ParseUser::logInWithTwitter('asdf', null, 'asdf', null, 'bogus', 'bogus'); } public function testLoginWithTwitterNoConsumerKey() { - $this->setExpectedException('Parse\ParseException', - 'Cannot log in Twitter user without a consumer key.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot log in Twitter user without a consumer key.' + ); $user = ParseUser::logInWithTwitter('asdf', 'asdf', null, null, 'bogus', 'bogus'); } public function testLoginWithTwitterNoAuthToken() { - $this->setExpectedException('Parse\ParseException', - 'Cannot log in Twitter user without an auth token.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot log in Twitter user without an auth token.' + ); $user = ParseUser::logInWithTwitter('asdf', 'asdf', 'asdf', null, null, 'bogus'); } public function testLoginWithTwitterNoAuthTokenSecret() { - $this->setExpectedException('Parse\ParseException', - 'Cannot log in Twitter user without an auth token secret.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot log in Twitter user without an auth token secret.' + ); $user = ParseUser::logInWithTwitter('asdf', 'asdf', 'asdf', null, 'bogus', null); } @@ -152,8 +170,10 @@ public function testLoginWithAnonymous() public function testLinkWithFacebook() { - $this->setExpectedException('Parse\ParseException', - 'Facebook auth is invalid for this user.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Facebook auth is invalid for this user.' + ); $this->testUserSignUp(); $user = ParseUser::logIn('asdf', 'zxcv'); $user->linkWithFacebook('asdf', 'zxcv'); @@ -161,16 +181,20 @@ public function testLinkWithFacebook() public function testLinkWithFacebookUnsavedUser() { - $this->setExpectedException('Parse\ParseException', - 'Cannot link an unsaved user, use ParseUser::logInWithFacebook'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot link an unsaved user, use ParseUser::logInWithFacebook' + ); $user = new ParseUser(); $user->linkWithFacebook('asdf', 'zxcv'); } public function testLinkWithFacebookNoId() { - $this->setExpectedException('Parse\ParseException', - 'Cannot link Facebook user without an id.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot link Facebook user without an id.' + ); $this->testUserSignUp(); $user = ParseUser::logIn('asdf', 'zxcv'); $user->linkWithFacebook(null, 'zxcv'); @@ -178,8 +202,10 @@ public function testLinkWithFacebookNoId() public function testLinkWithFacebookNoAccessToken() { - $this->setExpectedException('Parse\ParseException', - 'Cannot link Facebook user without an access token.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot link Facebook user without an access token.' + ); $this->testUserSignUp(); $user = ParseUser::logIn('asdf', 'zxcv'); $user->linkWithFacebook('asdf', null); @@ -187,8 +213,10 @@ public function testLinkWithFacebookNoAccessToken() public function testLinkWithTwitter() { - $this->setExpectedException('Parse\ParseException', - 'Twitter auth is invalid for this user.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Twitter auth is invalid for this user.' + ); $this->testUserSignUp(); $user = ParseUser::logIn('asdf', 'zxcv'); $user->linkWithTwitter('qwer', 'asdf', 'zxcv', null, 'bogus', 'bogus'); @@ -196,16 +224,20 @@ public function testLinkWithTwitter() public function testLinkWithTwitterUnsavedUser() { - $this->setExpectedException('Parse\ParseException', - 'Cannot link an unsaved user, use ParseUser::logInWithTwitter'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot link an unsaved user, use ParseUser::logInWithTwitter' + ); $user = new ParseUser(); $user->linkWithTwitter('qwer', 'asdf', 'zxcv', null, 'bogus', 'bogus'); } public function testLinkWithTwitterNoId() { - $this->setExpectedException('Parse\ParseException', - 'Cannot link Twitter user without an id.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot link Twitter user without an id.' + ); $this->testUserSignUp(); $user = ParseUser::logIn('asdf', 'zxcv'); $user->linkWithTwitter(null, 'asdf', 'zxcv', null, 'bogus', 'bogus'); @@ -213,8 +245,10 @@ public function testLinkWithTwitterNoId() public function testLinkWithTwitterNoScreenName() { - $this->setExpectedException('Parse\ParseException', - 'Cannot link Twitter user without Twitter screen name.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot link Twitter user without Twitter screen name.' + ); $this->testUserSignUp(); $user = ParseUser::logIn('asdf', 'zxcv'); $user->linkWithTwitter('qwer', null, 'zxcv', null, 'bogus', 'bogus'); @@ -222,8 +256,10 @@ public function testLinkWithTwitterNoScreenName() public function testLinkWithTwitterNoConsumerKey() { - $this->setExpectedException('Parse\ParseException', - 'Cannot link Twitter user without a consumer key.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot link Twitter user without a consumer key.' + ); $this->testUserSignUp(); $user = ParseUser::logIn('asdf', 'zxcv'); $user->linkWithTwitter('qwer', 'asdf', null, null, 'bogus', 'bogus'); @@ -231,8 +267,10 @@ public function testLinkWithTwitterNoConsumerKey() public function testLinkWithTwitterNoAuthToken() { - $this->setExpectedException('Parse\ParseException', - 'Cannot link Twitter user without an auth token.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot link Twitter user without an auth token.' + ); $this->testUserSignUp(); $user = ParseUser::logIn('asdf', 'zxcv'); $user->linkWithTwitter('qwer', 'asdf', 'zxcv', null, null, 'bogus'); @@ -240,8 +278,10 @@ public function testLinkWithTwitterNoAuthToken() public function testLinkWithTwitterNoAuthTokenSecret() { - $this->setExpectedException('Parse\ParseException', - 'Cannot link Twitter user without an auth token secret.'); + $this->setExpectedException( + 'Parse\ParseException', + 'Cannot link Twitter user without an auth token secret.' + ); $this->testUserSignUp(); $user = ParseUser::logIn('asdf', 'zxcv'); $user->linkWithTwitter('qwer', 'asdf', 'zxcv', null, 'bogus', null); @@ -638,7 +678,6 @@ public function testAnonymousLogin() $user = ParseUser::loginWithAnonymous(); $this->assertEquals(ParseUser::getCurrentUser(), $user); ParseUser::logOut(); - } /** @@ -660,7 +699,7 @@ public function testGetCurrentUserByIdAndSession() $this->assertNull(ParseUser::getCurrentUser()); - $storage->set('user',[ + $storage->set('user', [ 'id' => $id, '_sessionToken' => $sessionToken, 'moredata' => 'moredata' @@ -678,6 +717,5 @@ public function testGetCurrentUserByIdAndSession() $this->assertEquals('moredata', $currentUser->get('moredata')); ParseUser::logOut(); - } } diff --git a/tests/Parse/RemoveOperationTest.php b/tests/Parse/RemoveOperationTest.php index 577fa6f1..e77ecdd8 100644 --- a/tests/Parse/RemoveOperationTest.php +++ b/tests/Parse/RemoveOperationTest.php @@ -8,7 +8,6 @@ namespace Parse\Test; - use Parse\Internal\AddOperation; use Parse\Internal\DeleteOperation; use Parse\Internal\RemoveOperation; @@ -22,10 +21,11 @@ class RemoveOperationTest extends \PHPUnit_Framework_TestCase */ public function testMissingArray() { - $this->setExpectedException('\Parse\ParseException', - 'RemoveOperation requires an array.'); + $this->setExpectedException( + '\Parse\ParseException', + 'RemoveOperation requires an array.' + ); new RemoveOperation('not an array'); - } /** @@ -57,7 +57,6 @@ public function testMergePrevious() 'key2' => 'value2', 'key1' => 'value1' ], $merged->getValue(), 'Value was not as expected'); - } /** @@ -65,13 +64,14 @@ public function testMergePrevious() */ public function testInvalidMerge() { - $this->setExpectedException('\Parse\ParseException', - 'Operation is invalid after previous operation.'); + $this->setExpectedException( + '\Parse\ParseException', + 'Operation is invalid after previous operation.' + ); $removeOp = new RemoveOperation([ 'key1' => 'value1' ]); $removeOp->_mergeWithPrevious(new AddOperation(['key'=>'value'])); - } /** @@ -83,6 +83,5 @@ public function testEmptyApply() 'key1' => 'value1' ]); $this->assertEmpty($removeOp->_apply([], null, null)); - } -} \ No newline at end of file +}