Skip to content

Commit 194d5ba

Browse files
author
Benjamin Wilson Friedman
authored
Updated Tests & SDK for Open Source Parse Server (#280)
-Updates test cases to work with open source parse-sever and to generally increase coverage overall. Coverage bumped to 95% and slight changes to internal classes to help with testing. -Updated tests to address $this->expectException not being present in older versions of phpunit, particularly that which comes with composer. -Updated CONTRIBUTING with new method for running tests.
1 parent ffa336d commit 194d5ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2608
-107
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.idea
22
composer.lock
33
vendor
4+
5+
# ignore test results
6+
phpunit-test-results

CONTRIBUTING.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,64 @@ into a single commit. Please provide ample explanation in the commit message.
1111
Installation
1212
------------
1313

14-
Testing the Parse PHP SDK involves some set-up. You'll need to create a Parse
15-
App just for testing, and deploy some cloud code to it.
14+
Testing the Parse PHP SDK requires having a working Parse Server instance to run against.
15+
Additionally you'll need to add some cloud code to it.
16+
17+
To get started:
1618

1719
* [Get Composer], the PHP package manager.
1820
* Run "composer install" to download dependencies.
19-
* Create a new app here: [Create Parse App]
20-
* Use the Parse CLI to create a Cloud Code folder for the new app.
21-
* Copy tests/cloudcode/cloud/main.js into the newly created cloud/ folder.
22-
* Run "parse deploy" in your cloud folder.
23-
* Paste your App ID, REST API Key, and Master Key in tests/Parse/Helper.php
2421

25-
You should now be able to execute, from project root folder:
22+
From here you have to setup an instance of parse server.
23+
24+
To get started quickly you can clone and run this [parse server test] project.
25+
It's setup with the appropriate configuration to run the php sdk test suite.
26+
Additionally it handles setting up mongodb for the server.
27+
28+
Alternately you can configure a compatible test server as follows:
29+
30+
* [Setup a local Parse Server instance]
31+
* Add main.js in tests/cloudcode/cloud/ to your Parse Server configuration as a cloud code file
32+
* Ensure your App ID, REST API Key, and Master Key match those contained in tests/Parse/Helper.php
33+
* Add a mock push configuration, for example:
34+
```json
35+
{
36+
"android":
37+
{
38+
"senderId": "blank-sender-id",
39+
"apiKey": "not-a-real-api-key"
40+
}
41+
}
42+
```
43+
* Add a mock email adapter configuration, for example:
44+
```json
45+
{
46+
"module": "parse-server-simple-mailgun-adapter",
47+
"options": {
48+
"apiKey": "not-a-real-api-key",
49+
"domain": "example.com",
50+
"fromAddress": "[email protected]"
51+
}
52+
}
53+
```
54+
* Ensure the public url is correct. For a locally hosted instance this is probably ```http://localhost:1337/parse```
55+
56+
57+
You should now be able to execute the tests, from project root folder:
58+
59+
./vendor/bin/phpunit
60+
61+
The test suite is setup for code coverage if you have [XDebug] installed and setup.
62+
Coverage is outputted as text and as html in the phpunit-test-results/ directory within the project root.
2663

27-
./vendor/bin/phpunit --stderr .
64+
If you do not have XDebug tests will still run, just without coverage.
2865

29-
At present the full suite of tests takes around 20 minutes.
66+
Please make sure that any new functionality (or issues) you are working on are covered by tests when possible.
67+
If you have XDebug setup and can view code coverage please ensure that you do your best to completely cover any new code you are adding.
3068

3169
[Get Composer]: https://getcomposer.org/download/
3270
[Contributor License Agreement]: https://developers.facebook.com/opensource/cla
3371
[Create Parse App]: https://parse.com/apps/new
72+
[XDebug]: https://xdebug.org/
73+
[parse server test]: https://github.com/montymxb/parse-server-test
74+
[Setup a local Parse Server instance]: https://github.com/ParsePlatform/parse-server#user-content-locally

phpunit.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,13 @@
2020
<directory suffix="Test.php">./tests</directory>
2121
</testsuite>
2222
</testsuites>
23+
<filter>
24+
<whitelist processUncoveredFilesFromWhitelist="true">
25+
<directory suffix=".php">./src/Parse</directory>
26+
</whitelist>
27+
</filter>
28+
<logging>
29+
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
30+
<log type="coverage-html" target="phpunit-test-results/" showUncoveredFiles="true"/>
31+
</logging>
2332
</phpunit>

src/Parse/Internal/AddUniqueOperation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Parse\ParseClient;
66
use Parse\ParseException;
7+
use Parse\ParseObject;
78

89
/**
910
* Class AddUniqueOperation - Operation to add unique objects to an array key.

src/Parse/Internal/ParseRelationOperation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public function __construct($objectsToAdd, $objectsToRemove)
6363
*/
6464
private function checkAndAssignClassName($objects)
6565
{
66+
if(!is_array($objects)) {
67+
$objects = [$objects];
68+
69+
}
70+
6671
foreach ($objects as $object) {
6772
if ($this->targetClassName === null) {
6873
$this->targetClassName = $object->getClassName();

src/Parse/Internal/RemoveOperation.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ public function _apply($oldValue, $obj, $key)
105105
if (empty($oldValue)) {
106106
return [];
107107
}
108+
109+
if(!is_array($oldValue)) {
110+
$oldValue = [$oldValue];
111+
112+
}
113+
108114
$newValue = [];
109115
foreach ($oldValue as $oldObject) {
110116
foreach ($this->objects as $newObject) {

src/Parse/ParseACL.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ public static function _getDefaultACL()
548548
return self::$defaultACL;
549549
}
550550
if ($last != ParseUser::getCurrentUser()) {
551-
self::$defaultACLWithCurrentUser = clone self::$defaultAC;
551+
self::$defaultACLWithCurrentUser = clone self::$defaultACL;
552552
self::$defaultACLWithCurrentUser->_setShared(true);
553553
self::$defaultACLWithCurrentUser->setUserReadAccess(ParseUser::getCurrentUser(), true);
554554
self::$defaultACLWithCurrentUser->setUserWriteAccess(ParseUser::getCurrentUser(), true);

src/Parse/ParseApp.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function fetchApps()
2424
'apps',
2525
null,
2626
null,
27-
false,
27+
true,
2828
true
2929
);
3030

@@ -47,7 +47,7 @@ public static function fetchApp($application_id)
4747
'apps/'.$application_id,
4848
null,
4949
null,
50-
false,
50+
true,
5151
true
5252
);
5353

@@ -70,7 +70,7 @@ public static function createApp(array $data)
7070
'apps',
7171
null,
7272
json_encode($data),
73-
false,
73+
true,
7474
true
7575
);
7676

@@ -94,7 +94,7 @@ public static function updateApp($application_id, array $data)
9494
'apps/'.$application_id,
9595
null,
9696
json_encode($data),
97-
false,
97+
true,
9898
true
9999
);
100100

src/Parse/ParseClient.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,10 @@ public static function _request(
323323
$data = '{}';
324324
}
325325
if ($appRequest) {
326+
// 'app' requests are not available in open source parse-server
326327
self::assertAppInitialized();
327328
$headers = self::_getAppRequestHeaders();
329+
328330
} else {
329331
self::assertParseInitialized();
330332
$headers = self::_getRequestHeaders($sessionToken, $useMasterKey);

src/Parse/ParseConfig.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@ protected function setConfig($config)
3838
{
3939
$this->currentConfig = $config;
4040
}
41+
42+
public function getConfig()
43+
{
44+
return $this->currentConfig;
45+
46+
}
4147
}

0 commit comments

Comments
 (0)