Skip to content

Remove Default API #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions src/Parse/ParseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ final class ParseClient
*
* @var string
*/
private static $serverURL = 'https://api.parse.com/';
private static $serverURL = null;

/**
* The mount path for the current parse server
*
* @var string
*/
private static $mountPath = "1/";
private static $mountPath = null;

/**
* The application id.
Expand Down Expand Up @@ -193,6 +193,24 @@ public static function setServerURL($serverURL, $mountPath)
}
}

/**
* Clears the existing server url.
* Used primarily for testing purposes.
*/
public static function _clearServerURL()
{
self::$serverURL = null;
}

/**
* Clears the existing mount path.
* Used primarily for testing purposes.
*/
public static function _clearMountPath()
{
self::$mountPath = null;
}

/**
* Sets the Http client to use for requests
*
Expand Down Expand Up @@ -408,6 +426,9 @@ public static function _request(
$httpClient->setCAFile(self::$caFile);
}

// verify the server url and mount path have been set
self::assertServerInitialized();

if ($appRequest) {
// ** 'app' requests are not available in open source parse-server
self::assertAppInitialized();
Expand Down Expand Up @@ -570,6 +591,30 @@ public static function _unsetStorage()
self::$storage = null;
}

/**
* Asserts that the server and mount path have been initialized
*
* @throws Exception
*/
private static function assertServerInitialized()
{
if (self::$serverURL === null) {
throw new Exception(
'Missing a valid server url. '.
'You must call ParseClient::setServerURL(\'https://your.parse-server.com\', \'/parse\') '.
' before making any requests.'
);
}

if (self::$mountPath === null) {
throw new Exception(
'Missing a valid mount path. '.
'You must call ParseClient::setServerURL(\'https://your.parse-server.com\', \'/parse\') '.
' before making any requests.'
);
}
}

/**
* Asserts that the sdk has been initialized with a valid application id
*
Expand All @@ -579,7 +624,7 @@ private static function assertParseInitialized()
{
if (self::$applicationId === null) {
throw new Exception(
'You must call Parse::initialize() before making any requests.'
'You must call ParseClient::initialize() before making any requests.'
);
}
}
Expand All @@ -593,7 +638,7 @@ private static function assertAppInitialized()
{
if (self::$accountKey === null || empty(self::$accountKey)) {
throw new Exception(
'You must call Parse::initialize(..., $accountKey) before making any app requests. '.
'You must call ParseClient::initialize(..., $accountKey) before making any app requests. '.
'Your account key must not be null or empty.'
);
}
Expand Down
36 changes: 34 additions & 2 deletions tests/Parse/ParseClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testParseNotInitialized()
{
$this->setExpectedException(
'\Exception',
'You must call Parse::initialize() before making any requests.'
'You must call ParseClient::initialize() before making any requests.'
);

ParseClient::initialize(
Expand All @@ -69,7 +69,7 @@ public function testAppNotNotInitialized()
{
$this->setExpectedException(
'\Exception',
'You must call Parse::initialize(..., $accountKey) before making any app requests. '.
'You must call ParseClient::initialize(..., $accountKey) before making any app requests. '.
'Your account key must not be null or empty.'
);

Expand Down Expand Up @@ -519,6 +519,38 @@ public function testStreamCAFile()
);
}

/**
* @group api-not-set
*/
public function testURLNotSet()
{
$this->setExpectedException(
'\Exception',
'Missing a valid server url. '.
'You must call ParseClient::setServerURL(\'https://your.parse-server.com\', \'/parse\') '.
' before making any requests.'
);

ParseClient::_clearServerURL();
(new ParseObject('TestingClass'))->save();
}

/**
* @group api-not-set
*/
public function testMountPathNotSet()
{
$this->setExpectedException(
'\Exception',
'Missing a valid mount path. '.
'You must call ParseClient::setServerURL(\'https://your.parse-server.com\', \'/parse\') '.
' before making any requests.'
);

ParseClient::_clearMountPath();
(new ParseObject('TestingClass'))->save();
}

/**
* @group bad-api-response
*/
Expand Down