Skip to content

Commit b760ca3

Browse files
author
Benjamin Wilson Friedman
authored
Remove Default API (#332)
* Removed default api and added appropriate checking * lint
1 parent 592e376 commit b760ca3

File tree

2 files changed

+83
-6
lines changed

2 files changed

+83
-6
lines changed

src/Parse/ParseClient.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ final class ParseClient
2424
*
2525
* @var string
2626
*/
27-
private static $serverURL = 'https://api.parse.com/';
27+
private static $serverURL = null;
2828

2929
/**
3030
* The mount path for the current parse server
3131
*
3232
* @var string
3333
*/
34-
private static $mountPath = "1/";
34+
private static $mountPath = null;
3535

3636
/**
3737
* The application id.
@@ -193,6 +193,24 @@ public static function setServerURL($serverURL, $mountPath)
193193
}
194194
}
195195

196+
/**
197+
* Clears the existing server url.
198+
* Used primarily for testing purposes.
199+
*/
200+
public static function _clearServerURL()
201+
{
202+
self::$serverURL = null;
203+
}
204+
205+
/**
206+
* Clears the existing mount path.
207+
* Used primarily for testing purposes.
208+
*/
209+
public static function _clearMountPath()
210+
{
211+
self::$mountPath = null;
212+
}
213+
196214
/**
197215
* Sets the Http client to use for requests
198216
*
@@ -408,6 +426,9 @@ public static function _request(
408426
$httpClient->setCAFile(self::$caFile);
409427
}
410428

429+
// verify the server url and mount path have been set
430+
self::assertServerInitialized();
431+
411432
if ($appRequest) {
412433
// ** 'app' requests are not available in open source parse-server
413434
self::assertAppInitialized();
@@ -570,6 +591,30 @@ public static function _unsetStorage()
570591
self::$storage = null;
571592
}
572593

594+
/**
595+
* Asserts that the server and mount path have been initialized
596+
*
597+
* @throws Exception
598+
*/
599+
private static function assertServerInitialized()
600+
{
601+
if (self::$serverURL === null) {
602+
throw new Exception(
603+
'Missing a valid server url. '.
604+
'You must call ParseClient::setServerURL(\'https://your.parse-server.com\', \'/parse\') '.
605+
' before making any requests.'
606+
);
607+
}
608+
609+
if (self::$mountPath === null) {
610+
throw new Exception(
611+
'Missing a valid mount path. '.
612+
'You must call ParseClient::setServerURL(\'https://your.parse-server.com\', \'/parse\') '.
613+
' before making any requests.'
614+
);
615+
}
616+
}
617+
573618
/**
574619
* Asserts that the sdk has been initialized with a valid application id
575620
*
@@ -579,7 +624,7 @@ private static function assertParseInitialized()
579624
{
580625
if (self::$applicationId === null) {
581626
throw new Exception(
582-
'You must call Parse::initialize() before making any requests.'
627+
'You must call ParseClient::initialize() before making any requests.'
583628
);
584629
}
585630
}
@@ -593,7 +638,7 @@ private static function assertAppInitialized()
593638
{
594639
if (self::$accountKey === null || empty(self::$accountKey)) {
595640
throw new Exception(
596-
'You must call Parse::initialize(..., $accountKey) before making any app requests. '.
641+
'You must call ParseClient::initialize(..., $accountKey) before making any app requests. '.
597642
'Your account key must not be null or empty.'
598643
);
599644
}

tests/Parse/ParseClientTest.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testParseNotInitialized()
4747
{
4848
$this->setExpectedException(
4949
'\Exception',
50-
'You must call Parse::initialize() before making any requests.'
50+
'You must call ParseClient::initialize() before making any requests.'
5151
);
5252

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

@@ -519,6 +519,38 @@ public function testStreamCAFile()
519519
);
520520
}
521521

522+
/**
523+
* @group api-not-set
524+
*/
525+
public function testURLNotSet()
526+
{
527+
$this->setExpectedException(
528+
'\Exception',
529+
'Missing a valid server url. '.
530+
'You must call ParseClient::setServerURL(\'https://your.parse-server.com\', \'/parse\') '.
531+
' before making any requests.'
532+
);
533+
534+
ParseClient::_clearServerURL();
535+
(new ParseObject('TestingClass'))->save();
536+
}
537+
538+
/**
539+
* @group api-not-set
540+
*/
541+
public function testMountPathNotSet()
542+
{
543+
$this->setExpectedException(
544+
'\Exception',
545+
'Missing a valid mount path. '.
546+
'You must call ParseClient::setServerURL(\'https://your.parse-server.com\', \'/parse\') '.
547+
' before making any requests.'
548+
);
549+
550+
ParseClient::_clearMountPath();
551+
(new ParseObject('TestingClass'))->save();
552+
}
553+
522554
/**
523555
* @group bad-api-response
524556
*/

0 commit comments

Comments
 (0)