-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from leancloud/cloud-run-remote
feat: runRemote for invokning cloud function remotely
- Loading branch information
Showing
4 changed files
with
87 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,40 @@ | ||
<?php | ||
|
||
use LeanCloud\Client; | ||
use LeanCloud\Engine\Cloud; | ||
use LeanCloud\User; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CloudTest extends TestCase { | ||
public static function setUpBeforeClass() { | ||
Client::initialize( | ||
getenv("LEANCLOUD_APP_ID"), | ||
getenv("LEANCLOUD_APP_KEY"), | ||
getenv("LEANCLOUD_APP_MASTER_KEY")); | ||
|
||
$user = new User(); | ||
$user->setUsername("alice"); | ||
$user->setPassword("blabla"); | ||
$user->setEmail("[email protected]"); | ||
try { | ||
$user->signUp(); | ||
} catch (CloudException $ex) { | ||
// skip | ||
} | ||
} | ||
|
||
public static function tearDownAfterClass() { | ||
// destroy default user if present | ||
try { | ||
$user = User::logIn("alice", "blabla"); | ||
$user->destroy(); | ||
} catch (CloudException $ex) { | ||
// skip | ||
} | ||
} | ||
|
||
|
||
|
||
public function testGetKeys() { | ||
$name = uniqid(); | ||
Cloud::define($name, function($params, $user) { | ||
|
@@ -53,6 +84,27 @@ public function testFunctionAcceptMeta() { | |
$this->assertEquals("10.0.0.1", $result); | ||
} | ||
|
||
public function testRemoteFunction() { | ||
// Assumes [LeanFunction] is deployed at this application's LeanEngine. | ||
// [LeanFunction]: https://github.com/leancloud/LeanFunction | ||
$response = Cloud::runRemote("hello", []); | ||
$result = $response["result"]; | ||
$this->assertEquals("Hello world!", $result); | ||
} | ||
|
||
public function testRemoteFunctionWithSession() { | ||
// See testRemoteFunction for dependencies. | ||
try { | ||
User::logIn("alice", "blabla"); | ||
} catch (\LeanCloud\CloudException $e) { | ||
// skip | ||
} | ||
$token = User::getCurrentSessionToken(); | ||
$response = Cloud::runRemote("echo-session-token", [], $token); | ||
$result = $response["result"]; | ||
$this->assertEquals($token, $result); | ||
} | ||
|
||
public function testClassHook() { | ||
forEach(array("beforeSave", "afterSave", | ||
"beforeUpdate", "afterUpdate", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters