Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…sdk-php into migration
  • Loading branch information
Simply007 committed Sep 14, 2022
2 parents 0ea8d1b + 5118f36 commit 1f7eae6
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.0', '7.1', '7.2', '7.3']
php-versions: ['7.3', '7.4', '8.0', '8.1']
phpunit-versions: ['latest']

steps:
Expand Down
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,23 @@ composer.phar
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock
/.vs

# Created by https://www.toptal.com/developers/gitignore/api/phpunit
# Edit at https://www.toptal.com/developers/gitignore?templates=phpunit

### PHPUnit ###
# Covers PHPUnit
# Reference: https://phpunit.de/

# Generated files
.phpunit.result.cache
.phpunit.cache

# PHPUnit
/app/phpunit.xml
/phpunit.xml

# Build data
/build/

# End of https://www.toptal.com/developers/gitignore/api/phpunit
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Summary

The Kontent Delivery PHP SDK is a client library used for retrieving content from Kontent by Kentico. The best way to use the SDK is to consume it in the form of a [Packagist package](https://packagist.org/packages/kentico/kontent-delivery-sdk-php). The library currently supports only PHP 7 and above.
The Kontent Delivery PHP SDK is a client library used for retrieving content from Kontent by Kentico. The best way to use the SDK is to consume it in the form of a [Packagist package](https://packagist.org/packages/kentico/kontent-delivery-sdk-php). The library currently supports only PHP 8 and above.

## Sample site

Expand Down Expand Up @@ -45,7 +45,7 @@ require __DIR__ . '/vendor/autoload.php';

The `DeliveryClient` class is the main class of the SDK. Using this class, you can retrieve content from your Kontent projects.

To create an instance of the class, you need to provide a [project ID](https://docs.kontent.ai/tutorials/develop-apps/get-content/getting-content#section-getting-content-items).
To create an instance of the class, you need to provide a [project ID](https://kontent.ai/learn/tutorials/develop-apps/get-content/get-content-items#a-1-find-your-project-id).

```php
use Kontent\Ai\Delivery\DeliveryClient;
Expand All @@ -58,7 +58,7 @@ There are some other optional parameters that you can use during the `DeliveryCl

* `$previewApiKey` – sets the Delivery Preview API key. The client will automatically start using the preview endpoint for querying. See [previewing unpublished content](#previewing-unpublished-content).
* `$securedProductionApiKey` – sets the production Delivery API key (do not combine it with the Delivery Preview API key)
* `$waitForLoadingNewContent` – makes the client instance wait while fetching updated content, useful when acting upon [webhook calls](https://docs.kontent.ai/tutorials/develop-apps/integrate/using-webhooks-for-automatic-updates#section-requesting-new-content).
* `$waitForLoadingNewContent` – makes the client instance wait while fetching updated content, useful when acting upon [webhook calls](https://kontent.ai/learn/tutorials/develop-apps/integrate/webhooks#a-get-the-latest-content).
* `$debugRequests` – switches the HTTP client to debug mode
* `$retryAttempts` – number of times the client will retry to connect to the Kontent API on failures per request

Expand All @@ -78,7 +78,7 @@ $items = $client->getItems();

### Filtering retrieved data

The SDK supports full scale of the API querying and filtering capabilities as described in the [API reference](https://docs.kontent.ai/reference/delivery-api#tag/Filtering-content).
The SDK supports full scale of the API querying and filtering capabilities as described in the [API reference](https://kontent.ai/learn/reference/delivery-api#tag/Filtering-content).

```php
use Kontent\Ai\Delivery\QueryParams;
Expand Down Expand Up @@ -111,7 +111,7 @@ $response = $client->getItems((new QueryParams())

### Working with taxonomies

To retrieve information about your taxonomies, you can use the `getTaxonomy` and `getTaxonomies` methods. Additionally, you can specify query [parameters](https://docs.kontent.ai/reference/delivery-api#operation/list-taxonomy-groups).
To retrieve information about your taxonomies, you can use the `getTaxonomy` and `getTaxonomies` methods. Additionally, you can specify query [parameters](https://kontent.ai/learn/reference/delivery-api#operation/list-taxonomy-groups).

```php
use Kontent\Ai\Delivery\QueryParams;
Expand All @@ -134,11 +134,11 @@ To retrieve unpublished content, you need to create a `DeliveryClient` with both
$client = new DeliveryClient('YOUR_PROJECT_ID', 'YOUR_PREVIEW_API_KEY');
```

For more details, see [Previewing unpublished content using the Delivery API](https://docs.kontent.ai/tutorials/write-and-collaborate/preview-content/previewing-unpublished-content).
For more details, see [Previewing unpublished content using the Delivery API](https://kontent.ai/learn/tutorials/develop-apps/build-strong-foundation/set-up-preview#a-get-the-latest-version-of-everything).

## Response structure

For full description of single and multiple content item JSON response formats, see our [API reference](https://docs.kontent.ai/reference/delivery-api#operation/list-content-items).
For full description of single and multiple content item JSON response formats, see our [API reference](https://kontent.ai/learn/reference/delivery-api#operation/list-content-items).

### Single content item response

Expand Down
84 changes: 44 additions & 40 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
{
"name": "kontent-ai/delivery-sdk-php",
"type": "library",
"license": "MIT",
"description": "Kontent.ai Delivery SDK for PHP",
"keywords": [
"delivery",
"content-delivery",
"headless",
"cms",
"kontent-ai",
"headless-cms"
],
"homepage": "https://kontent.ai/",
"authors": [
{
"name": "Kontent.ai DevRel",
"email": "[email protected]"
},
{
"name": "Stephen Rushing",
"email": "[email protected]"
}
],
"require": {
"php": "^7.0",
"nategood/httpful": "^0.2.20",
"kub-at/php-simple-html-dom-parser": "^1.9"
},
"require-dev": {
"phpdocumentor/phpdocumentor": "2.*",
"codeclimate/php-test-reporter": "dev-master",
"phpunit/phpunit": "^6.4"
},
"autoload": {
"psr-4": {
"Kontent\\Ai\\": "src/Kontent/Ai"
}
}
}
{
"name": "kontent-ai/delivery-sdk-php",
"type": "library",
"license": "MIT",
"description": "Kontent.ai Delivery SDK for PHP",
"keywords": [
"delivery",
"content-delivery",
"headless",
"cms",
"kontent-ai",
"headless-cms"
],
"homepage": "https://kontent.ai/",
"authors": [
{
"name": "Kontent.ai DevRel",
"email": "[email protected]"
},
{
"name": "Stephen Rushing",
"email": "[email protected]"
}
],
"require": {
"php": "^7.0 || ^8.0",
"nategood/httpful": "^0.2.20",
"kub-at/php-simple-html-dom-parser": "^1.9"
},
"require-dev": {
"phpdocumentor/shim": "^3.3",
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
"Kontent\\Ai\\": "src/Kontent/Ai"
}
},
"config": {
"allow-plugins": {
"phpdocumentor/shim": true
}
}
}
43 changes: 22 additions & 21 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="e2e">
<directory>tests/E2E</directory>
</testsuite>
<testsuite name="official">
<directory>tests/Official</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<testsuites>
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="e2e">
<directory>tests/E2E</directory>
</testsuite>
<testsuite name="official">
<directory>tests/Official</directory>
</testsuite>
</testsuites>
<logging/>
</phpunit>
2 changes: 1 addition & 1 deletion src/Kontent/Ai/Delivery/DeliveryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class DeliveryClient
{
private $sdkVersion = '4.0.0';
private $sdkVersion = '5.0.0';

private $urlBuilder = null;
private $previewMode = false;
Expand Down
8 changes: 4 additions & 4 deletions tests/E2E/DeliveryClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function testGetArticleWithLinksItem()
$this->assertEquals('coffee-processing-techniques', $item->urlPattern);
$this->assertInstanceOf(\Kontent\Ai\Delivery\Models\Items\ContentItemSystem::class, $item->system);
$this->assertInstanceOf(\Kontent\Ai\Delivery\Models\Items\ContentItemSystem::class, $item->system);
$this->assertContains('<a data-item-id="80c7074b-3da1-4e1d-882b-c5716ebb4d25" href="/kenya-gakuyuni-aa">Kenya Gakuyuni AA</a>', $item->bodyCopy);
$this->assertContains('<a data-item-id="0c9a11bb-6fc3-409c-b3cb-f0b797e15489" href="/brazil-natural-barra-grande">Brazil Natural Barra Grande</a>', $item->bodyCopy);
$this->assertStringContainsString('<a data-item-id="80c7074b-3da1-4e1d-882b-c5716ebb4d25" href="/kenya-gakuyuni-aa">Kenya Gakuyuni AA</a>', $item->bodyCopy);
$this->assertStringContainsString('<a data-item-id="0c9a11bb-6fc3-409c-b3cb-f0b797e15489" href="/brazil-natural-barra-grande">Brazil Natural Barra Grande</a>', $item->bodyCopy);
}

public function testGetHomeItem()
Expand All @@ -43,7 +43,7 @@ public function testGetHomeItem()
$this->assertEquals('1bd6ba00-4bf2-4a2b-8334-917faa686f66', $item->system->id);
$this->assertInstanceOf(\DateTime::class, $item->system->getLastModifiedDateTime());
$this->assertInstanceOf(\DateTime::class, $item->system->lastModified);
$this->assertRegExp('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $item->system->getLastModifiedDateTime('Y-m-d'));
$this->assertMatchesRegularExpression('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $item->system->getLastModifiedDateTime('Y-m-d'));
}

public function testGetNonExistentItem()
Expand Down Expand Up @@ -71,7 +71,7 @@ public function testNumber()
{
$client = new DeliveryClient($this->getProjectId());
$item = $client->getItem('brazil_natural_barra_grande');
$this->assertInternalType('float', $item->price);
$this->assertIsFloat($item->price);
$this->assertEquals(8.5, $item->price);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/E2E/ModelBindingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function testGetArticleWithLinks_LinksUrlResolved()
$this->assertEquals('117cdfae-52cf-4885-b271-66aef6825612', $item->system->id);
$this->assertEquals('Coffee processing techniques', $item->title);
$this->assertEquals('coffee-processing-techniques', $item->urlPattern);
$this->assertContains('<a data-item-id="80c7074b-3da1-4e1d-882b-c5716ebb4d25" href="/custom/kenya-gakuyuni-aa">Kenya Gakuyuni AA</a>', $item->bodyCopy);
$this->assertContains('<a data-item-id="0c9a11bb-6fc3-409c-b3cb-f0b797e15489" href="/custom/brazil-natural-barra-grande">Brazil Natural Barra Grande</a>', $item->bodyCopy);
$this->assertStringContainsString('<a data-item-id="80c7074b-3da1-4e1d-882b-c5716ebb4d25" href="/custom/kenya-gakuyuni-aa">Kenya Gakuyuni AA</a>', $item->bodyCopy);
$this->assertStringContainsString('<a data-item-id="0c9a11bb-6fc3-409c-b3cb-f0b797e15489" href="/custom/brazil-natural-barra-grande">Brazil Natural Barra Grande</a>', $item->bodyCopy);
}

public function testHomeModel()
Expand Down
12 changes: 6 additions & 6 deletions tests/Official/CodeExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class CodeExamplesTests extends TestCase
{
protected function setUp()
protected function setUp(): void
{
$this->client = new DeliveryClient('975bf280-fd91-488c-994c-2f04416e5ee3');
}
Expand All @@ -33,7 +33,7 @@ public function test_ListContentItems()

$this->assertNotNull($items);
$this->assertNotNull($items->items);
$this->assertInternalType('array', $items->items);
$this->assertIsArray($items->items);
}

public function test_OneType()
Expand All @@ -49,7 +49,7 @@ public function test_ThreeTypes()

$this->assertNotNull($types);
$this->assertNotNull($types->types);
$this->assertInternalType('array', $types->types);
$this->assertIsArray($types->types);
}

public function test_contentTypeElement()
Expand All @@ -66,7 +66,7 @@ public function test_getTaxonomyGroup()

$this->assertNotNull($taxonomies);
$this->assertNotNull($taxonomies->taxonomies);
$this->assertInternalType('array', $taxonomies->taxonomies);
$this->assertIsArray($taxonomies->taxonomies);
}

public function test_getFiveLatestArticles()
Expand All @@ -79,7 +79,7 @@ public function test_getFiveLatestArticles()

$this->assertNotNull($items);
$this->assertNotNull($items->items);
$this->assertInternalType('array', $items->items);
$this->assertIsArray($items->items);
}

public function test_getArticlesWithTaxonomyTerm()
Expand All @@ -89,7 +89,7 @@ public function test_getArticlesWithTaxonomyTerm()

$this->assertNotNull($items);
$this->assertNotNull($items->items);
$this->assertInternalType('array', $items->items);
$this->assertIsArray($items->items);
}

public function test_getContentInSpecificLanguageWithFallback()
Expand Down
18 changes: 9 additions & 9 deletions tests/Unit/ModelBinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public function test_BindModel_LinksCorrectlyResolved()
$model = $modelBinder->bindModel(\Kontent\Ai\Delivery\Models\Items\ContentItem::class, $data);

// Test content links
$this->assertContains('<a data-item-id="00000000-0000-0000-0000-000000000002" href="/custom/link-1">Link 1</a>', $model->bodyCopy);
$this->assertContains('<a data-item-id="00000000-0000-0000-0000-000000000003" href="/custom/link-2">Link 2</a>', $model->bodyCopy);
$this->assertStringContainsString('<a data-item-id="00000000-0000-0000-0000-000000000002" href="/custom/link-1">Link 1</a>', $model->bodyCopy);
$this->assertStringContainsString('<a data-item-id="00000000-0000-0000-0000-000000000003" href="/custom/link-2">Link 2</a>', $model->bodyCopy);

// Test broken links
$this->assertContains('<a data-item-id="FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF" href="/404">404</a>', $model->bodyCopy);
$this->assertStringContainsString('<a data-item-id="FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF" href="/404">404</a>', $model->bodyCopy);
}

public function test_BindModel_DefaultImplementation_InlineLinkedItemsNotChanged()
Expand All @@ -53,8 +53,8 @@ public function test_BindModel_DefaultImplementation_InlineLinkedItemsNotChanged

$model = $modelBinder->bindModel(\Kontent\Ai\Delivery\Models\Items\ContentItem::class, $data->item, $data->modular_content);

$this->assertContains('<object type="application/kenticocloud" data-type="item" data-codename="modular_item_1"></object>', $model->bodyCopy);
$this->assertContains('<object type="application/kenticocloud" data-type="item" data-codename="modular_item_2"></object>', $model->bodyCopy);
$this->assertStringContainsString('<object type="application/kenticocloud" data-type="item" data-codename="modular_item_1"></object>', $model->bodyCopy);
$this->assertStringContainsString('<object type="application/kenticocloud" data-type="item" data-codename="modular_item_2"></object>', $model->bodyCopy);
}

public function test_BindModel_DefaultImplementationEmptyRichTextValue_ResolvedWithNoError()
Expand Down Expand Up @@ -95,10 +95,10 @@ public function test_BindModel_MockImplementation_InlineLinkedItemsResolved()

$model = $modelBinder->bindModel(\Kontent\Ai\Delivery\Models\Items\ContentItem::class, $data->item, $data->modular_content);

$this->assertContains('<div>Modular item 1</div>', $model->bodyCopy);
$this->assertContains('<div>Modular item 2</div>', $model->bodyCopy);
$this->assertContains('<object type="application/kenticocloud" data-type="noitem" data-codename="modular_item_1"></object>', $model->bodyCopy);
$this->assertContains('<object type="text/xml" data-type="item" data-codename="modular_item_1"></object>', $model->bodyCopy);
$this->assertStringContainsString('<div>Modular item 1</div>', $model->bodyCopy);
$this->assertStringContainsString('<div>Modular item 2</div>', $model->bodyCopy);
$this->assertStringContainsString('<object type="application/kenticocloud" data-type="noitem" data-codename="modular_item_1"></object>', $model->bodyCopy);
$this->assertStringContainsString('<object type="text/xml" data-type="item" data-codename="modular_item_1"></object>', $model->bodyCopy);
}

public function test_BindModel_MockImplementation_TableInRichTextResolved()
Expand Down
Loading

0 comments on commit 1f7eae6

Please sign in to comment.