Skip to content

Commit cf3b807

Browse files
committed
Merge remote-tracking branch 'upstream/master' into failing-test-502
2 parents 570832c + eedefb9 commit cf3b807

18 files changed

+200
-135
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
- run: npm ci
5353
- run: npm start
5454
- run: npm run lint
55+
- run: npm run test-stream
5556
- run: npm run test:coverage
5657
- run: npm run document-check
5758
- run: npm run document

.github/workflows/release-automated.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: release-automated
22
on:
33
push:
44
branches: [ master, release, alpha, beta ]
5+
env:
6+
NODE_VERSION: 18
7+
PHP_VERSION: 8.1
58
jobs:
69
release:
710
runs-on: ubuntu-latest
@@ -13,7 +16,7 @@ jobs:
1316
persist-credentials: false
1417
- uses: actions/setup-node@v3
1518
with:
16-
node-version: 18
19+
node-version: ${{ env.NODE_VERSION }}
1720
- run: npm ci
1821
- run: npx semantic-release
1922
env:
@@ -22,32 +25,30 @@ jobs:
2225
- name: Determine tag on current commit
2326
id: tag
2427
run: echo "::set-output name=current_tag::$(git describe --tags --abbrev=0 --exact-match || echo '')"
25-
publish-docs:
28+
docs-publish:
2629
needs: release
2730
if: needs.release.outputs.current_tag != ''
2831
runs-on: ubuntu-latest
32+
timeout-minutes: 15
2933
steps:
3034
- uses: actions/checkout@v3
3135
with:
3236
ref: ${{ needs.release.outputs.current_tag }}
3337
- name: Use Node.js
3438
uses: actions/setup-node@v3
3539
with:
36-
node-version: 16
37-
- name: Cache Node.js modules
38-
uses: actions/cache@v3
40+
node-version: ${{ env.NODE_VERSION }}
41+
- name: Setup PHP
42+
uses: shivammathur/setup-php@v2
3943
with:
40-
path: ~/.npm
41-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
42-
restore-keys: |
43-
${{ runner.os }}-node-
44+
php-version: ${{ env.PHP_VERSION }}
4445
- name: Generate Docs
4546
run: |
46-
npm ci
47+
composer install
4748
npm run document-check
48-
npm run documentation
49+
npm run document
4950
env:
50-
SOURCE_TAG: ${{ github.event.inputs.tag }}
51+
SOURCE_TAG: ${{ needs.release.outputs.current_tag }}
5152
- name: Deploy
5253
uses: peaceiris/actions-gh-pages@v3.7.3
5354
with:

