Skip to content

Commit

Permalink
update unit tests & doc
Browse files Browse the repository at this point in the history
  • Loading branch information
lanlin committed Sep 30, 2021
1 parent b96f077 commit daf4ee9
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codequality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: php-cs-fixer:2.16.4
php-version: '8.0'
tools: php-cs-fixer:3.1.0

- name: Code Reformatting...
run: php-cs-fixer fix -v --allow-risky=yes --config=./.php_cs
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
coverage: pcov

- name: Validate composer.json and composer.lock
Expand All @@ -37,6 +37,4 @@ jobs:
run: composer install --prefer-dist --no-progress

- name: Run test suite
env:
TESTING_ENVS: ${{ secrets.TESTING_ENVS }}
run: composer run-script test
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,36 @@
[![License](https://img.shields.io/github/license/lanlin/nylas-php)](https://github.com/lanlin/nylas-php#license)

PHP bindings for the Nylas REST API (V2.2). https://docs.nylas.com/reference</br>
I'll try to keep up with [NyLas Changelog](https://changelog.nylas.com) in future updates.
I'll try to keep up with [NyLas API Changelog](https://changelog.nylas.com/labels/api) in future updates.

Last check at the point: [Dashboard Release for Canada and Ireland](https://changelog.nylas.com/#entry-176451)
Last check at the point: [Node SDK v5.8.0 is released (2021-09-17)](https://changelog.nylas.com/publications/node-sdk-v5-8-0-is-released)

**What's new?**</br>

1. API 2.2 support</br>
1. API 2.2 & 2.3 beta support</br>
2. All Nylas APIs have been implemented within this SDK.</br>
3. Support send & get message in raw type</br>
4. Support async batch upload & download</br>
-- Contact picture download</br>
-- File upload & download<br>
5. The parameters that required by methods almost the same as nylas official api required.</br>
6. Support async batch get & delete & send (since version 3.1).
6. Support async batch get & delete & send
7. Chained calls and good code hints, easy to use</br>

## Installation (PHP 7.4 required since version 4.0)
## Installation (PHP 8.0 required since version 5.0)

**version 3.x for php >= 7.3 (branch 3.0)**

**version 4.x for php >= 7.4 (branch 4.0)**

**version 5.x for php >= 8.0 (branch master)**

Tips: There are many breaking changes since version 5.0

1. all methods name changed (named same as the nylas API doc describe title)
2. the smart methods removed
3. many other changes

This library is available on https://packagist.org/packages/lanlin/nylas-php</br>
You can install it by running

Expand All @@ -63,14 +69,13 @@ use Nylas\Client;

$options =
[
'client_id' => 'your client id', // required
'client_secret' => 'your client secret' // required

'debug' => true,
'region' => 'us', // server region, can be us, ireland or canada, default is us
'log_file' => dirname(__FILE__) . '/test.log', // a file path or a resource handler
'account_id' => 'your account id',
'access_token' => 'your access token',

'client_id' => 'your client id', // required
'client_secret' => 'your client secret' // required
];

$nylas = new Client($options);
Expand All @@ -93,12 +98,12 @@ $id = 'id_xxx';
$ids = ['id_xxx', 'id_yyy', ...];

// one per time
$dataA = $nylas->Contacts->Contact->getContact($id);
$dataB = $nylas->Contacts->Contact->deleteContact($id);
$dataA = $nylas->Contacts->Contact->returnAContact($id);
$dataB = $nylas->Contacts->Contact->deleteAContact($id);

// batch request
$dataC = $nylas->Contacts->Contact->getContact($ids);
$dataD = $nylas->Contacts->Contact->deleteContact($ids);
$dataC = $nylas->Contacts->Contact->returnAContact($ids);
$dataD = $nylas->Contacts->Contact->deleteAContact($ids);
```

For more detail about the batch request, you should have to read the source code.</br>
Expand Down
Binary file removed media/autocomplete.gif
Binary file not shown.
Binary file removed media/options.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Webhooks/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function returnAWebhook(string $webhookId): array
*
* @return array
*/
public function updateWebhook(string $webhookId, bool $enable = true): array
public function updateAWebhook(string $webhookId, bool $enable = true): array
{
$params = ['state' => $enable ? 'active' : 'inactive'];

Expand Down
4 changes: 2 additions & 2 deletions tests/Messages/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function testSearchMessage(): void

$this->mockResponse($this->getSearchData());

$data = $this->client->Messages->Search->messages($q);
$data = $this->client->Messages->Search->searchMessages($q);

$this->assertTrue(\count($data) > 0);
$this->assertArrayHasKey('account_id', $data[0]);
}

// ------------------------------------------------------------------------------
Expand Down
14 changes: 12 additions & 2 deletions tests/Rooms/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@ class ResourceTest extends AbsCase

public function testReturnAllMessagesToBeSent(): void
{
$this->mockResponse([]);
$this->mockResponse([
[
'object' => 'room_resource',
'email' => '[email protected]',
'name' => 'Training Room 1A',
'capacity' => '8',
'building' => 'West Building',
'floor_name' => '7',
'floor_number' => '7',
],
]);

$data = $this->client->Rooms->Resource->returnRoomResourceInformation();

$this->assertArrayHasKey('account_id', $data[0]);
$this->assertArrayHasKey('email', $data[0]);
}

// ------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions tests/Threads/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function testSearchThread(): void

$this->mockResponse($this->getSearchData());

$data = $this->client->Threads->Search->threads($q);
$data = $this->client->Threads->Search->searchThreads($q);

$this->assertTrue(\count($data) > 0);
$this->assertArrayHasKey('account_id', $data[0]);
}

// ------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions tests/Threads/ThreadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testReturnAllThreads(): void

$data = $this->client->Threads->Thread->returnsAllThreads($para);

$this->assertTrue(!empty($data[0]['id']));
$this->assertArrayHasKey('account_id', $data[0]);
}

// ------------------------------------------------------------------------------
Expand All @@ -55,7 +55,7 @@ public function testReturnAThread(): void
{
$id = $this->faker->uuid;

$this->mockResponse([$id => $this->getThreadBaseData()]);
$this->mockResponse([$this->getThreadBaseData()]);

$data = $this->client->Threads->Thread->returnsAThread($id);

Expand All @@ -79,7 +79,7 @@ public function testUpdateAThread(): void

$data = $this->client->Threads->Thread->updateAThread($id, $params);

$this->assertArrayHasKey('id', $data);
$this->assertArrayHasKey('account_id', $data);
}

// ------------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions tests/Utilities/OptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public function testOptions(): void

$data = $options->getAllOptions();

unset($data['server'], $data['access_token']);

$this->assertSame($optionsData, $data);
$this->assertArrayHasKey('log_file', $data);
}

// ------------------------------------------------------------------------------
Expand Down
62 changes: 62 additions & 0 deletions tests/Webhooks/SignatureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Tests\Webhooks;

use Exception;
use Tests\AbsCase;

/**
* ----------------------------------------------------------------------------------
* Webhook Test
* ----------------------------------------------------------------------------------
*
* @author lanlin
* @change 2021/09/30
*
* @internal
*/
class SignatureTest extends AbsCase
{
// ------------------------------------------------------------------------------

public function testEchoChallenge(): void
{
$this->client->Webhooks->Signature->echoChallenge();

$this->assertPassed();
}

// ------------------------------------------------------------------------------

public function testGetNotification(): void
{
$this->expectException(Exception::class);

$this->client->Webhooks->Signature->getNotification();
}

// ------------------------------------------------------------------------------

public function testParseNotification(): void
{
$params = \json_encode(['deltas' => ['aaa' => 'bbb']]);

$data = $this->client->Webhooks->Signature->parseNotification($params);

$this->assertArrayHasKey('aaa', $data);
}

// ------------------------------------------------------------------------------

public function testXSignatureVerification(): void
{
$para = $this->faker->name;
$code = $this->faker->uuid;

$data = $this->client->Webhooks->Signature->xSignatureVerification($code, $para);

$this->assertFalse($data);
}

// ------------------------------------------------------------------------------
}
Loading

0 comments on commit daf4ee9

Please sign in to comment.