diff --git a/src/Parse/Internal/AddOperation.php b/src/Parse/Internal/AddOperation.php index 219f3832..ba4a6202 100755 --- a/src/Parse/Internal/AddOperation.php +++ b/src/Parse/Internal/AddOperation.php @@ -8,12 +8,14 @@ /** * Class AddOperation - FieldOperation for adding object(s) to array fields. * - * @author Fosco Marotto + * @author Fosco Marotto */ class AddOperation implements FieldOperation { /** - * @var - Array with objects to add. + * Array with objects to add. + * + * @var array */ private $objects; diff --git a/src/Parse/Internal/AddUniqueOperation.php b/src/Parse/Internal/AddUniqueOperation.php index 76733391..33af4a2e 100755 --- a/src/Parse/Internal/AddUniqueOperation.php +++ b/src/Parse/Internal/AddUniqueOperation.php @@ -8,12 +8,14 @@ /** * Class AddUniqueOperation - Operation to add unique objects to an array key. * - * @author Fosco Marotto + * @author Fosco Marotto */ class AddUniqueOperation implements FieldOperation { /** - * @var - Array containing objects to add. + * Array containing objects to add. + * + * @var array */ private $objects; diff --git a/src/Parse/Internal/DeleteOperation.php b/src/Parse/Internal/DeleteOperation.php index a703c80e..4bf14e97 100755 --- a/src/Parse/Internal/DeleteOperation.php +++ b/src/Parse/Internal/DeleteOperation.php @@ -5,7 +5,7 @@ /** * Class DeleteOperation - FieldOperation to remove a key from an object. * - * @author Fosco Marotto + * @author Fosco Marotto */ class DeleteOperation implements FieldOperation { diff --git a/src/Parse/Internal/Encodable.php b/src/Parse/Internal/Encodable.php index a965c966..5264aa97 100644 --- a/src/Parse/Internal/Encodable.php +++ b/src/Parse/Internal/Encodable.php @@ -6,7 +6,7 @@ * Class Encodable - Interface for Parse Classes which provide an encode * method. * - * @author Fosco Marotto + * @author Fosco Marotto */ interface Encodable { diff --git a/src/Parse/Internal/FieldOperation.php b/src/Parse/Internal/FieldOperation.php index 01535072..e70b542d 100755 --- a/src/Parse/Internal/FieldOperation.php +++ b/src/Parse/Internal/FieldOperation.php @@ -5,7 +5,7 @@ /** * Class FieldOperation - Interface for all Parse Field Operations. * - * @author Fosco Marotto + * @author Fosco Marotto */ interface FieldOperation extends Encodable { diff --git a/src/Parse/Internal/IncrementOperation.php b/src/Parse/Internal/IncrementOperation.php index 73726c2a..e2a0dfaf 100755 --- a/src/Parse/Internal/IncrementOperation.php +++ b/src/Parse/Internal/IncrementOperation.php @@ -7,12 +7,14 @@ /** * Class IncrementOperation - Operation to increment numeric object key. * - * @author Fosco Marotto + * @author Fosco Marotto */ class IncrementOperation implements FieldOperation { /** - * @var int - Amount to increment by. + * Amount to increment by. + * + * @var int */ private $value; diff --git a/src/Parse/Internal/ParseRelationOperation.php b/src/Parse/Internal/ParseRelationOperation.php index a3e18a0b..5fc47ac5 100644 --- a/src/Parse/Internal/ParseRelationOperation.php +++ b/src/Parse/Internal/ParseRelationOperation.php @@ -9,20 +9,28 @@ /** * ParseRelationOperation - A class that is used to manage ParseRelation changes such as object add or remove. * - * @author Mohamed Madbouli + * @author Mohamed Madbouli */ class ParseRelationOperation implements FieldOperation { /** - * @var string - The className of the target objects. + * The className of the target objects. + * + * @var string */ private $targetClassName; + /** - * @var array - Array of objects to add to this relation. + * Array of objects to add to this relation. + * + * @var array */ private $relationsToAdd = []; + /** - * @var array - Array of objects to remove from this relation. + * Array of objects to remove from this relation. + * + * @var array */ private $relationsToRemove = []; @@ -126,10 +134,13 @@ public function _apply($oldValue, $object, $key) return new ParseRelation($object, $key, $this->targetClassName); } elseif ($oldValue instanceof ParseRelation) { if ($this->targetClassName != null - && $oldValue->getTargetClass() !== $this->targetClassName) { - throw new \Exception('Related object object must be of class ' - .$this->targetClassName.', but '.$oldValue->getTargetClass() - .' was passed in.'); + && $oldValue->getTargetClass() !== $this->targetClassName + ) { + throw new \Exception( + 'Related object object must be of class ' + .$this->targetClassName.', but '.$oldValue->getTargetClass() + .' was passed in.' + ); } return $oldValue; @@ -155,34 +166,50 @@ public function _mergeWithPrevious($previous) } if ($previous instanceof ParseRelationOperation) { if ($previous->targetClassName != null - && $previous->targetClassName != $this->targetClassName + && $previous->targetClassName != $this->targetClassName ) { - throw new \Exception('Related object object must be of class ' - .$this->targetClassName.', but '.$previous->targetClassName - .' was passed in.'); + throw new \Exception( + 'Related object object must be of class ' + .$this->targetClassName.', but '.$previous->targetClassName + .' was passed in.' + ); } $newRelationToAdd = self::convertToOneDimensionalArray( - $this->relationsToAdd); + $this->relationsToAdd + ); $newRelationToRemove = self::convertToOneDimensionalArray( - $this->relationsToRemove); + $this->relationsToRemove + ); - $previous->addObjects($newRelationToAdd, - $previous->relationsToAdd); - $previous->removeObjects($newRelationToAdd, - $previous->relationsToRemove); + $previous->addObjects( + $newRelationToAdd, + $previous->relationsToAdd + ); + $previous->removeObjects( + $newRelationToAdd, + $previous->relationsToRemove + ); - $previous->removeObjects($newRelationToRemove, - $previous->relationsToAdd); - $previous->addObjects($newRelationToRemove, - $previous->relationsToRemove); + $previous->removeObjects( + $newRelationToRemove, + $previous->relationsToAdd + ); + $previous->addObjects( + $newRelationToRemove, + $previous->relationsToRemove + ); $newRelationToAdd = self::convertToOneDimensionalArray( - $previous->relationsToAdd); + $previous->relationsToAdd + ); $newRelationToRemove = self::convertToOneDimensionalArray( - $previous->relationsToRemove); + $previous->relationsToRemove + ); - return new ParseRelationOperation($newRelationToAdd, - $newRelationToRemove); + return new ParseRelationOperation( + $newRelationToAdd, + $newRelationToRemove + ); } throw new \Exception('Operation is invalid after previous operation.'); } diff --git a/src/Parse/Internal/RemoveOperation.php b/src/Parse/Internal/RemoveOperation.php index f38afab9..1a97b616 100644 --- a/src/Parse/Internal/RemoveOperation.php +++ b/src/Parse/Internal/RemoveOperation.php @@ -10,12 +10,14 @@ * Class RemoveOperation - FieldOperation for removing object(s) from array * fields. * - * @author Fosco Marotto + * @author Fosco Marotto */ class RemoveOperation implements FieldOperation { /** - * @var - Array with objects to remove. + * Array with objects to remove. + * + * @var array */ private $objects; @@ -109,7 +111,8 @@ public function _apply($oldValue, $obj, $key) if ($oldObject instanceof ParseObject) { if ($newObject instanceof ParseObject && !$oldObject->isDirty() - && $oldObject->getObjectId() == $newObject->getObjectId()) { + && $oldObject->getObjectId() == $newObject->getObjectId() + ) { // found the object, won't add it. } else { $newValue[] = $oldObject; diff --git a/src/Parse/Internal/SetOperation.php b/src/Parse/Internal/SetOperation.php index 1c6c7243..994242b3 100755 --- a/src/Parse/Internal/SetOperation.php +++ b/src/Parse/Internal/SetOperation.php @@ -7,17 +7,21 @@ /** * Class SetOperation - Operation to set a value for an object key. * - * @author Fosco Marotto + * @author Fosco Marotto */ class SetOperation implements FieldOperation { /** - * @var - Value to set for this operation. + * Value to set for this operation. + * + * @var mixed */ private $value; /** - * @var - If the value should be forced as object. + * If the value should be forced as object. + * + * @var bool */ private $isAssociativeArray; diff --git a/src/Parse/ParseACL.php b/src/Parse/ParseACL.php index dfe933b4..1cb691ed 100644 --- a/src/Parse/ParseACL.php +++ b/src/Parse/ParseACL.php @@ -12,36 +12,39 @@ * example, any user could read a particular object but only a particular set * of users could write to that object. * - * @author Mohamed Madbouli + * @author Mohamed Madbouli */ class ParseACL implements Encodable { - /* - * @ignore - */ const PUBLIC_KEY = '*'; + /** - * @var array - + * @var array */ private $permissionsById = []; + /** - * @var bool - + * @var bool */ private $shared = false; + /** - * @var ParseUser - + * @var ParseUser */ private static $lastCurrentUser = null; + /** - * @var ParseACL - + * @var ParseACL */ private static $defaultACLWithCurrentUser = null; + /** - * @var ParseACL - + * @var ParseACL */ private static $defaultACL = null; + /** - * @var bool - + * @var bool */ private static $defaultACLUsesCurrentUser = false; @@ -69,7 +72,6 @@ public static function createACLWithUser($user) * @throws \Exception * * @return ParseACL - * @ignore */ public static function _createACLFromJSON($data) { @@ -81,11 +83,13 @@ public static function _createACLFromJSON($data) foreach ($permissions as $accessType => $value) { if ($accessType !== 'read' && $accessType !== 'write') { throw new \Exception( - 'Tried to create an ACL with an invalid permission type.'); + 'Tried to create an ACL with an invalid permission type.' + ); } if (!is_bool($value)) { throw new \Exception( - 'Tried to create an ACL with an invalid permission value.'); + 'Tried to create an ACL with an invalid permission value.' + ); } $acl->setAccess($accessType, $id, $value); } @@ -98,7 +102,6 @@ public static function _createACLFromJSON($data) * Return if ParseACL shared or not. * * @return bool - * @ignore */ public function _isShared() { @@ -109,16 +112,12 @@ public function _isShared() * Set shared for ParseACL. * * @param bool $shared - * @ignore */ public function _setShared($shared) { $this->shared = $shared; } - /** - * @ignore - */ public function _encode() { if (empty($this->permissionsById)) { @@ -438,7 +437,8 @@ private static function validateRoleState($role) { if (!$role->getObjectId()) { throw new \Exception( - "Roles must be saved to the server before they can be used in an ACL."); + "Roles must be saved to the server before they can be used in an ACL." + ); } } @@ -538,7 +538,6 @@ public static function setDefaultACL($acl, $withAccessForCurrentUser) * Get the defaultACL. * * @return ParseACL - * @ignore */ public static function _getDefaultACL() { diff --git a/src/Parse/ParseAggregateException.php b/src/Parse/ParseAggregateException.php index 24b0748b..543468a0 100644 --- a/src/Parse/ParseAggregateException.php +++ b/src/Parse/ParseAggregateException.php @@ -5,7 +5,7 @@ /** * ParseAggregateException - Multiple error condition. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseAggregateException extends ParseException { diff --git a/src/Parse/ParseAnalytics.php b/src/Parse/ParseAnalytics.php index f6a8bff0..c48a3749 100644 --- a/src/Parse/ParseAnalytics.php +++ b/src/Parse/ParseAnalytics.php @@ -7,7 +7,7 @@ /** * ParseAnalytics - Handles sending app-open and custom analytics events. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseAnalytics { @@ -43,9 +43,11 @@ class ParseAnalytics public static function track($name, $dimensions = []) { $name = trim($name); + if (strlen($name) === 0) { throw new Exception('A name for the custom event must be provided.'); } + foreach ($dimensions as $key => $value) { if (!is_string($key) || !is_string($value)) { throw new Exception('Dimensions expected string keys and values.'); @@ -60,9 +62,6 @@ public static function track($name, $dimensions = []) ); } - /** - * @ignore - */ public static function _toSaveJSON($data) { return json_encode( diff --git a/src/Parse/ParseBytes.php b/src/Parse/ParseBytes.php index 4799fbd6..848284c7 100644 --- a/src/Parse/ParseBytes.php +++ b/src/Parse/ParseBytes.php @@ -5,12 +5,14 @@ /** * ParseBytes - Representation of a Byte array for storage on a Parse Object. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseBytes implements Internal\Encodable { /** - * @var - byte array + * Byte array. + * + * @var array */ private $byteArray; @@ -59,7 +61,6 @@ private function setByteArray(array $byteArray) * Encode to associative array representation. * * @return array - * @ignore */ public function _encode() { diff --git a/src/Parse/ParseClient.php b/src/Parse/ParseClient.php index 716bd2fd..4d31eb06 100755 --- a/src/Parse/ParseClient.php +++ b/src/Parse/ParseClient.php @@ -7,51 +7,61 @@ /** * ParseClient - Main class for Parse initialization and communication. * - * @author Fosco Marotto + * @author Fosco Marotto */ final class ParseClient { /** * Constant for the API Server Host Address. - * - * @ignore */ const HOST_NAME = 'https://api.parse.com'; /** - * @var - String for applicationId. + * The application id. + * + * @var string */ private static $applicationId; /** - * @var - String for REST API Key. + * The REST API Key. + * + * @var string */ private static $restKey; /** - * @var - String for Master Key. + * The Master Key. + * + * @var string */ private static $masterKey; /** - * @var - Boolean for Enable/Disable curl exceptions. + * Enable/Disable curl exceptions. + * + * @var bool */ private static $enableCurlExceptions; /** - * @var ParseStorageInterface Object for managing persistence + * The object for managing persistence. + * + * @var ParseStorageInterface */ private static $storage; /** - * @var - Boolean for enabling revocable sessions. + * Are revocable sessions enabled? + * + * @var bool */ private static $forceRevocableSession = false; /** * Constant for version string to include with requests. * - * @ignore + * @var string */ const VERSION_STRING = 'php1.1.0'; @@ -93,8 +103,6 @@ public static function initialize($app_id, $rest_key, $master_key, $enableCurlEx * @throws \Exception * * @return mixed Encoded results. - * - * @ignore */ public static function _encode($value, $allowParseObjects) { @@ -137,7 +145,6 @@ public static function _encode($value, $allowParseObjects) * @param mixed $data The value to decode * * @return mixed - * @ignore */ public static function _decode($data) { @@ -206,7 +213,6 @@ public static function _decode($data) * @param bool $allowParseObjects Allow nested objects. * * @return array Encoded results. - * @ignore */ public static function _encodeArray($value, $allowParseObjects) { @@ -230,11 +236,10 @@ public static function _encodeArray($value, $allowParseObjects) * @throws \Exception * * @return mixed Result from Parse API Call. - * @ignore */ public static function _request($method, $relativeUrl, $sessionToken = null, - $data = null, $useMasterKey = false) - { + $data = null, $useMasterKey = false + ) { if ($data === '[]') { $data = '{}'; } @@ -279,7 +284,8 @@ public static function _request($method, $relativeUrl, $sessionToken = null, $decoded = json_decode($response, true); if (isset($decoded['error'])) { - throw new ParseException($decoded['error'], + throw new ParseException( + $decoded['error'], isset($decoded['code']) ? $decoded['code'] : 0 ); } @@ -318,7 +324,6 @@ public static function getStorage() * use the first assigned storage object. * * @return null - * @ignore */ public static function _unsetStorage() { @@ -339,7 +344,6 @@ private static function assertParseInitialized() * @param $useMasterKey * * @return array - * @ignore */ public static function _getRequestHeaders($sessionToken, $useMasterKey) { diff --git a/src/Parse/ParseCloud.php b/src/Parse/ParseCloud.php index b0db92ba..0dfa8466 100644 --- a/src/Parse/ParseCloud.php +++ b/src/Parse/ParseCloud.php @@ -5,7 +5,7 @@ /** * ParseCloud - Facilitates calling Parse Cloud functions. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseCloud { diff --git a/src/Parse/ParseConfig.php b/src/Parse/ParseConfig.php index 43858032..7efd8628 100644 --- a/src/Parse/ParseConfig.php +++ b/src/Parse/ParseConfig.php @@ -5,7 +5,7 @@ /** * ParseConfig - For accessing Parse Config settings. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseConfig { @@ -25,8 +25,6 @@ public function get($key) if (isset($this->currentConfig[$key])) { return $this->currentConfig[$key]; } - - return; } public function escape($key) @@ -34,8 +32,6 @@ public function escape($key) if (isset($this->currentConfig[$key])) { return htmlentities($this->currentConfig[$key]); } - - return; } protected function setConfig($config) diff --git a/src/Parse/ParseException.php b/src/Parse/ParseException.php index b4e7a9a3..6e1fc138 100644 --- a/src/Parse/ParseException.php +++ b/src/Parse/ParseException.php @@ -5,7 +5,7 @@ /** * ParseException - Wrapper for \Exception class. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseException extends \Exception { @@ -17,8 +17,8 @@ class ParseException extends \Exception * @param \Exception $previous Previous Exception. */ public function __construct($message, $code = 0, - \Exception $previous = null) - { + \Exception $previous = null + ) { parent::__construct($message, $code, $previous); } } diff --git a/src/Parse/ParseFile.php b/src/Parse/ParseFile.php index 62485275..3543df8a 100755 --- a/src/Parse/ParseFile.php +++ b/src/Parse/ParseFile.php @@ -5,24 +5,35 @@ /** * ParseFile - Representation of a Parse File object. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseFile implements \Parse\Internal\Encodable { /** - * @var - Filename + * The filename. + * + * @var string */ private $name; + /** - * @var - URL of File data stored on Parse. + * The URL of file data stored on Parse. + * + * @var string */ private $url; + /** - * @var - Data + * The data. + * + * @var string */ private $data; + /** - * @var - Mime type + * The mime type. + * + * @var string */ private $mimeType; @@ -148,7 +159,6 @@ public static function createFromFile($path, $name, $mimeType = null) * @param $url * * @return ParseFile - * @ignore */ public static function _createFromServer($name, $url) { @@ -163,7 +173,6 @@ public static function _createFromServer($name, $url) * Encode to associative array representation. * * @return string - * @ignore */ public function _encode() { @@ -218,7 +227,8 @@ private function upload() $decoded = json_decode($response, true); if (isset($decoded['error'])) { - throw new ParseException($decoded['error'], + throw new ParseException( + $decoded['error'], isset($decoded['code']) ? $decoded['code'] : 0 ); } diff --git a/src/Parse/ParseGeoPoint.php b/src/Parse/ParseGeoPoint.php index 25941000..282e0570 100755 --- a/src/Parse/ParseGeoPoint.php +++ b/src/Parse/ParseGeoPoint.php @@ -5,16 +5,21 @@ /** * ParseGeoPoint - Representation of a Parse GeoPoint object. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseGeoPoint implements \Parse\Internal\Encodable { /** - * @var - Float value for latitude. + * The latitude. + * + * @var float */ private $latitude; + /** - * @var - Float value for longitude. + * The longitude. + * + * @var float */ private $longitude; @@ -86,7 +91,6 @@ public function setLongitude($lon) * Encode to associative array representation. * * @return array - * @ignore */ public function _encode() { diff --git a/src/Parse/ParseInstallation.php b/src/Parse/ParseInstallation.php index 70793c44..916e68f4 100644 --- a/src/Parse/ParseInstallation.php +++ b/src/Parse/ParseInstallation.php @@ -5,7 +5,7 @@ /** * ParseInstallation - Representation of an Installation stored on Parse. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseInstallation extends ParseObject { diff --git a/src/Parse/ParseMemoryStorage.php b/src/Parse/ParseMemoryStorage.php index fb0881c3..1dd096e7 100644 --- a/src/Parse/ParseMemoryStorage.php +++ b/src/Parse/ParseMemoryStorage.php @@ -6,7 +6,7 @@ * ParseMemoryStorage - Uses non-persisted memory for storage. * This is used by default if a PHP Session is not active. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseMemoryStorage implements ParseStorageInterface { diff --git a/src/Parse/ParseObject.php b/src/Parse/ParseObject.php index 3d4e7fdd..8def21ac 100755 --- a/src/Parse/ParseObject.php +++ b/src/Parse/ParseObject.php @@ -15,49 +15,77 @@ /** * ParseObject - Representation of an object stored on Parse. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseObject implements Encodable { /** - * @var array - Data as it exists on the server. + * Data as it exists on the server. + * + * @var array */ protected $serverData; + /** - * @var array - Set of unsaved operations. + * Set of unsaved operations. + * + * @var array */ protected $operationSet; + /** - * @var array - Estimated value of applying operationSet to serverData. + * Estimated value of applying operationSet to serverData. + * + * @var array */ private $estimatedData; + /** - * @var array - Determine if data available for a given key or not. + * Determine if data available for a given key or not. + * + * @var array */ private $dataAvailability; + /** - * @var - Class Name for data on Parse. + * Class name for data on Parse. + * + * @var string */ private $className; + /** - * @var string - Unique identifier on Parse. + * Unique identifier on Parse. + * + * @var string */ private $objectId; + /** - * @var \DateTime - Timestamp when object was created. + * Timestamp when object was created. + * + * @var \DateTime */ private $createdAt; + /** - * @var \DateTime - Timestamp when object was last updated. + * Timestamp when object was last updated. + * + * @var \DateTime */ private $updatedAt; + /** - * @var bool - Whether the object has been fully fetched from Parse. + * Whether the object has been fully fetched from Parse. + * + * @var bool */ private $hasBeenFetched; /** - * @var array - Holds the registered subclasses and Parse class names. + * Holds the registered subclasses and Parse class names. + * + * @var array */ private static $registeredSubclasses = []; @@ -74,8 +102,8 @@ class ParseObject implements Encodable * @throws Exception */ public function __construct($className = null, $objectId = null, - $isPointer = false) - { + $isPointer = false + ) { if (empty(self::$registeredSubclasses)) { throw new Exception( 'You must initialize the ParseClient using ParseClient::initialize '. @@ -125,7 +153,6 @@ private static function getSubclass() * @throws Exception * * @return null - * @ignore */ public function __set($key, $value) { @@ -146,7 +173,6 @@ public function __set($key, $value) * @param string $key Key to retrieve from the Object. * * @return mixed - * @ignore */ public function __get($key) { @@ -166,7 +192,8 @@ public function get($key) { if (!$this->_isDataAvailable($key)) { throw new \Exception( - 'ParseObject has no data for this key. Call fetch() to get the data.'); + 'ParseObject has no data for this key. Call fetch() to get the data.' + ); } if (isset($this->estimatedData[$key])) { return $this->estimatedData[$key]; @@ -217,7 +244,6 @@ public function isDirty() * @param $considerChildren * * @return bool - * @ignore */ protected function _isDirty($considerChildren) { @@ -229,13 +255,15 @@ protected function _isDirty($considerChildren) private function hasDirtyChildren() { $result = false; - self::traverse(true, $this->estimatedData, function ($object) use (&$result) { - if ($object instanceof ParseObject) { - if ($object->isDirty()) { - $result = true; + self::traverse( + true, $this->estimatedData, function ($object) use (&$result) { + if ($object instanceof ParseObject) { + if ($object->isDirty()) { + $result = true; + } } } - }); + ); return $result; } @@ -361,7 +389,6 @@ public function clear() * @param FieldOperation $operation Operation to perform. * * @return null - * @ignore */ public function _performOperation($key, FieldOperation $operation) { @@ -452,8 +479,8 @@ public function getUpdatedAt() * @return Object */ public static function create($className, $objectId = null, - $isPointer = false) - { + $isPointer = false + ) { if (isset(self::$registeredSubclasses[$className])) { return new self::$registeredSubclasses[$className]( $className, $objectId, $isPointer @@ -491,7 +518,6 @@ public function fetch($useMasterKey = false) * @param bool $completeData Fetch all data or not. * * @return null - * @ignore */ public function _mergeAfterFetch($result, $completeData = true) { @@ -516,7 +542,6 @@ public function _mergeAfterFetch($result, $completeData = true) * data will be fetched. * * @return null - * @ignore */ public function _mergeAfterFetchWithSelectedKeys($result, $selectedKeys) { @@ -783,7 +808,6 @@ public function delete($key) * Return a JSON encoded value of the object. * * @return string - * @ignore */ public function _encode() { @@ -859,10 +883,10 @@ public static function saveAll($list, $useMasterKey = false) } /** - * Save Object and unsaved children within. + * Save object and unsaved children within. * - * @param $target - * @param bool $useMasterKey Whether to use the Master Key. + * @param array $target + * @param bool $useMasterKey Whether to use the Master Key. * * @throws ParseException * @@ -929,12 +953,16 @@ private static function deepSave($target, $useMasterKey = false) if (count($requests) === 1) { $req = $requests[0]; - $result = ParseClient::_request($req['method'], - $req['path'], $sessionToken, json_encode($req['body']), $useMasterKey); + $result = ParseClient::_request( + $req['method'], + $req['path'], $sessionToken, json_encode($req['body']), $useMasterKey + ); $batch[0]->mergeAfterSave($result); } else { - $result = ParseClient::_request('POST', '/1/batch', $sessionToken, - json_encode(["requests" => $requests]), $useMasterKey); + $result = ParseClient::_request( + 'POST', '/1/batch', $sessionToken, + json_encode(["requests" => $requests]), $useMasterKey + ); $errorCollection = []; @@ -961,7 +989,7 @@ private static function deepSave($target, $useMasterKey = false) } if (count($errorCollection)) { throw new ParseAggregateException( - "Errors during batch save.", $errorCollection + "Errors during batch save.", $errorCollection ); } } @@ -976,23 +1004,25 @@ private static function deepSave($target, $useMasterKey = false) * @param array &$unsavedFiles Array to populate with files. */ private static function findUnsavedChildren($object, - &$unsavedChildren, &$unsavedFiles) - { - static::traverse(true, $object, function ($obj) use ( - &$unsavedChildren, - &$unsavedFiles - ) { - if ($obj instanceof ParseObject) { - if ($obj->_isDirty(false)) { - $unsavedChildren[] = $obj; - } - } elseif ($obj instanceof ParseFile) { - if (!$obj->getURL()) { - $unsavedFiles[] = $obj; + &$unsavedChildren, &$unsavedFiles + ) { + static::traverse( + true, $object, function ($obj) use ( + &$unsavedChildren, + &$unsavedFiles + ) { + if ($obj instanceof ParseObject) { + if ($obj->_isDirty(false)) { + $unsavedChildren[] = $obj; + } + } elseif ($obj instanceof ParseFile) { + if (!$obj->getURL()) { + $unsavedFiles[] = $obj; + } } - } - }); + } + ); } /** @@ -1006,8 +1036,8 @@ private static function findUnsavedChildren($object, * @return mixed The result of calling mapFunction on the root object. */ private static function traverse($deep, &$object, $mapFunction, - $seen = []) - { + $seen = [] + ) { if ($object instanceof ParseObject) { if (in_array($object, $seen, true)) { return; @@ -1056,20 +1086,22 @@ private function canBeSerialized() private static function canBeSerializedAsValue($object) { $result = true; - self::traverse(false, $object, function ($obj) use (&$result) { - // short circuit as soon as possible. - if ($result === false) { - return; - } - // cannot make a pointer to an unsaved object. - if ($obj instanceof ParseObject) { - if (!$obj->getObjectId()) { - $result = false; - + self::traverse( + false, $object, function ($obj) use (&$result) { + // short circuit as soon as possible. + if ($result === false) { return; } + // cannot make a pointer to an unsaved object. + if ($obj instanceof ParseObject) { + if (!$obj->getObjectId()) { + $result = false; + + return; + } + } } - }); + ); return $result; } @@ -1116,8 +1148,6 @@ public function getRelation($key) * @throws \Exception * * @return array - * - * @ignore */ public function _toPointer() { @@ -1187,8 +1217,6 @@ public static function registerSubclass() /** * Un-register a subclass. * Cannot be called on the base class ParseObject. - * - * @ignore */ public static function _unregisterSubclass() { diff --git a/src/Parse/ParsePush.php b/src/Parse/ParsePush.php index fd039ef2..c3b24f2b 100644 --- a/src/Parse/ParsePush.php +++ b/src/Parse/ParsePush.php @@ -5,7 +5,7 @@ /** * ParsePush - Handles sending push notifications with Parse. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParsePush { @@ -31,7 +31,8 @@ class ParsePush public static function send($data, $useMasterKey = false) { if (isset($data['expiration_time']) - && isset($data['expiration_interval'])) { + && isset($data['expiration_interval']) + ) { throw new \Exception( 'Both expiration_time and expiration_interval can\'t be set.' ); diff --git a/src/Parse/ParseQuery.php b/src/Parse/ParseQuery.php index 7ee96b2e..2ca99663 100755 --- a/src/Parse/ParseQuery.php +++ b/src/Parse/ParseQuery.php @@ -5,40 +5,63 @@ /** * ParseQuery - Handles querying data from Parse. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseQuery { /** - * @var - Class Name for data stored on Parse. + * Class name for data stored on Parse. + * + * @var string */ private $className; + /** - * @var array - Where constraints. + * Where constraints. + * + * @var array */ private $where = []; + /** - * @var array - Order By keys. + * Order By keys. + * + * @var array */ private $orderBy = []; + /** - * @var array - Include nested objects. + * Include nested objects. + * + * @var array */ private $includes = []; + /** - * @var array - Include certain keys only. + * Include certain keys only. + * + * @var array */ private $selectedKeys = []; + /** - * @var int - Skip from the beginning of the search results. + * Skip from the beginning of the search results. + * + * @var int */ private $skip = 0; + /** - * @var - Determines if the query is a count query or a results query. + * Determines if the query is a count query or a results query. + * + * @var int */ private $count; + /** - * @var int - Limit of results, defaults to 100 when not explicitly set. + * Limit of results, defaults to 100 when not explicitly set. + * + * @var int */ private $limit = -1; @@ -213,7 +236,6 @@ public function startsWith($key, $value) * Returns an associative array of the query constraints. * * @return array - * @ignore */ public function _getOptions() { @@ -290,9 +312,11 @@ public function count($useMasterKey = false) $this->limit = 0; $this->count = 1; $queryString = $this->buildQueryString($this->_getOptions()); - $result = ParseClient::_request('GET', - '/1/classes/'.$this->className. - '?'.$queryString, null, null, $useMasterKey); + $result = ParseClient::_request( + 'GET', + '/1/classes/'.$this->className. + '?'.$queryString, null, null, $useMasterKey + ); return $result['count']; } @@ -311,9 +335,11 @@ public function find($useMasterKey = false) $sessionToken = ParseUser::getCurrentUser()->getSessionToken(); } $queryString = $this->buildQueryString($this->_getOptions()); - $result = ParseClient::_request('GET', - '/1/classes/'.$this->className. - '?'.$queryString, $sessionToken, null, $useMasterKey); + $result = ParseClient::_request( + 'GET', + '/1/classes/'.$this->className. + '?'.$queryString, $sessionToken, null, $useMasterKey + ); $output = []; foreach ($result['results'] as $row) { $obj = ParseObject::create($this->className, $row['objectId']); @@ -412,9 +438,11 @@ public function descending($key) public function addDescending($key) { if (is_array($key)) { - $key = array_map(function ($element) { - return '-'.$element; - }, $key); + $key = array_map( + function ($element) { + return '-'.$element; + }, $key + ); $this->orderBy = array_merge($this->orderBy, $key); } else { $this->orderBy[] = "-".$key; @@ -508,8 +536,10 @@ public function withinKilometers($key, $point, $maxDistance) */ public function withinGeoBox($key, $southwest, $northeast) { - $this->addCondition($key, '$within', - ['$box' => [$southwest, $northeast]]); + $this->addCondition( + $key, '$within', + ['$box' => [$southwest, $northeast]] + ); return $this; } @@ -546,7 +576,8 @@ public function each($callback, $useMasterKey = false, $batchSize = 100) { if ($this->orderBy || $this->skip || ($this->limit >= 0)) { throw new \Exception( - "Cannot iterate on a query with sort, skip, or limit."); + "Cannot iterate on a query with sort, skip, or limit." + ); } $query = new ParseQuery($this->className); $query->where = $this->where; @@ -639,8 +670,10 @@ public function matchesKeyInQuery($key, $queryKey, $query) { $queryParam = $query->_getOptions(); $queryParam["className"] = $query->className; - $this->addCondition($key, '$select', - ['key' => $queryKey, 'query' => $queryParam]); + $this->addCondition( + $key, '$select', + ['key' => $queryKey, 'query' => $queryParam] + ); return $this; } @@ -661,8 +694,10 @@ public function doesNotMatchKeyInQuery($key, $queryKey, $query) { $queryParam = $query->_getOptions(); $queryParam["className"] = $query->className; - $this->addCondition($key, '$dontSelect', - ['key' => $queryKey, 'query' => $queryParam]); + $this->addCondition( + $key, '$dontSelect', + ['key' => $queryKey, 'query' => $queryParam] + ); return $this; } @@ -701,7 +736,6 @@ public static function orQueries($queryObjects) * @param array $queries The list of queries to OR. * * @return ParseQuery Returns the query, so you can chain this call. - * @ignore */ private function _or($queries) { diff --git a/src/Parse/ParseRelation.php b/src/Parse/ParseRelation.php index 8fcd86ec..2fa991ca 100644 --- a/src/Parse/ParseRelation.php +++ b/src/Parse/ParseRelation.php @@ -8,20 +8,28 @@ * ParseRelation - A class that is used to access all of the children of a many-to-many relationship. Each instance * of ParseRelation is associated with a particular parent object and key. * - * @author Mohamed Madbouli + * @author Mohamed Madbouli */ class ParseRelation { /** - * @var ParseObject - The parent of this relation. + * The parent of this relation. + * + * @var ParseObject */ private $parent; + /** - * @var string - The key of the relation in the parent object. + * The key of the relation in the parent object. + * + * @var string */ private $key; + /** - * @var string - The className of the target objects. + * The className of the target objects. + * + * @var string */ private $targetClassName; diff --git a/src/Parse/ParseRole.php b/src/Parse/ParseRole.php index 50b5db29..78d82bdb 100644 --- a/src/Parse/ParseRole.php +++ b/src/Parse/ParseRole.php @@ -5,7 +5,7 @@ /** * ParseRole - Representation of an access Role. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseRole extends ParseObject { diff --git a/src/Parse/ParseSession.php b/src/Parse/ParseSession.php index ef938dee..31904481 100644 --- a/src/Parse/ParseSession.php +++ b/src/Parse/ParseSession.php @@ -5,7 +5,7 @@ /** * ParseSession - Representation of an expiring user session. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseSession extends ParseObject { diff --git a/src/Parse/ParseSessionStorage.php b/src/Parse/ParseSessionStorage.php index b6450a66..36e1255a 100644 --- a/src/Parse/ParseSessionStorage.php +++ b/src/Parse/ParseSessionStorage.php @@ -5,12 +5,14 @@ /** * ParseSessionStorage - Uses PHP session support for persistent storage. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseSessionStorage implements ParseStorageInterface { /** - * @var string Parse will store its values in a specific key. + * Parse will store its values in a specific key. + * + * @var string */ private $storageKey = 'parseData'; diff --git a/src/Parse/ParseStorageInterface.php b/src/Parse/ParseStorageInterface.php index 533dde7a..1578762a 100644 --- a/src/Parse/ParseStorageInterface.php +++ b/src/Parse/ParseStorageInterface.php @@ -5,7 +5,7 @@ /** * ParseStorageInterface - Specifies an interface for implementing persistence. * - * @author Fosco Marotto + * @author Fosco Marotto */ interface ParseStorageInterface { diff --git a/src/Parse/ParseUser.php b/src/Parse/ParseUser.php index 27e89439..6131a7b3 100644 --- a/src/Parse/ParseUser.php +++ b/src/Parse/ParseUser.php @@ -5,19 +5,23 @@ /** * ParseUser - Representation of a user object stored on Parse. * - * @author Fosco Marotto + * @author Fosco Marotto */ class ParseUser extends ParseObject { public static $parseClassName = "_User"; /** - * @var ParseUser The currently logged-in user. + * The currently logged-in user. + * + * @var ParseUser */ private static $currentUser = null; /** - * @var string The sessionToken for an authenticated user. + * The sessionToken for an authenticated user. + * + * @var string */ protected $_sessionToken = null; @@ -309,9 +313,6 @@ public static function requestPasswordReset($email) ParseClient::_request('POST', '/1/requestPasswordReset', null, $json); } - /** - * @ignore - */ public static function _clearCurrentUserVariable() { static::$currentUser = null; diff --git a/tests/IncrementTest.php b/tests/IncrementTest.php index bc33070d..7a02de6b 100644 --- a/tests/IncrementTest.php +++ b/tests/IncrementTest.php @@ -175,7 +175,8 @@ public function testIncrementEmptyFieldOnFreshObject() $query = new ParseQuery('TestObject'); $query->equalTo('objectId', $obj->getObjectId()); $result = $query->first(); - $this->assertEquals($result->get('yo'), 1, + $this->assertEquals( + $result->get('yo'), 1, 'Error in increment on empty field of fresh object' ); } @@ -194,7 +195,8 @@ public function testIncrementEmptyField() $queryAgain = new ParseQuery('TestObject'); $queryAgain->equalTo('objectId', $objAgain->getObjectId()); $objectAgainTwo = $queryAgain->first(); - $this->assertEquals($objectAgainTwo->get('yo'), 2, + $this->assertEquals( + $objectAgainTwo->get('yo'), 2, 'Error in increment on empty field' ); } @@ -209,7 +211,8 @@ public function testIncrementEmptyFieldAndTypeConflict() $obj->set('randomkey', 'bar'); $obj->save(); $objAgain->increment('randomkey'); - $this->setExpectedException('Parse\ParseException', + $this->setExpectedException( + 'Parse\ParseException', "invalid type for key" ); $objAgain->save(); @@ -225,7 +228,8 @@ public function testIncrementEmptyFieldSolidifiesType() $objAgain->set('randomkeyagain', 'bar'); $obj->increment('randomkeyagain'); $obj->save(); - $this->setExpectedException('Parse\ParseException', + $this->setExpectedException( + 'Parse\ParseException', 'invalid type for key randomkeyagain, '. 'expected number, but got string' ); diff --git a/tests/ParseFileTest.php b/tests/ParseFileTest.php index 281b9d4a..d8b26d25 100644 --- a/tests/ParseFileTest.php +++ b/tests/ParseFileTest.php @@ -23,8 +23,10 @@ public function testParseFileFactories() { $file = ParseFile::_createFromServer("hi.txt", "http://"); $file2 = ParseFile::createFromData("hello", "hi.txt"); - $file3 = ParseFile::createFromFile("ParseFileTest.php", - "file.php"); + $file3 = ParseFile::createFromFile( + "ParseFileTest.php", + "file.php" + ); $this->assertEquals("http://", $file->getURL()); $this->assertEquals("hi.txt", $file->getName()); $this->assertEquals("hello", $file2->getData()); diff --git a/tests/ParseObjectTest.php b/tests/ParseObjectTest.php index aec9abfe..73e764f4 100644 --- a/tests/ParseObjectTest.php +++ b/tests/ParseObjectTest.php @@ -32,8 +32,10 @@ public function testUpdate() $obj->save(); $obj->set('foo', 'changed'); $obj->save(); - $this->assertEquals($obj->foo, 'changed', - 'Update should have succeeded'); + $this->assertEquals( + $obj->foo, 'changed', + 'Update should have succeeded' + ); } public function testSaveCycle() @@ -59,10 +61,14 @@ public function testReturnedObjectIsAParseObject() $query = new ParseQuery('TestObject'); $returnedObject = $query->get($obj->getObjectId()); - $this->assertTrue($returnedObject instanceof ParseObject, - 'Returned object was not a ParseObject'); - $this->assertEquals('bar', $returnedObject->foo, - 'Value of foo was not saved.'); + $this->assertTrue( + $returnedObject instanceof ParseObject, + 'Returned object was not a ParseObject' + ); + $this->assertEquals( + 'bar', $returnedObject->foo, + 'Value of foo was not saved.' + ); } public function testFetch() @@ -277,8 +283,10 @@ public function testInvalidKeyName() { $obj = ParseObject::create("TestItem"); $obj->set('foo^bar', 'baz'); - $this->setExpectedException('Parse\ParseException', - 'invalid field name'); + $this->setExpectedException( + 'Parse\ParseException', + 'invalid field name' + ); $obj->save(); } @@ -733,8 +741,10 @@ public function testEmptyArray() $obj->save(); $query = new ParseQuery('TestObject'); $returnedObject = $query->get($obj->getObjectId()); - $this->assertTrue(is_array($returnedObject->get('baz')), - 'Value was not stored as an array.'); + $this->assertTrue( + is_array($returnedObject->get('baz')), + 'Value was not stored as an array.' + ); $this->assertEquals(0, count($returnedObject->get('baz'))); } @@ -883,10 +893,12 @@ public function testEmptyObjectsAndArrays() is_object($saveOpAssoc->_encode()), "Value should be object." ); $obj->save(); - $obj->setAssociativeArray('obj', [ + $obj->setAssociativeArray( + 'obj', [ 'foo' => 'bar', 'baz' => 'yay', - ]); + ] + ); $obj->save(); $query = new ParseQuery('TestObject'); $objAgain = $query->get($obj->getObjectId()); diff --git a/tests/ParsePushTest.php b/tests/ParsePushTest.php index 111f1c0e..6c5769bc 100644 --- a/tests/ParsePushTest.php +++ b/tests/ParsePushTest.php @@ -19,29 +19,35 @@ public function tearDown() public function testBasicPush() { - ParsePush::send([ + ParsePush::send( + [ 'channels' => [''], 'data' => ['alert' => 'sample message'], - ]); + ] + ); } public function testPushToQuery() { $query = ParseInstallation::query(); $query->equalTo('key', 'value'); - ParsePush::send([ + ParsePush::send( + [ 'data' => ['alert' => 'iPhone 5 is out!'], 'where' => $query, - ]); + ] + ); } public function testPushDates() { - ParsePush::send([ + ParsePush::send( + [ 'data' => ['alert' => 'iPhone 5 is out!'], 'push_time' => new DateTime(), 'expiration_time' => new DateTime(), 'channels' => [], - ]); + ] + ); } } diff --git a/tests/ParseQueryTest.php b/tests/ParseQueryTest.php index 0136b4af..3673b066 100644 --- a/tests/ParseQueryTest.php +++ b/tests/ParseQueryTest.php @@ -42,12 +42,14 @@ public function saveObjects($numberOfObjects, $callback) public function provideTestObjects($numberOfObjects) { - $this->saveObjects($numberOfObjects, function ($i) { - $obj = ParseObject::create('TestObject'); - $obj->set('foo', 'bar'.$i); + $this->saveObjects( + $numberOfObjects, function ($i) { + $obj = ParseObject::create('TestObject'); + $obj->set('foo', 'bar'.$i); - return $obj; - }); + return $obj; + } + ); } public function testBasicQuery() @@ -62,10 +64,14 @@ public function testBasicQuery() $query = new ParseQuery("TestObject"); $query->equalTo("foo", "baz"); $results = $query->find(); - $this->assertEquals(1, count($results), - 'Did not find object.'); - $this->assertEquals("baz", $results[0]->get("foo"), - 'Did not return the correct object.'); + $this->assertEquals( + 1, count($results), + 'Did not find object.' + ); + $this->assertEquals( + "baz", $results[0]->get("foo"), + 'Did not return the correct object.' + ); } public function testQueryWithLimit() @@ -80,8 +86,10 @@ public function testQueryWithLimit() $query = new ParseQuery("TestObject"); $query->limit(1); $results = $query->find(); - $this->assertEquals(1, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 1, count($results), + 'Did not return correct number of objects.' + ); } public function testEqualTo() @@ -101,8 +109,10 @@ public function testNotEqualTo() $query = new ParseQuery('TestObject'); $query->notEqualTo('foo', 'bar9'); $results = $query->find(); - $this->assertEquals(count($results), 9, - 'Did not find 9 objects, found '.count($results)); + $this->assertEquals( + count($results), 9, + 'Did not find 9 objects, found '.count($results) + ); } public function testLessThan() @@ -111,10 +121,14 @@ public function testLessThan() $query = new ParseQuery('TestObject'); $query->lessThan('foo', 'bar1'); $results = $query->find(); - $this->assertEquals(count($results), 1, - 'LessThan function did not return correct number of objects.'); - $this->assertEquals($results[0]->get('foo'), 'bar0', - 'LessThan function did not return the correct object'); + $this->assertEquals( + count($results), 1, + 'LessThan function did not return correct number of objects.' + ); + $this->assertEquals( + $results[0]->get('foo'), 'bar0', + 'LessThan function did not return the correct object' + ); } public function testLessThanOrEqualTo() @@ -123,10 +137,14 @@ public function testLessThanOrEqualTo() $query = new ParseQuery('TestObject'); $query->lessThanOrEqualTo('foo', 'bar0'); $results = $query->find(); - $this->assertEquals(count($results), 1, - 'LessThanOrEqualTo function did not return correct number of objects.'); - $this->assertEquals($results[0]->get('foo'), 'bar0', - 'LessThanOrEqualTo function did not return the correct object.'); + $this->assertEquals( + count($results), 1, + 'LessThanOrEqualTo function did not return correct number of objects.' + ); + $this->assertEquals( + $results[0]->get('foo'), 'bar0', + 'LessThanOrEqualTo function did not return the correct object.' + ); } public function testStartsWithSingle() @@ -135,10 +153,14 @@ public function testStartsWithSingle() $query = new ParseQuery('TestObject'); $query->startsWith('foo', 'bar0'); $results = $query->find(); - $this->assertEquals(count($results), 1, - 'StartsWith function did not return correct number of objects.'); - $this->assertEquals($results[0]->get('foo'), 'bar0', - 'StartsWith function did not return the correct object.'); + $this->assertEquals( + count($results), 1, + 'StartsWith function did not return correct number of objects.' + ); + $this->assertEquals( + $results[0]->get('foo'), 'bar0', + 'StartsWith function did not return the correct object.' + ); } public function testStartsWithMultiple() @@ -147,8 +169,10 @@ public function testStartsWithMultiple() $query = new ParseQuery('TestObject'); $query->startsWith('foo', 'bar'); $results = $query->find(); - $this->assertEquals(count($results), 10, - 'StartsWith function did not return correct number of objects.'); + $this->assertEquals( + count($results), 10, + 'StartsWith function did not return correct number of objects.' + ); } public function testStartsWithMiddle() @@ -157,8 +181,10 @@ public function testStartsWithMiddle() $query = new ParseQuery('TestObject'); $query->startsWith('foo', 'ar'); $results = $query->find(); - $this->assertEquals(count($results), 0, - 'StartsWith function did not return correct number of objects.'); + $this->assertEquals( + count($results), 0, + 'StartsWith function did not return correct number of objects.' + ); } public function testStartsWithRegexDelimiters() @@ -169,12 +195,16 @@ public function testStartsWithRegexDelimiters() $query = new ParseQuery('TestObject'); $query->startsWith('foo', 'foob\E'); $results = $query->find(); - $this->assertEquals(count($results), 1, - 'StartsWith function did not return correct number of objects.'); + $this->assertEquals( + count($results), 1, + 'StartsWith function did not return correct number of objects.' + ); $query->startsWith('foo', 'foobE'); $results = $query->find(); - $this->assertEquals(count($results), 0, - 'StartsWith function did not return correct number of objects.'); + $this->assertEquals( + count($results), 0, + 'StartsWith function did not return correct number of objects.' + ); } public function testStartsWithRegexDot() @@ -185,16 +215,22 @@ public function testStartsWithRegexDot() $query = new ParseQuery('TestObject'); $query->startsWith('foo', 'foo(.)*'); $results = $query->find(); - $this->assertEquals(count($results), 0, - 'StartsWith function did not return correct number of objects.'); + $this->assertEquals( + count($results), 0, + 'StartsWith function did not return correct number of objects.' + ); $query->startsWith('foo', 'foo.*'); $results = $query->find(); - $this->assertEquals(count($results), 0, - 'StartsWith function did not return correct number of objects.'); + $this->assertEquals( + count($results), 0, + 'StartsWith function did not return correct number of objects.' + ); $query->startsWith('foo', 'foo'); $results = $query->find(); - $this->assertEquals(count($results), 1, - 'StartsWith function did not return correct number of objects.'); + $this->assertEquals( + count($results), 1, + 'StartsWith function did not return correct number of objects.' + ); } public function testStartsWithRegexSlash() @@ -205,12 +241,16 @@ public function testStartsWithRegexSlash() $query = new ParseQuery('TestObject'); $query->startsWith('foo', 'foo/bar'); $results = $query->find(); - $this->assertEquals(count($results), 0, - 'StartsWith function did not return correct number of objects.'); + $this->assertEquals( + count($results), 0, + 'StartsWith function did not return correct number of objects.' + ); $query->startsWith('foo', 'foobar'); $results = $query->find(); - $this->assertEquals(count($results), 1, - 'StartsWith function did not return correct number of objects.'); + $this->assertEquals( + count($results), 1, + 'StartsWith function did not return correct number of objects.' + ); } public function testStartsWithRegexQuestionmark() @@ -221,16 +261,22 @@ public function testStartsWithRegexQuestionmark() $query = new ParseQuery('TestObject'); $query->startsWith('foo', 'foox?bar'); $results = $query->find(); - $this->assertEquals(count($results), 0, - 'StartsWith function did not return correct number of objects.'); + $this->assertEquals( + count($results), 0, + 'StartsWith function did not return correct number of objects.' + ); $query->startsWith('foo', 'foo(x)?bar'); $results = $query->find(); - $this->assertEquals(count($results), 0, - 'StartsWith function did not return correct number of objects.'); + $this->assertEquals( + count($results), 0, + 'StartsWith function did not return correct number of objects.' + ); $query->startsWith('foo', 'foobar'); $results = $query->find(); - $this->assertEquals(count($results), 1, - 'StartsWith function did not return correct number of objects.'); + $this->assertEquals( + count($results), 1, + 'StartsWith function did not return correct number of objects.' + ); } public function testGreaterThan() @@ -239,10 +285,14 @@ public function testGreaterThan() $query = new ParseQuery('TestObject'); $query->greaterThan('foo', 'bar8'); $results = $query->find(); - $this->assertEquals(count($results), 1, - 'GreaterThan function did not return correct number of objects.'); - $this->assertEquals($results[0]->get('foo'), 'bar9', - 'GreaterThan function did not return the correct object.'); + $this->assertEquals( + count($results), 1, + 'GreaterThan function did not return correct number of objects.' + ); + $this->assertEquals( + $results[0]->get('foo'), 'bar9', + 'GreaterThan function did not return the correct object.' + ); } public function testGreaterThanOrEqualTo() @@ -251,10 +301,14 @@ public function testGreaterThanOrEqualTo() $query = new ParseQuery('TestObject'); $query->greaterThanOrEqualTo('foo', 'bar9'); $results = $query->find(); - $this->assertEquals(count($results), 1, - 'GreaterThanOrEqualTo function did not return correct number of objects.'); - $this->assertEquals($results[0]->get('foo'), 'bar9', - 'GreaterThanOrEqualTo function did not return the correct object.'); + $this->assertEquals( + count($results), 1, + 'GreaterThanOrEqualTo function did not return correct number of objects.' + ); + $this->assertEquals( + $results[0]->get('foo'), 'bar9', + 'GreaterThanOrEqualTo function did not return the correct object.' + ); } public function testLessThanOrEqualGreaterThanOrEqual() @@ -264,8 +318,10 @@ public function testLessThanOrEqualGreaterThanOrEqual() $query->lessThanOrEqualTo('foo', 'bar4'); $query->greaterThanOrEqualTo('foo', 'bar2'); $results = $query->find(); - $this->assertEquals(3, count($results), - 'LessThanGreaterThan did not return correct number of objects.'); + $this->assertEquals( + 3, count($results), + 'LessThanGreaterThan did not return correct number of objects.' + ); } public function testLessThanGreaterThan() @@ -275,46 +331,60 @@ public function testLessThanGreaterThan() $query->lessThan('foo', 'bar5'); $query->greaterThan('foo', 'bar3'); $results = $query->find(); - $this->assertEquals(1, count($results), - 'LessThanGreaterThan did not return correct number of objects.'); - $this->assertEquals('bar4', $results[0]->get('foo'), - 'LessThanGreaterThan did not return the correct object.'); + $this->assertEquals( + 1, count($results), + 'LessThanGreaterThan did not return correct number of objects.' + ); + $this->assertEquals( + 'bar4', $results[0]->get('foo'), + 'LessThanGreaterThan did not return the correct object.' + ); } public function testObjectIdEqualTo() { ParseTestHelper::clearClass("BoxedNumber"); $boxedNumberArray = []; - $this->saveObjects(5, function ($i) use (&$boxedNumberArray) { - $boxedNumber = new ParseObject("BoxedNumber"); - $boxedNumber->set("number", $i); - $boxedNumberArray[] = $boxedNumber; + $this->saveObjects( + 5, function ($i) use (&$boxedNumberArray) { + $boxedNumber = new ParseObject("BoxedNumber"); + $boxedNumber->set("number", $i); + $boxedNumberArray[] = $boxedNumber; - return $boxedNumber; - }); + return $boxedNumber; + } + ); $query = new ParseQuery("BoxedNumber"); $query->equalTo("objectId", $boxedNumberArray[4]->getObjectId()); $results = $query->find(); - $this->assertEquals(1, count($results), - 'Did not find object.'); - $this->assertEquals(4, $results[0]->get("number"), - 'Did not return the correct object.'); + $this->assertEquals( + 1, count($results), + 'Did not find object.' + ); + $this->assertEquals( + 4, $results[0]->get("number"), + 'Did not return the correct object.' + ); } public function testFindNoElements() { ParseTestHelper::clearClass("BoxedNumber"); - $this->saveObjects(5, function ($i) { - $boxedNumber = new ParseObject("BoxedNumber"); - $boxedNumber->set("number", $i); + $this->saveObjects( + 5, function ($i) { + $boxedNumber = new ParseObject("BoxedNumber"); + $boxedNumber->set("number", $i); - return $boxedNumber; - }); + return $boxedNumber; + } + ); $query = new ParseQuery("BoxedNumber"); $query->equalTo("number", 17); $results = $query->find(); - $this->assertEquals(0, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 0, count($results), + 'Did not return correct number of objects.' + ); } public function testFindWithError() @@ -332,10 +402,14 @@ public function testGet() $testObj->save(); $query = new ParseQuery("TestObject"); $result = $query->get($testObj->getObjectId()); - $this->assertEquals($testObj->getObjectId(), $result->getObjectId(), - 'Did not return the correct object.'); - $this->assertEquals("bar", $result->get("foo"), - 'Did not return the correct object.'); + $this->assertEquals( + $testObj->getObjectId(), $result->getObjectId(), + 'Did not return the correct object.' + ); + $this->assertEquals( + "bar", $result->get("foo"), + 'Did not return the correct object.' + ); } public function testGetError() @@ -366,8 +440,10 @@ public function testFirst() $query = new ParseQuery("TestObject"); $query->equalTo("foo", "bar"); $result = $query->first(); - $this->assertEquals("bar", $result->get("foo"), - 'Did not return the correct object.'); + $this->assertEquals( + "bar", $result->get("foo"), + 'Did not return the correct object.' + ); } public function testFirstWithError() @@ -386,23 +462,29 @@ public function testFirstNoResult() $query = new ParseQuery("TestObject"); $query->equalTo("foo", "baz"); $result = $query->first(); - $this->assertTrue(empty($result), - 'Did not return correct number of objects.'); + $this->assertTrue( + empty($result), + 'Did not return correct number of objects.' + ); } public function testFirstWithTwoResults() { - $this->saveObjects(2, function ($i) { - $testObject = ParseObject::create("TestObject"); - $testObject->set("foo", "bar"); + $this->saveObjects( + 2, function ($i) { + $testObject = ParseObject::create("TestObject"); + $testObject->set("foo", "bar"); - return $testObject; - }); + return $testObject; + } + ); $query = new ParseQuery("TestObject"); $query->equalTo("foo", "bar"); $result = $query->first(); - $this->assertEquals("bar", $result->get("foo"), - 'Did not return the correct object.'); + $this->assertEquals( + "bar", $result->get("foo"), + 'Did not return the correct object.' + ); } public function testNotEqualToObject() @@ -410,71 +492,95 @@ public function testNotEqualToObject() ParseTestHelper::clearClass("Container"); ParseTestHelper::clearClass("Item"); $items = []; - $this->saveObjects(2, function ($i) use (&$items) { - $items[] = ParseObject::create("Item"); + $this->saveObjects( + 2, function ($i) use (&$items) { + $items[] = ParseObject::create("Item"); - return $items[$i]; - }); - $this->saveObjects(2, function ($i) use ($items) { - $container = ParseObject::create("Container"); - $container->set("item", $items[$i]); + return $items[$i]; + } + ); + $this->saveObjects( + 2, function ($i) use ($items) { + $container = ParseObject::create("Container"); + $container->set("item", $items[$i]); - return $container; - }); + return $container; + } + ); $query = new ParseQuery("Container"); $query->notEqualTo("item", $items[0]); $result = $query->find(); - $this->assertEquals(1, count($result), - 'Did not return the correct object.'); + $this->assertEquals( + 1, count($result), + 'Did not return the correct object.' + ); } public function testSkip() { - $this->saveObjects(2, function ($i) { - return ParseObject::create("TestObject"); - }); + $this->saveObjects( + 2, function ($i) { + return ParseObject::create("TestObject"); + } + ); $query = new ParseQuery("TestObject"); $query->skip(1); $result = $query->find(); - $this->assertEquals(1, count($result), - 'Did not return the correct object.'); + $this->assertEquals( + 1, count($result), + 'Did not return the correct object.' + ); $query->skip(3); $result = $query->find(); - $this->assertEquals(0, count($result), - 'Did not return the correct object.'); + $this->assertEquals( + 0, count($result), + 'Did not return the correct object.' + ); } public function testSkipDoesNotAffectCount() { - $this->saveObjects(2, function ($i) { - return ParseObject::create("TestObject"); - }); + $this->saveObjects( + 2, function ($i) { + return ParseObject::create("TestObject"); + } + ); $query = new ParseQuery("TestObject"); $count = $query->count(); - $this->assertEquals(2, $count, - 'Did not return correct number of objects.'); + $this->assertEquals( + 2, $count, + 'Did not return correct number of objects.' + ); $query->skip(1); - $this->assertEquals(2, $count, - 'Did not return correct number of objects.'); + $this->assertEquals( + 2, $count, + 'Did not return correct number of objects.' + ); $query->skip(3); - $this->assertEquals(2, $count, - 'Did not return correct number of objects.'); + $this->assertEquals( + 2, $count, + 'Did not return correct number of objects.' + ); } public function testCount() { ParseTestHelper::clearClass("BoxedNumber"); - $this->saveObjects(3, function ($i) { - $boxedNumber = ParseObject::create("BoxedNumber"); - $boxedNumber->set("x", $i + 1); + $this->saveObjects( + 3, function ($i) { + $boxedNumber = ParseObject::create("BoxedNumber"); + $boxedNumber->set("x", $i + 1); - return $boxedNumber; - }); + return $boxedNumber; + } + ); $query = new ParseQuery("BoxedNumber"); $query->greaterThan("x", 1); $count = $query->count(); - $this->assertEquals(2, $count, - 'Did not return correct number of objects.'); + $this->assertEquals( + 2, $count, + 'Did not return correct number of objects.' + ); } public function testCountError() @@ -489,20 +595,26 @@ public function testOrderByAscendingNumber() { ParseTestHelper::clearClass("BoxedNumber"); $numbers = [3, 1, 2]; - $this->saveObjects(3, function ($i) use ($numbers) { - $boxedNumber = ParseObject::create("BoxedNumber"); - $boxedNumber->set("number", $numbers[$i]); + $this->saveObjects( + 3, function ($i) use ($numbers) { + $boxedNumber = ParseObject::create("BoxedNumber"); + $boxedNumber->set("number", $numbers[$i]); - return $boxedNumber; - }); + return $boxedNumber; + } + ); $query = new ParseQuery("BoxedNumber"); $query->ascending("number"); $results = $query->find(); - $this->assertEquals(3, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 3, count($results), + 'Did not return correct number of objects.' + ); for ($i = 0; $i < 3; $i++) { - $this->assertEquals($i + 1, $results[$i]->get("number"), - 'Did not return the correct object.'); + $this->assertEquals( + $i + 1, $results[$i]->get("number"), + 'Did not return the correct object.' + ); } } @@ -510,34 +622,42 @@ public function testOrderByDescendingNumber() { ParseTestHelper::clearClass("BoxedNumber"); $numbers = [3, 1, 2]; - $this->saveObjects(3, function ($i) use ($numbers) { - $boxedNumber = ParseObject::create("BoxedNumber"); - $boxedNumber->set("number", $numbers[$i]); + $this->saveObjects( + 3, function ($i) use ($numbers) { + $boxedNumber = ParseObject::create("BoxedNumber"); + $boxedNumber->set("number", $numbers[$i]); - return $boxedNumber; - }); + return $boxedNumber; + } + ); $query = new ParseQuery("BoxedNumber"); $query->descending("number"); $results = $query->find(); - $this->assertEquals(3, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 3, count($results), + 'Did not return correct number of objects.' + ); for ($i = 0; $i < 3; $i++) { - $this->assertEquals(3 - $i, $results[$i]->get("number"), - 'Did not return the correct object.'); + $this->assertEquals( + 3 - $i, $results[$i]->get("number"), + 'Did not return the correct object.' + ); } } public function provideTestObjectsForQuery($numberOfObjects) { - $this->saveObjects($numberOfObjects, function ($i) { - $parent = ParseObject::create("ParentObject"); - $child = ParseObject::create("ChildObject"); - $child->set("x", $i); - $parent->set("x", 10 + $i); - $parent->set("child", $child); + $this->saveObjects( + $numberOfObjects, function ($i) { + $parent = ParseObject::create("ParentObject"); + $child = ParseObject::create("ChildObject"); + $child->set("x", $i); + $parent->set("x", 10 + $i); + $parent->set("child", $child); - return $parent; - }); + return $parent; + } + ); } public function testMatchesQuery() @@ -551,11 +671,15 @@ public function testMatchesQuery() $query->matchesQuery("child", $subQuery); $results = $query->find(); - $this->assertEquals(4, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 4, count($results), + 'Did not return correct number of objects.' + ); foreach ($results as $parentObj) { - $this->assertGreaterThan(15, $parentObj->get("x"), - 'Did not return the correct object.'); + $this->assertGreaterThan( + 15, $parentObj->get("x"), + 'Did not return the correct object.' + ); } } @@ -570,13 +694,19 @@ public function testDoesNotMatchQuery() $query->doesNotMatchQuery("child", $subQuery); $results = $query->find(); - $this->assertEquals(6, count($results), - 'Did not return the correct object.'); + $this->assertEquals( + 6, count($results), + 'Did not return the correct object.' + ); foreach ($results as $parentObj) { - $this->assertLessThanOrEqual(15, $parentObj->get("x"), - 'Did not return the correct object.'); - $this->assertGreaterThanOrEqual(10, $parentObj->get("x"), - 'Did not return the correct object.'); + $this->assertLessThanOrEqual( + 15, $parentObj->get("x"), + 'Did not return the correct object.' + ); + $this->assertGreaterThanOrEqual( + 10, $parentObj->get("x"), + 'Did not return the correct object.' + ); } } @@ -592,21 +722,25 @@ public function provideTestObjectsForKeyInQuery() $personName = ["Bob", "Tom", "Billy"]; $numberOfPersonObjects = count($personHomeTown); - $this->saveObjects($numberOFRestaurantObjects, function ($i) use ($restaurantRatings, $restaurantLocations) { - $restaurant = ParseObject::create("Restaurant"); - $restaurant->set("ratings", $restaurantRatings[$i]); - $restaurant->set("location", $restaurantLocations[$i]); + $this->saveObjects( + $numberOFRestaurantObjects, function ($i) use ($restaurantRatings, $restaurantLocations) { + $restaurant = ParseObject::create("Restaurant"); + $restaurant->set("ratings", $restaurantRatings[$i]); + $restaurant->set("location", $restaurantLocations[$i]); - return $restaurant; - }); + return $restaurant; + } + ); - $this->saveObjects($numberOfPersonObjects, function ($i) use ($personHomeTown, $personName) { - $person = ParseObject::create("Person"); - $person->set("hometown", $personHomeTown[$i]); + $this->saveObjects( + $numberOfPersonObjects, function ($i) use ($personHomeTown, $personName) { + $person = ParseObject::create("Person"); + $person->set("hometown", $personHomeTown[$i]); $person->set("name", $personName[$i]); - return $person; - }); + return $person; + } + ); } public function testMatchesKeyInQuery() @@ -619,10 +753,14 @@ public function testMatchesKeyInQuery() $query->matchesKeyInQuery("hometown", "location", $subQuery); $results = $query->find(); - $this->assertEquals(1, count($results), - 'Did not return correct number of objects.'); - $this->assertEquals("Bob", $results[0]->get("name"), - 'Did not return the correct object.'); + $this->assertEquals( + 1, count($results), + 'Did not return correct number of objects.' + ); + $this->assertEquals( + "Bob", $results[0]->get("name"), + 'Did not return the correct object.' + ); } public function testDoesNotMatchKeyInQuery() @@ -635,10 +773,14 @@ public function testDoesNotMatchKeyInQuery() $query->doesNotmatchKeyInQuery("hometown", "location", $subQuery); $results = $query->find(); - $this->assertEquals(1, count($results), - 'Did not return correct number of objects.'); - $this->assertEquals("Billy", $results[0]->get("name"), - 'Did not return the correct object.'); + $this->assertEquals( + 1, count($results), + 'Did not return correct number of objects.' + ); + $this->assertEquals( + "Billy", $results[0]->get("name"), + 'Did not return the correct object.' + ); } public function testOrQueries() @@ -652,12 +794,16 @@ public function testOrQueries() $mainQuery = ParseQuery::orQueries([$subQuery1, $subQuery2]); $results = $mainQuery->find(); $length = count($results); - $this->assertEquals(6, $length, - 'Did not return correct number of objects.'); + $this->assertEquals( + 6, $length, + 'Did not return correct number of objects.' + ); for ($i = 0; $i < $length; $i++) { - $this->assertTrue($results[$i]->get("foo") < "bar2" || - $results[$i]->get("foo") > "bar5", - 'Did not return the correct object.'); + $this->assertTrue( + $results[$i]->get("foo") < "bar2" || + $results[$i]->get("foo") > "bar5", + 'Did not return the correct object.' + ); } } @@ -665,15 +811,17 @@ public function testComplexQueries() { ParseTestHelper::clearClass("Child"); ParseTestHelper::clearClass("Parent"); - $this->saveObjects(10, function ($i) { - $child = new ParseObject("Child"); - $child->set("x", $i); - $parent = new ParseObject("Parent"); - $parent->set("y", $i); - $parent->set("child", $child); - - return $parent; - }); + $this->saveObjects( + 10, function ($i) { + $child = new ParseObject("Child"); + $child->set("x", $i); + $parent = new ParseObject("Parent"); + $parent->set("y", $i); + $parent->set("child", $child); + + return $parent; + } + ); $subQuery = new ParseQuery("Child"); $subQuery->equalTo("x", 4); $query1 = new ParseQuery("Parent"); @@ -683,8 +831,10 @@ public function testComplexQueries() $orQuery = ParseQuery::orQueries([$query1, $query2]); $results = $orQuery->find(); - $this->assertEquals(3, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 3, count($results), + 'Did not return correct number of objects.' + ); } public function testEach() @@ -692,27 +842,35 @@ public function testEach() ParseTestHelper::clearClass("Object"); $total = 50; $count = 25; - $this->saveObjects($total, function ($i) { - $obj = new ParseObject("Object"); - $obj->set("x", $i + 1); + $this->saveObjects( + $total, function ($i) { + $obj = new ParseObject("Object"); + $obj->set("x", $i + 1); - return $obj; - }); + return $obj; + } + ); $query = new ParseQuery("Object"); $query->lessThanOrEqualTo("x", $count); $values = []; - $query->each(function ($obj) use (&$values) { - $values[] = $obj->get("x"); - }, 10); + $query->each( + function ($obj) use (&$values) { + $values[] = $obj->get("x"); + }, 10 + ); $valuesLength = count($values); - $this->assertEquals($count, $valuesLength, - 'Did not return correct number of objects.'); + $this->assertEquals( + $count, $valuesLength, + 'Did not return correct number of objects.' + ); sort($values); for ($i = 0; $i < $valuesLength; $i++) { - $this->assertEquals($i + 1, $values[$i], - 'Did not return the correct object.'); + $this->assertEquals( + $i + 1, $values[$i], + 'Did not return the correct object.' + ); } } @@ -721,54 +879,66 @@ public function testEachFailsWithOrder() ParseTestHelper::clearClass("Object"); $total = 50; $count = 25; - $this->saveObjects($total, function ($i) { - $obj = new ParseObject("Object"); - $obj->set("x", $i + 1); + $this->saveObjects( + $total, function ($i) { + $obj = new ParseObject("Object"); + $obj->set("x", $i + 1); - return $obj; - }); + return $obj; + } + ); $query = new ParseQuery("Object"); $query->lessThanOrEqualTo("x", $count); $query->ascending("x"); $this->setExpectedException('\Exception', 'sort'); - $query->each(function ($obj) { - }); + $query->each( + function ($obj) { + } + ); } public function testEachFailsWithSkip() { $total = 50; $count = 25; - $this->saveObjects($total, function ($i) { - $obj = new ParseObject("Object"); - $obj->set("x", $i + 1); + $this->saveObjects( + $total, function ($i) { + $obj = new ParseObject("Object"); + $obj->set("x", $i + 1); - return $obj; - }); + return $obj; + } + ); $query = new ParseQuery("Object"); $query->lessThanOrEqualTo("x", $count); $query->skip(5); $this->setExpectedException('\Exception', 'skip'); - $query->each(function ($obj) { - }); + $query->each( + function ($obj) { + } + ); } public function testEachFailsWithLimit() { $total = 50; $count = 25; - $this->saveObjects($total, function ($i) { - $obj = new ParseObject("Object"); - $obj->set("x", $i + 1); + $this->saveObjects( + $total, function ($i) { + $obj = new ParseObject("Object"); + $obj->set("x", $i + 1); - return $obj; - }); + return $obj; + } + ); $query = new ParseQuery("Object"); $query->lessThanOrEqualTo("x", $count); $query->limit(5); $this->setExpectedException('\Exception', 'limit'); - $query->each(function ($obj) { - }); + $query->each( + function ($obj) { + } + ); } public function testContainsAllNumberArrayQueries() @@ -784,8 +954,10 @@ public function testContainsAllNumberArrayQueries() $query = new ParseQuery("NumberSet"); $query->containsAll("numbers", [1, 2, 3]); $results = $query->find(); - $this->assertEquals(1, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 1, count($results), + 'Did not return correct number of objects.' + ); } public function testContainsAllStringArrayQueries() @@ -801,8 +973,10 @@ public function testContainsAllStringArrayQueries() $query = new ParseQuery("StringSet"); $query->containsAll("strings", ["a", "b", "c"]); $results = $query->find(); - $this->assertEquals(1, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 1, count($results), + 'Did not return correct number of objects.' + ); } public function testContainsAllDateArrayQueries() @@ -828,120 +1002,152 @@ public function testContainsAllDateArrayQueries() $obj2->save(); $query = new ParseQuery("DateSet"); - $query->containsAll("dates", [ + $query->containsAll( + "dates", [ new DateTime("2013-02-01T00:00:00Z"), new DateTime("2013-02-02T00:00:00Z"), new DateTime("2013-02-03T00:00:00Z"), - ]); + ] + ); $result = $query->find(); - $this->assertEquals(1, count($result), - 'Did not return correct number of objects.'); + $this->assertEquals( + 1, count($result), + 'Did not return correct number of objects.' + ); } public function testContainsAllObjectArrayQueries() { ParseTestHelper::clearClass("MessageSet"); $messageList = []; - $this->saveObjects(4, function ($i) use (&$messageList) { - $messageList[] = ParseObject::create("TestObject"); - $messageList[$i]->set("i", $i); + $this->saveObjects( + 4, function ($i) use (&$messageList) { + $messageList[] = ParseObject::create("TestObject"); + $messageList[$i]->set("i", $i); - return $messageList[$i]; - }); + return $messageList[$i]; + } + ); $messageSet1 = ParseObject::create("MessageSet"); $messageSet1->setArray("messages", $messageList); $messageSet1->save(); $messageSet2 = ParseObject::create("MessageSet"); - $messageSet2->setArray("message", - [$messageList[0], $messageList[1], $messageList[3]] + $messageSet2->setArray( + "message", + [$messageList[0], $messageList[1], $messageList[3]] ); $messageSet2->save(); $query = new ParseQuery("MessageSet"); $query->containsAll("messages", [$messageList[0], $messageList[2]]); $results = $query->find(); - $this->assertEquals(1, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 1, count($results), + 'Did not return correct number of objects.' + ); } public function testContainedInObjectArrayQueries() { $messageList = []; - $this->saveObjects(4, function ($i) use (&$messageList) { - $message = ParseObject::create("TestObject"); - if ($i > 0) { - $message->set("prior", $messageList[$i - 1]); + $this->saveObjects( + 4, function ($i) use (&$messageList) { + $message = ParseObject::create("TestObject"); + if ($i > 0) { + $message->set("prior", $messageList[$i - 1]); + } + $messageList[] = $message; + + return $message; } - $messageList[] = $message; - - return $message; - }); + ); $query = new ParseQuery("TestObject"); $query->containedIn("prior", [$messageList[0], $messageList[2]]); $results = $query->find(); - $this->assertEquals(2, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 2, count($results), + 'Did not return correct number of objects.' + ); } public function testContainedInQueries() { ParseTestHelper::clearClass("BoxedNumber"); - $this->saveObjects(10, function ($i) { - $boxedNumber = ParseObject::create("BoxedNumber"); - $boxedNumber->set("number", $i); + $this->saveObjects( + 10, function ($i) { + $boxedNumber = ParseObject::create("BoxedNumber"); + $boxedNumber->set("number", $i); - return $boxedNumber; - }); + return $boxedNumber; + } + ); $query = new ParseQuery("BoxedNumber"); $query->containedIn("number", [3, 5, 7, 9, 11]); $results = $query->find(); - $this->assertEquals(4, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 4, count($results), + 'Did not return correct number of objects.' + ); } public function testNotContainedInQueries() { ParseTestHelper::clearClass("BoxedNumber"); - $this->saveObjects(10, function ($i) { - $boxedNumber = ParseObject::create("BoxedNumber"); - $boxedNumber->set("number", $i); + $this->saveObjects( + 10, function ($i) { + $boxedNumber = ParseObject::create("BoxedNumber"); + $boxedNumber->set("number", $i); - return $boxedNumber; - }); + return $boxedNumber; + } + ); $query = new ParseQuery("BoxedNumber"); $query->notContainedIn("number", [3, 5, 7, 9, 11]); $results = $query->find(); - $this->assertEquals(6, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 6, count($results), + 'Did not return correct number of objects.' + ); } public function testObjectIdContainedInQueries() { ParseTestHelper::clearClass("BoxedNumber"); $objects = []; - $this->saveObjects(5, function ($i) use (&$objects) { - $boxedNumber = ParseObject::create("BoxedNumber"); - $boxedNumber->set("number", $i); - $objects[] = $boxedNumber; + $this->saveObjects( + 5, function ($i) use (&$objects) { + $boxedNumber = ParseObject::create("BoxedNumber"); + $boxedNumber->set("number", $i); + $objects[] = $boxedNumber; - return $boxedNumber; - }); + return $boxedNumber; + } + ); $query = new ParseQuery("BoxedNumber"); - $query->containedIn("objectId", [$objects[2]->getObjectId(), + $query->containedIn( + "objectId", [$objects[2]->getObjectId(), $objects[3]->getObjectId(), $objects[0]->getObjectId(), "NONSENSE", ] ); $query->ascending("number"); $results = $query->find(); - $this->assertEquals(3, count($results), - 'Did not return correct number of objects.'); - $this->assertEquals(0, $results[0]->get("number"), - 'Did not return the correct object.'); - $this->assertEquals(2, $results[1]->get("number"), - 'Did not return the correct object.'); - $this->assertEquals(3, $results[2]->get("number"), - 'Did not return the correct object.'); + $this->assertEquals( + 3, count($results), + 'Did not return correct number of objects.' + ); + $this->assertEquals( + 0, $results[0]->get("number"), + 'Did not return the correct object.' + ); + $this->assertEquals( + 2, $results[1]->get("number"), + 'Did not return the correct object.' + ); + $this->assertEquals( + 3, $results[2]->get("number"), + 'Did not return the correct object.' + ); } public function testStartsWith() @@ -950,17 +1156,21 @@ public function testStartsWith() "VWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'"; $prefixes = ['zax', 'start', '', '']; $suffixes = ['qub', '', 'end', '']; - $this->saveObjects(4, function ($i) use ($prefixes, $suffixes, $someAscii) { - $obj = ParseObject::create("TestObject"); - $obj->set("myString", $prefixes[$i].$someAscii.$suffixes[$i]); + $this->saveObjects( + 4, function ($i) use ($prefixes, $suffixes, $someAscii) { + $obj = ParseObject::create("TestObject"); + $obj->set("myString", $prefixes[$i].$someAscii.$suffixes[$i]); - return $obj; - }); + return $obj; + } + ); $query = new ParseQuery("TestObject"); $query->startsWith("myString", $someAscii); $results = $query->find(); - $this->assertEquals(2, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 2, count($results), + 'Did not return correct number of objects.' + ); } public function provideTestObjectsForOrderBy() @@ -983,13 +1193,19 @@ public function testOrderByAscNumberThenDescString() $query->ascending('number')->addDescending('string'); $results = $query->find(); $expected = [[1, 'b'], [2, 'd'], [3, 'c'], [3, 'a']]; - $this->assertEquals(4, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 4, count($results), + 'Did not return correct number of objects.' + ); for ($i = 0; $i < 4; $i++) { - $this->assertEquals($expected[$i][0], $results[$i]->get('number'), - 'Did not return the correct object.'); - $this->assertEquals($expected[$i][1], $results[$i]->get('string'), - 'Did not return the correct object.'); + $this->assertEquals( + $expected[$i][0], $results[$i]->get('number'), + 'Did not return the correct object.' + ); + $this->assertEquals( + $expected[$i][1], $results[$i]->get('string'), + 'Did not return the correct object.' + ); } } @@ -1000,13 +1216,19 @@ public function testOrderByDescNumberThenAscString() $query->descending('number')->addAscending('string'); $results = $query->find(); $expected = [[3, 'a'], [3, 'c'], [2, 'd'], [1, 'b']]; - $this->assertEquals(4, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 4, count($results), + 'Did not return correct number of objects.' + ); for ($i = 0; $i < 4; $i++) { - $this->assertEquals($expected[$i][0], $results[$i]->get('number'), - 'Did not return the correct object.'); - $this->assertEquals($expected[$i][1], $results[$i]->get('string'), - 'Did not return the correct object.'); + $this->assertEquals( + $expected[$i][0], $results[$i]->get('number'), + 'Did not return the correct object.' + ); + $this->assertEquals( + $expected[$i][1], $results[$i]->get('string'), + 'Did not return the correct object.' + ); } } @@ -1017,13 +1239,19 @@ public function testOrderByDescNumberAndString() $query->descending(['number', 'string']); $results = $query->find(); $expected = [[3, 'c'], [3, 'a'], [2, 'd'], [1, 'b']]; - $this->assertEquals(4, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 4, count($results), + 'Did not return correct number of objects.' + ); for ($i = 0; $i < 4; $i++) { - $this->assertEquals($expected[$i][0], $results[$i]->get('number'), - 'Did not return the correct object.'); - $this->assertEquals($expected[$i][1], $results[$i]->get('string'), - 'Did not return the correct object.'); + $this->assertEquals( + $expected[$i][0], $results[$i]->get('number'), + 'Did not return the correct object.' + ); + $this->assertEquals( + $expected[$i][1], $results[$i]->get('string'), + 'Did not return the correct object.' + ); } } @@ -1043,12 +1271,16 @@ public function testOrderByCreatedAtAsc() $query->ascending('createdAt'); $query->find(); $results = $query->find(); - $this->assertEquals(4, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 4, count($results), + 'Did not return correct number of objects.' + ); $expected = [3, 1, 3, 2]; for ($i = 0; $i < 4; $i++) { - $this->assertEquals($expected[$i], $results[$i]->get('number'), - 'Did not return the correct object.'); + $this->assertEquals( + $expected[$i], $results[$i]->get('number'), + 'Did not return the correct object.' + ); } } @@ -1059,12 +1291,16 @@ public function testOrderByCreatedAtDesc() $query->descending('createdAt'); $query->find(); $results = $query->find(); - $this->assertEquals(4, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 4, count($results), + 'Did not return correct number of objects.' + ); $expected = [2, 3, 1, 3]; for ($i = 0; $i < 4; $i++) { - $this->assertEquals($expected[$i], $results[$i]->get('number'), - 'Did not return the correct object.'); + $this->assertEquals( + $expected[$i], $results[$i]->get('number'), + 'Did not return the correct object.' + ); } } @@ -1072,24 +1308,30 @@ public function testOrderByUpdatedAtAsc() { $numbers = [3, 1, 2]; $objects = []; - $this->saveObjects(3, function ($i) use ($numbers, &$objects) { - $obj = ParseObject::create("TestObject"); - $obj->set('number', $numbers[$i]); - $objects[] = $obj; + $this->saveObjects( + 3, function ($i) use ($numbers, &$objects) { + $obj = ParseObject::create("TestObject"); + $obj->set('number', $numbers[$i]); + $objects[] = $obj; - return $obj; - }); + return $obj; + } + ); $objects[1]->set('number', 4); $objects[1]->save(); $query = new ParseQuery("TestObject"); $query->ascending('updatedAt'); $results = $query->find(); - $this->assertEquals(3, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 3, count($results), + 'Did not return correct number of objects.' + ); $expected = [3, 2, 4]; for ($i = 0; $i < 3; $i++) { - $this->assertEquals($expected[$i], $results[$i]->get('number'), - 'Did not return the correct object.'); + $this->assertEquals( + $expected[$i], $results[$i]->get('number'), + 'Did not return the correct object.' + ); } } @@ -1097,24 +1339,30 @@ public function testOrderByUpdatedAtDesc() { $numbers = [3, 1, 2]; $objects = []; - $this->saveObjects(3, function ($i) use ($numbers, &$objects) { - $obj = ParseObject::create("TestObject"); - $obj->set('number', $numbers[$i]); - $objects[] = $obj; + $this->saveObjects( + 3, function ($i) use ($numbers, &$objects) { + $obj = ParseObject::create("TestObject"); + $obj->set('number', $numbers[$i]); + $objects[] = $obj; - return $obj; - }); + return $obj; + } + ); $objects[1]->set('number', 4); $objects[1]->save(); $query = new ParseQuery("TestObject"); $query->descending('updatedAt'); $results = $query->find(); - $this->assertEquals(3, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 3, count($results), + 'Did not return correct number of objects.' + ); $expected = [4, 2, 3]; for ($i = 0; $i < 3; $i++) { - $this->assertEquals($expected[$i], $results[$i]->get('number'), - 'Did not return the correct object.'); + $this->assertEquals( + $expected[$i], $results[$i]->get('number'), + 'Did not return the correct object.' + ); } } @@ -1127,8 +1375,10 @@ public function testSelectKeysQuery() $query = new ParseQuery("TestObject"); $query->select('foo'); $result = $query->first(); - $this->assertEquals('baz', $result->get('foo'), - 'Did not return the correct object.'); + $this->assertEquals( + 'baz', $result->get('foo'), + 'Did not return the correct object.' + ); $this->setExpectedException('\Exception', 'Call fetch()'); $result->get('bar'); } @@ -1138,10 +1388,14 @@ public function testGetWithoutError() $obj = ParseObject::create("TestObject"); $obj->set('foo', 'baz'); $obj->set('bar', 1); - $this->assertEquals('baz', $obj->get('foo'), - 'Did not return the correct object.'); - $this->assertEquals(1, $obj->get('bar'), - 'Did not return the correct object.'); + $this->assertEquals( + 'baz', $obj->get('foo'), + 'Did not return the correct object.' + ); + $this->assertEquals( + 1, $obj->get('bar'), + 'Did not return the correct object.' + ); $obj->save(); } public function testSelectKeysQueryArrayArg() @@ -1153,92 +1407,112 @@ public function testSelectKeysQueryArrayArg() $query = new ParseQuery("TestObject"); $query->select(['foo', 'bar']); $result = $query->first(); - $this->assertEquals('baz', $result->get('foo'), - 'Did not return the correct object.'); - $this->assertEquals(1, $result->get('bar'), - 'Did not return the correct object.'); + $this->assertEquals( + 'baz', $result->get('foo'), + 'Did not return the correct object.' + ); + $this->assertEquals( + 1, $result->get('bar'), + 'Did not return the correct object.' + ); } public function testExists() { - $this->saveObjects(9, function ($i) { - $obj = ParseObject::create("TestObject"); - if ($i & 1) { - $obj->set('y', $i); - } else { - $obj->set('x', $i); - } + $this->saveObjects( + 9, function ($i) { + $obj = ParseObject::create("TestObject"); + if ($i & 1) { + $obj->set('y', $i); + } else { + $obj->set('x', $i); + } - return $obj; - }); + return $obj; + } + ); $query = new ParseQuery("TestObject"); $query->exists('x'); $results = $query->find(); - $this->assertEquals(5, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 5, count($results), + 'Did not return correct number of objects.' + ); } public function testDoesNotExist() { - $this->saveObjects(9, function ($i) { - $obj = ParseObject::create("TestObject"); - if ($i & 1) { - $obj->set('y', $i); - } else { - $obj->set('x', $i); - } + $this->saveObjects( + 9, function ($i) { + $obj = ParseObject::create("TestObject"); + if ($i & 1) { + $obj->set('y', $i); + } else { + $obj->set('x', $i); + } - return $obj; - }); + return $obj; + } + ); $query = new ParseQuery("TestObject"); $query->doesNotExist('x'); $results = $query->find(); - $this->assertEquals(4, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 4, count($results), + 'Did not return correct number of objects.' + ); } public function testExistsRelation() { ParseTestHelper::clearClass("Item"); - $this->saveObjects(9, function ($i) { - $obj = ParseObject::create("TestObject"); - if ($i & 1) { - $obj->set('y', $i); - } else { - $item = ParseObject::create("Item"); - $item->set('e', $i); - $obj->set('e', $item); + $this->saveObjects( + 9, function ($i) { + $obj = ParseObject::create("TestObject"); + if ($i & 1) { + $obj->set('y', $i); + } else { + $item = ParseObject::create("Item"); + $item->set('e', $i); + $obj->set('e', $item); + } + + return $obj; } - - return $obj; - }); + ); $query = new ParseQuery("TestObject"); $query->exists('e'); $results = $query->find(); - $this->assertEquals(5, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 5, count($results), + 'Did not return correct number of objects.' + ); } public function testDoesNotExistRelation() { ParseTestHelper::clearClass("Item"); - $this->saveObjects(9, function ($i) { - $obj = ParseObject::create("TestObject"); - if ($i & 1) { - $obj->set('y', $i); - } else { - $item = ParseObject::create("Item"); - $item->set('x', $i); - $obj->set('x', $i); + $this->saveObjects( + 9, function ($i) { + $obj = ParseObject::create("TestObject"); + if ($i & 1) { + $obj->set('y', $i); + } else { + $item = ParseObject::create("Item"); + $item->set('x', $i); + $obj->set('x', $i); + } + + return $obj; } - - return $obj; - }); + ); $query = new ParseQuery("TestObject"); $query->doesNotExist('x'); $results = $query->find(); - $this->assertEquals(4, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 4, count($results), + 'Did not return correct number of objects.' + ); } public function testDoNotIncludeRelation() @@ -1270,10 +1544,14 @@ public function testIncludeRelation() $query = new ParseQuery('Parent'); $query->includeKey('child'); $result = $query->first(); - $this->assertEquals($result->get('y'), $result->get('child')->get('x'), - 'Object should be fetched.'); - $this->assertEquals(1, $result->get('child')->get('x'), - 'Object should be fetched.'); + $this->assertEquals( + $result->get('y'), $result->get('child')->get('x'), + 'Object should be fetched.' + ); + $this->assertEquals( + 1, $result->get('child')->get('x'), + 'Object should be fetched.' + ); } public function testNestedIncludeRelation() @@ -1296,11 +1574,15 @@ public function testNestedIncludeRelation() $query = new ParseQuery('GrandParent'); $query->includeKey('parent.child'); $result = $query->first(); - $this->assertEquals($result->get('z'), $result->get('parent')->get('y'), - 'Object should be fetched.'); - $this->assertEquals($result->get('z'), - $result->get('parent')->get('child')->get('x'), - 'Object should be fetched.'); + $this->assertEquals( + $result->get('z'), $result->get('parent')->get('y'), + 'Object should be fetched.' + ); + $this->assertEquals( + $result->get('z'), + $result->get('parent')->get('child')->get('x'), + 'Object should be fetched.' + ); } public function testIncludeArrayRelation() @@ -1308,13 +1590,15 @@ public function testIncludeArrayRelation() ParseTestHelper::clearClass("Child"); ParseTestHelper::clearClass("Parent"); $children = []; - $this->saveObjects(5, function ($i) use (&$children) { - $child = ParseObject::create("Child"); - $child->set('x', $i); - $children[] = $child; + $this->saveObjects( + 5, function ($i) use (&$children) { + $child = ParseObject::create("Child"); + $child->set('x', $i); + $children[] = $child; - return $child; - }); + return $child; + } + ); $parent = ParseObject::create("Parent"); $parent->setArray('children', $children); $parent->save(); @@ -1322,13 +1606,17 @@ public function testIncludeArrayRelation() $query = new ParseQuery("Parent"); $query->includeKey('children'); $result = $query->find(); - $this->assertEquals(1, count($result), - 'Did not return correct number of objects.'); + $this->assertEquals( + 1, count($result), + 'Did not return correct number of objects.' + ); $children = $result[0]->get('children'); $length = count($children); for ($i = 0; $i < $length; $i++) { - $this->assertEquals($i, $children[$i]->get('x'), - 'Object should be fetched.'); + $this->assertEquals( + $i, $children[$i]->get('x'), + 'Object should be fetched.' + ); } } @@ -1339,8 +1627,10 @@ public function testIncludeWithNoResults() $query = new ParseQuery("Parent"); $query->includeKey('children'); $result = $query->find(); - $this->assertEquals(0, count($result), - 'Did not return correct number of objects.'); + $this->assertEquals( + 0, count($result), + 'Did not return correct number of objects.' + ); } public function testIncludeWithNonExistentKey() @@ -1354,8 +1644,10 @@ public function testIncludeWithNonExistentKey() $query = new ParseQuery("Parent"); $query->includeKey('child'); $results = $query->find(); - $this->assertEquals(1, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 1, count($results), + 'Did not return correct number of objects.' + ); } public function testIncludeOnTheWrongKeyType() @@ -1370,8 +1662,10 @@ public function testIncludeOnTheWrongKeyType() $query->includeKey('foo'); $this->setExpectedException('Parse\ParseException', '', 102); $results = $query->find(); - $this->assertEquals(1, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 1, count($results), + 'Did not return correct number of objects.' + ); } public function testIncludeWhenOnlySomeObjectsHaveChildren() @@ -1381,30 +1675,38 @@ public function testIncludeWhenOnlySomeObjectsHaveChildren() $child = ParseObject::create('Child'); $child->set('foo', 'bar'); $child->save(); - $this->saveObjects(4, function ($i) use ($child) { - $parent = ParseObject::create('Parent'); - $parent->set('num', $i); - if ($i & 1) { - $parent->set('child', $child); + $this->saveObjects( + 4, function ($i) use ($child) { + $parent = ParseObject::create('Parent'); + $parent->set('num', $i); + if ($i & 1) { + $parent->set('child', $child); + } + + return $parent; } - - return $parent; - }); + ); $query = new ParseQuery('Parent'); $query->includeKey(['child']); $query->ascending('num'); $results = $query->find(); - $this->assertEquals(4, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 4, count($results), + 'Did not return correct number of objects.' + ); $length = count($results); for ($i = 0; $i < $length; $i++) { if ($i & 1) { - $this->assertEquals('bar', $results[$i]->get('child')->get('foo'), - 'Object should be fetched'); + $this->assertEquals( + 'bar', $results[$i]->get('child')->get('foo'), + 'Object should be fetched' + ); } else { - $this->assertEquals(null, $results[$i]->get('child'), - 'Should not have child'); + $this->assertEquals( + null, $results[$i]->get('child'), + 'Should not have child' + ); } } } @@ -1429,10 +1731,14 @@ public function testIncludeMultipleKeys() $query = new ParseQuery('Parent'); $query->includeKey(['foofoo', 'barbar']); $result = $query->first(); - $this->assertEquals('oof', $result->get('foofoo')->get('rev'), - 'Object should be fetched'); - $this->assertEquals('rab', $result->get('barbar')->get('rev'), - 'Object should be fetched'); + $this->assertEquals( + 'oof', $result->get('foofoo')->get('rev'), + 'Object should be fetched' + ); + $this->assertEquals( + 'rab', $result->get('barbar')->get('rev'), + 'Object should be fetched' + ); } public function testEqualToObject() @@ -1440,53 +1746,65 @@ public function testEqualToObject() ParseTestHelper::clearClass("Item"); ParseTestHelper::clearClass("Container"); $items = []; - $this->saveObjects(2, function ($i) use (&$items) { - $items[] = ParseObject::create("Item"); - $items[$i]->set('x', $i); - - return $items[$i]; - }); - $this->saveObjects(2, function ($i) use ($items) { - $container = ParseObject::create("Container"); - $container->set('item', $items[$i]); - - return $container; - }); + $this->saveObjects( + 2, function ($i) use (&$items) { + $items[] = ParseObject::create("Item"); + $items[$i]->set('x', $i); + + return $items[$i]; + } + ); + $this->saveObjects( + 2, function ($i) use ($items) { + $container = ParseObject::create("Container"); + $container->set('item', $items[$i]); + + return $container; + } + ); $query = new ParseQuery("Container"); $query->equalTo('item', $items[0]); $result = $query->find(); - $this->assertEquals(1, count($result), - 'Did not return the correct object.'); + $this->assertEquals( + 1, count($result), + 'Did not return the correct object.' + ); } public function testEqualToNull() { - $this->saveObjects(10, function ($i) { - $obj = ParseObject::create('TestObject'); - $obj->set('num', $i); + $this->saveObjects( + 10, function ($i) { + $obj = ParseObject::create('TestObject'); + $obj->set('num', $i); - return $obj; - }); + return $obj; + } + ); $query = new ParseQuery('TestObject'); $query->equalTo('num', null); $results = $query->find(); - $this->assertEquals(0, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 0, count($results), + 'Did not return correct number of objects.' + ); } public function provideTimeTestObjects() { ParseTestHelper::clearClass("TimeObject"); $items = []; - $this->saveObjects(3, function ($i) use (&$items) { - $timeObject = ParseObject::create('TimeObject'); - $timeObject->set('name', 'item'.$i); - $timeObject->set('time', new DateTime()); - sleep(1); - $items[] = $timeObject; - - return $timeObject; - }); + $this->saveObjects( + 3, function ($i) use (&$items) { + $timeObject = ParseObject::create('TimeObject'); + $timeObject->set('name', 'item'.$i); + $timeObject->set('time', new DateTime()); + sleep(1); + $items[] = $timeObject; + + return $timeObject; + } + ); return $items; } @@ -1497,8 +1815,10 @@ public function testTimeEquality() $query = new ParseQuery('TimeObject'); $query->equalTo('time', $items[1]->get('time')); $results = $query->find(); - $this->assertEquals(1, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 1, count($results), + 'Did not return correct number of objects.' + ); $this->assertEquals('item1', $results[0]->get('name')); } @@ -1508,8 +1828,10 @@ public function testTimeLessThan() $query = new ParseQuery('TimeObject'); $query->lessThan('time', $items[2]->get('time')); $results = $query->find(); - $this->assertEquals(2, count($results), - 'Did not return correct number of objects.'); + $this->assertEquals( + 2, count($results), + 'Did not return correct number of objects.' + ); } public function testRestrictedGetFailsWithoutMasterKey() diff --git a/tests/ParseRelationTest.php b/tests/ParseRelationTest.php index 720c0fed..3d3fb9ca 100644 --- a/tests/ParseRelationTest.php +++ b/tests/ParseRelationTest.php @@ -36,13 +36,15 @@ public function saveObjects($numberOfObjects, $callback) public function testParseRelations() { $children = []; - $this->saveObjects(10, function ($i) use (&$children) { - $child = ParseObject::create('ChildObject'); - $child->set('x', $i); - $children[] = $child; - - return $child; - }); + $this->saveObjects( + 10, function ($i) use (&$children) { + $child = ParseObject::create('ChildObject'); + $child->set('x', $i); + $children[] = $child; + + return $child; + } + ); $parent = ParseObject::create('ParentObject'); $relation = $parent->getRelation('children'); $relation->add($children[0]); @@ -72,12 +74,14 @@ public function testParseRelations() $this->assertFalse($parent->isDirty()); $relation->remove($children[5]); - $relation->add([ + $relation->add( + [ $children[5], $children[6], $children[7], $children[8], - ]); + ] + ); $parent->save(); $results = $relation->getQuery()->find(); @@ -100,31 +104,37 @@ public function testParseRelations() public function testQueriesOnRelationFields() { $children = []; - $this->saveObjects(10, function ($i) use (&$children) { - $child = ParseObject::create('ChildObject'); - $child->set('x', $i); - $children[] = $child; + $this->saveObjects( + 10, function ($i) use (&$children) { + $child = ParseObject::create('ChildObject'); + $child->set('x', $i); + $children[] = $child; - return $child; - }); + return $child; + } + ); $parent = ParseObject::create('ParentObject'); $parent->set('x', 4); $relation = $parent->getRelation('children'); - $relation->add([ + $relation->add( + [ $children[0], $children[1], $children[2], - ]); + ] + ); $parent->save(); $parent2 = ParseObject::create('ParentObject'); $parent2->set('x', 3); $relation2 = $parent2->getRelation('children'); - $relation2->add([ + $relation2->add( + [ $children[4], $children[5], $children[6], - ]); + ] + ); $parent2->save(); $query = new ParseQuery('ParentObject'); $query->containedIn('children', [$children[4], $children[9]]); diff --git a/tests/ParseTestHelper.php b/tests/ParseTestHelper.php index 6aa9f8d9..3579d132 100644 --- a/tests/ParseTestHelper.php +++ b/tests/ParseTestHelper.php @@ -25,8 +25,10 @@ public static function tearDown() public static function clearClass($class) { $query = new ParseQuery($class); - $query->each(function (ParseObject $obj) { - $obj->destroy(true); - }, true); + $query->each( + function (ParseObject $obj) { + $obj->destroy(true); + }, true + ); } }