.github/workflows/release-manual-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ on:
66
default: ''
77
description: 'Version tag:'
88
env:
9-
NODE_VERSION: 16.17.1
9+
NODE_VERSION: 18
1010
PHP_VERSION: 8.1
1111
jobs:
1212
docs-publish:
1313
if: github.event.inputs.tag != ''
14-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-latest
1515
timeout-minutes: 15
1616
steps:
1717
- uses: actions/checkout@v3

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# [2.1.0](https://github.com/parse-community/parse-php-sdk/compare/2.0.0...2.1.0) (2023-04-29)
2+
3+
4+
### Features
5+
6+
* Add `ParseUser::logInAs` method ([#486](https://github.com/parse-community/parse-php-sdk/issues/486)) ([5b4e102](https://github.com/parse-community/parse-php-sdk/commit/5b4e102e4513e82cca1ddcce9c2158f6187239c8))
7+
18
# [2.0.0](https://github.com/parse-community/parse-php-sdk/compare/1.6.0...2.0.0) (2023-04-27)
29

310
### Features

CONTRIBUTING.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ When committing, keep all lines to less than 80 characters, and try to
77
follow the existing style. Before creating a pull request, squash your commits
88
into a single commit. Please provide ample explanation in the commit message.
99

10-
In addition there's a pretty cool [class inheritance diagram](http://parseplatform.org/parse-php-sdk/graph_class.html) you can check out as well.
11-
1210
Installation
1311
------------
1412

@@ -28,15 +26,13 @@ To setup the Test Parse Server:
2826
* Run `npm install` from the project root to download the server and it's dependencies.
2927
* When you're ready to run tests use `npm start` from the project root to boot up the test server.
3028

31-
The embedded test server utilizes this [parse server test] project.
32-
It's setup with the appropriate configuration to run the php sdk test suite.
33-
Additionally it handles setting up mongodb for the server.
29+
The test server is setup with the appropriate configuration to run the php sdk test suite. Additionally it handles setting up mongodb for the server. If you have a mongodb instance already running, you can use `npm run server-only`.
3430

3531
If you have specific needs and would like to alter your test server you can fork and modify the aforementioned test project.
3632
Alternately you can configure a compatible test server as follows:
3733

3834
* [Setup a local Parse Server instance]
39-
* Add main.js in tests/cloudcode/cloud/ to your Parse Server configuration as a cloud code file
35+
* Add cloud-code.js in tests to your Parse Server configuration as a cloud code file
4036
* Ensure your App ID, REST API Key, and Master Key match those contained in tests/Parse/Helper.php
4137
* Add a mock push configuration, for example:
4238
```json
@@ -70,6 +66,10 @@ You may also run tests directly using phpunit as follows:
7066

7167
npm test
7268

69+
For debugging you can use the `print` function found in tests/Parse/Helper.php
70+
71+
Helper::print()
72+
7373
Make sure your code is linted with phpcs ([PSR-2 Coding Style]):
7474

7575
npm run lint
@@ -90,11 +90,13 @@ If you do not have XDebug tests will still run, just without coverage.
9090
Please make sure that any new functionality (or issues) you are working on are covered by tests when possible.
9191
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.
9292

93+
## Code of Conduct
94+
95+
This project adheres to the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to honor this code.
96+
9397
[Get Composer]: https://getcomposer.org/download/
9498
[Get npm]: https://www.npmjs.com/get-npm
95-
[Contributor License Agreement]: https://developers.facebook.com/opensource/cla
9699
[XDebug]: https://xdebug.org/
97-
[parse server test]: https://github.com/montymxb/parse-server-test
98100
[Setup a local Parse Server instance]: https://github.com/parse-community/parse-server#user-content-locally
99101
[PSR-2 Coding Style]: http://www.php-fig.org/psr/psr-2/
100102

README.md

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
1-
<p align="center">
2-
<img alt="Parse Platform" src="Assets/logo large.png" width="200">
3-
</a>
4-
</p>
5-
6-
<h2 align="center">Parse PHP SDK</h2>
7-
8-
<p align="center">
9-
The Parse PHP SDK gives you access to the powerful Parse Server backend from your PHP app or script.
10-
</p>
11-
12-
<p align="center">
13-
<a href="https://twitter.com/intent/follow?screen_name=parseplatform"><img alt="Follow on Twitter" src="https://img.shields.io/twitter/follow/parseplatform?style=social&label=Follow"></a>
14-
<a href="https://community.parseplatform.org/"><img alt="Join the conversation" src="https://img.shields.io/discourse/https/community.parseplatform.org/topics.svg"></a>
15-
<a href="LICENSE"><img alt="License" src="https://img.shields.io/badge/license-BSD-lightgrey.svg"></a>
16-
<a href="https://packagist.org/packages/parse/php-sdk"><img alt="All time downloads" src="https://poser.pugx.org/parse/php-sdk/downloads" /></a>
17-
</p>
18-
19-
<p align="center">
20-
<a href="https://codecov.io/gh/parse-community/parse-php-sdk"><img alt="Test coverage" src="https://codecov.io/gh/parse-community/parse-php-sdk/branch/master/graph/badge.svg"></a>
21-
<a href="#backers"><img alt="Backers on Open Collective" src="https://opencollective.com/parse-server/backers/badge.svg" /></a>
22-
<a href="#sponsors"><img alt="Sponsors on Open Collective" src="https://opencollective.com/parse-server/sponsors/badge.svg" /></a>
23-
<a href="https://packagist.org/packages/parse/php-sdk"><img alt="Latest stable version" src="https://poser.pugx.org/parse/php-sdk/v/stable" /></a>
24-
</p>
25-
<br>
26-
27-
For more information on Parse and its features, see [the website](https://parseplatform.org), [the PHP guide](https://docs.parseplatform.org/php/guide/) or [API Reference](https://parseplatform.org/parse-php-sdk/namespaces/Parse.html).
28-
29-
## Table of Contents
30-
- [Table of Contents](#table-of-contents)
1+
![parse-repository-header-sdk-php](https://user-images.githubusercontent.com/5673677/235324256-42e13836-b26a-4de0-a5c7-b979bc5aff2c.png)
2+
3+
---
4+
5+
[![Build Status CI release](https://github.com/parse-community/parse-php-sdk/workflows/ci/badge.svg?branch=master)](https://github.com/parse-community/parse-php-sdk/actions?query=workflow%3Aci+branch%3Amaster)
6+
[![Snyk Badge](https://snyk.io/test/github/parse-community/parse-php-sdk/badge.svg)](https://snyk.io/test/github/parse-community/parse-php-sdk)
7+
[![Coverage](http://codecov.io/github/parse-community/parse-php-sdk/coverage.svg?branch=master)](http://codecov.io/github/parse-community/parse-php-sdk?branch=master)
8+
[![auto-release](https://img.shields.io/badge/%F0%9F%9A%80-auto--release-9e34eb.svg)](https://github.com/parse-community/parse-dashboard/releases)
9+
10+
[![PHP Version](https://img.shields.io/badge/php-8.1,_8.2-green.svg?logo=php&style=flat)](https://php.org/)
11+
12+
[![packagist latest version](https://img.shields.io/packagist/v/parse/php-sdk)](https://packagist.org/packages/parse/php-sdk)
13+
14+
[![Backers on Open Collective](https://opencollective.com/parse-server/backers/badge.svg)][open-collective-link]
15+
[![Sponsors on Open Collective](https://opencollective.com/parse-server/sponsors/badge.svg)][open-collective-link]
16+
[![Forum](https://img.shields.io/discourse/https/community.parseplatform.org/topics.svg)](https://community.parseplatform.org/c/client-sdks/javascript-sdk)
17+
[![Twitter](https://img.shields.io/twitter/follow/ParsePlatform.svg?label=Follow&style=social)](https://twitter.com/intent/follow?screen_name=ParsePlatform)
18+
19+
---
20+
21+
A library that gives you access to the powerful Parse Server backend from your PHP app. For more information on Parse and its features, see [the website](https://parseplatform.org), [the PHP guide](https://docs.parseplatform.org/php/guide/), [the Cloud Code guide](https://docs.parseplatform.org/cloudcode/guide/) or [API Reference](https://parseplatform.org/parse-php-sdk/).
22+
23+
---
24+
25+
## Table of Contents <!-- omit in toc -->
26+
3127
- [Installation](#installation)
3228
- [Install with Composer](#install-with-composer)
3329
- [Install with Git](#install-with-git)
@@ -780,8 +776,7 @@ $logs = ParseLogs::getInfoLogs(10, $fromDate, $untilDate, 'asc');
780776

781777
## Contributing / Testing
782778

783-
See [CONTRIBUTING](CONTRIBUTING.md) for information on testing and contributing to
784-
the Parse PHP SDK. We welcome fixes and enhancements.
779+
See [CONTRIBUTING](CONTRIBUTING.md) for information on testing and contributing to the Parse PHP SDK.
785780

786781
-----
787782

package-lock.json

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"name": "parse-php-sdk",
33
"scripts": {
44
"test": "./vendor/bin/phpunit",
5-
"test:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --stderr --coverage-clover=coverage.xml",
6-
"test-stream:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --stderr --bootstrap=./tests/bootstrap-stream.php --coverage-clover=coverage.xml",
5+
"test-stream": "./vendor/bin/phpunit --bootstrap=./tests/bootstrap-stream.php",
6+
"test:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-clover=coverage.xml",
7+
"test-stream:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --bootstrap=./tests/bootstrap-stream.php --coverage-clover=coverage.xml",
78
"lint": "./vendor/bin/phpcs --standard=./phpcs.xml.dist ./src/Parse ./tests/Parse",
89
"lint:fix": "./vendor/bin/phpcbf --standard=./phpcs.xml.dist ./src/Parse ./tests/Parse",
910
"prestart": "MONGODB_VERSION=4.0.4 MONGODB_TOPOLOGY=replicaset MONGODB_STORAGE_ENGINE=wiredTiger mongodb-runner start",
@@ -30,5 +31,6 @@
3031
"parse-server": "github:parse-community/parse-server#alpha",
3132
"semantic-release": "21.0.1",
3233
"winston": "3.2.1"
33-
}
34+
},
35+
"version": "2.1.0"
3436
}

release.config.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ async function config() {
7979
'changelogFile': changelogFile,
8080
}],
8181
["@semantic-release/exec", {
82-
"prepareCmd": `sed -i '' -r "s/const VERSION_STRING = '.*'/const VERSION_STRING = '\${nextRelease.version}'/" ./src/Parse/ParseClient.php`
82+
// Update Parse SDK version
83+
"prepareCmd": `sed -i'' -r "s/const VERSION_STRING = '.*'/const VERSION_STRING = '\${nextRelease.version}'/" ./src/Parse/ParseClient.php`
8384
}],
8485
['@semantic-release/npm', {
8586
'npmPublish': false,

src/Parse/HttpClients/ParseStream.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,16 @@ public function get($url)
6161
{
6262
try {
6363
// get our response
64-
$response = file_get_contents($url, false, $this->stream);
64+
$response = $this->getFileContents($url, false, $this->stream);
6565
$this->errorMessage = null;
6666
$this->errorCode = null;
6767
} catch (\Exception $e) {
6868
// set our error message/code and return false
6969
$this->errorMessage = $e->getMessage();
7070
$this->errorCode = $e->getCode();
71+
$this->responseHeaders = null;
7172
return false;
7273
}
73-
74-
// set response headers
75-
$this->responseHeaders = $http_response_header;
76-
7774
return $response;
7875
}
7976

@@ -98,12 +95,22 @@ public function getErrorMessage()
9895
}
9996

10097
/**
101-
* Gest the current error code
98+
* Get the current error code
10299
*
103100
* @return int
104101
*/
105102
public function getErrorCode()
106103
{
107104
return $this->errorCode;
108105
}
106+
107+
/**
108+
* Wrapper for file_get_contents, used for testing
109+
*/
110+
public function getFileContents($filename, $use_include_path, $context)
111+
{
112+
$result = file_get_contents($filename, $use_include_path, $context);
113+
$this->responseHeaders = $http_response_header;
114+
return $result;
115+
}
109116
}

src/Parse/ParseClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ final class ParseClient
108108
*
109109
* @var string
110110
*/
111-
const VERSION_STRING = '2.0.0';
111+
const VERSION_STRING = '2.1.0';
112112

113113
/**
114114
* Parse\Client::initialize, must be called before using Parse features.
@@ -554,7 +554,7 @@ public static function _request(
554554
$response = $httpClient->send($url, $method, $data);
555555

556556
// check content type of our response
557-
$contentType = $httpClient->getResponseContentType();
557+
$contentType = $httpClient->getResponseContentType() || '';
558558

559559
if (strpos($contentType, 'text/html') !== false) {
560560
throw new ParseException('Bad Request', -1);

src/Parse/ParseUser.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,33 @@ public static function logIn($username, $password)
157157
return $user;
158158
}
159159

160+
/**
161+
* Uses the master key to log in and return a valid ParseUser, or throws if invalid.
162+
*
163+
* @param $userId
164+
*
165+
* @throws ParseException
166+
*
167+
* @return ParseUser
168+
*/
169+
public static function logInAs($userId)
170+
{
171+
if (!$userId) {
172+
throw new ParseException(
173+
'Cannot log in as user with an empty user id',
174+
200
175+
);
176+
}
177+
$data = ['userId' => $userId];
178+
$result = ParseClient::_request('POST', 'loginAs', '', json_encode($data), true);
179+
$user = new static();
180+
$user->_mergeAfterFetch($result);
181+
$user->handleSaveResult(true);
182+
ParseClient::getStorage()->set('user', $user);
183+
184+
return $user;
185+
}
186+
160187
/**
161188
* Logs in with Facebook details, or throws if invalid.
162189
*

tests/Parse/ParseClientTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ public function testStreamConnectionTimeout()
321321
*/
322322
public function testNoCurlExceptions()
323323
{
324+
global $USE_CLIENT_STREAM;
325+
if (isset($USE_CLIENT_STREAM)) {
326+
$this->markTestSkipped('Skipping curl exception test');
327+
}
324328
Helper::setUpWithoutCURLExceptions();
325329

326330
ParseClient::setServerURL('http://404.example.com', 'parse');
@@ -656,7 +660,11 @@ public function testCheckBadServer()
656660

657661
ParseClient::setServerURL('http://___uh___oh___.com', 'parse');
658662
$health = ParseClient::getServerHealth();
659-
$this->assertTrue(isset($health['error']));
660-
$this->assertTrue(isset($health['error_message']));
663+
664+
global $USE_CLIENT_STREAM;
665+
if (!isset($USE_CLIENT_STREAM)) {
666+
$this->assertTrue(isset($health['error']));
667+
$this->assertTrue(isset($health['error_message']));
668+
}
661669
}
662670
}

0 commit comments

Comments
 (0)