-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed model deserialization issues after release. (#23)
Fixed invalid types in deserialization for models. Added basic tests from test fixtures.
- Loading branch information
Showing
17 changed files
with
271 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ parameters: | |
- src | ||
- tests | ||
checkGenericClassInNonGenericObjectType: false | ||
checkMissingIterableValueType: false |
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace HelpScoutDocs\Tests; | ||
|
||
use JsonException; | ||
use RuntimeException; | ||
use stdClass; | ||
|
||
trait FixtureLoader | ||
{ | ||
/** | ||
* @throws JsonException | ||
* @throws RuntimeException | ||
*/ | ||
public function loadFixtureAsStdClass(string $path): stdClass | ||
{ | ||
$data = file_get_contents($path); | ||
if ($data === false) { | ||
throw new RuntimeException("Failed to read fixture context of $path"); | ||
} | ||
return json_decode($data, false, 512, JSON_THROW_ON_ERROR); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace HelpScoutDocs\Tests\Models; | ||
|
||
use HelpScoutDocs\Models\Article; | ||
use HelpScoutDocs\Models\ArticleRef; | ||
use HelpScoutDocs\Models\ArticleRevision; | ||
use HelpScoutDocs\Models\ArticleRevisionRef; | ||
use HelpScoutDocs\Models\ArticleSearch; | ||
use HelpScoutDocs\Models\Category; | ||
use HelpScoutDocs\Models\Collection; | ||
use HelpScoutDocs\Models\Person; | ||
use HelpScoutDocs\Models\Redirect; | ||
use HelpScoutDocs\Models\Site; | ||
use HelpScoutDocs\Tests\FixtureLoader; | ||
use PHPUnit\Framework\TestCase; | ||
use stdClass; | ||
|
||
class ModelDeserializationTest extends TestCase | ||
{ | ||
use FixtureLoader; | ||
|
||
private const FIXTURE_PATH = __DIR__ . '/fixtures/'; | ||
|
||
/** | ||
* @param string $className | ||
* @param stdClass $fixture | ||
* @return void | ||
* @dataProvider dataProvider | ||
*/ | ||
public function testShouldDeserializeModels(string $className, stdClass $fixture): void | ||
{ | ||
new $className($fixture); | ||
} | ||
|
||
/** | ||
* @return array[] | ||
*/ | ||
public function dataProvider(): array | ||
{ | ||
return [ | ||
'Article' => [Article::class, $this->loadFixture('article')], | ||
'ArticleRef' => [ArticleRef::class, $this->loadFixture('article_ref')], | ||
'ArticleRevision' => [ArticleRevision::class, $this->loadFixture('article_revision')], | ||
'ArticleRevisionRef' => [ArticleRevisionRef::class, $this->loadFixture('article_revision_ref')], | ||
'ArticleSearch' => [ArticleSearch::class, $this->loadFixture('article_search')], | ||
'Category' => [Category::class, $this->loadFixture('category')], | ||
'Collection' => [Collection::class, $this->loadFixture('collection')], | ||
'Person' => [Person::class, $this->loadFixture('person')], | ||
'Redirect' => [Redirect::class, $this->loadFixture('redirect')], | ||
'Site' => [Site::class, $this->loadFixture('site')], | ||
]; | ||
} | ||
|
||
private function loadFixture(string $name): stdClass | ||
{ | ||
return $this->loadFixtureAsStdClass(self::FIXTURE_PATH . $name . '.json'); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"id": "521632244566c845e582652d", | ||
"number": 125, | ||
"collectionId": "5214c77c45667acd25394b51", | ||
"slug": "my-article", | ||
"status": "published", | ||
"hasDraft": false, | ||
"name": "My Article", | ||
"text": "This is the text of the article.", | ||
"categories": [ | ||
"5214c77d45667acd25394b52" | ||
], | ||
"related": [ | ||
"521632244566c845e582652b", | ||
"521632244566c845e582652c" | ||
], | ||
"publicUrl": "https://docs.helpscout.net/article/100-my-article", | ||
"popularity": 4.3, | ||
"viewCount": 237, | ||
"createdBy": 73423, | ||
"updatedBy": 73423, | ||
"createdAt": "2013-08-22T15:45:40Z", | ||
"updatedAt": "2013-08-22T21:40:56Z", | ||
"lastPublishedAt": "2013-08-22T21:40:56Z" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"id": "521632244566c845e582652d", | ||
"number": 125, | ||
"collectionId": "522f91311ef00a6bca026c9d", | ||
"slug": "my-article", | ||
"status": "published", | ||
"hasDraft": false, | ||
"name": "My Article", | ||
"publicUrl": "https://docs.helpscout.net/article/100-my-article", | ||
"popularity": 4.3, | ||
"viewCount": 237, | ||
"createdBy": 73423, | ||
"updatedBy": 73423, | ||
"createdAt": "2013-08-22T15:45:40Z", | ||
"updatedAt": "2013-08-22T21:40:56Z", | ||
"lastPublishedAt": "2013-08-22T21:40:56Z" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"id": "5230deaa456636123f6363d0", | ||
"articleId": "522f918d1ef00a6bca026ca0", | ||
"text": "This is the text of the article.", | ||
"createdBy": { | ||
"id": 73423, | ||
"firstName": "John", | ||
"lastName": "Appleseed" | ||
}, | ||
"createdAt": "2013-09-11T21:20:42Z" | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/HelpScoutDocs/Models/fixtures/article_revision_ref.json
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"id": "5230deaa456636123f6363d0", | ||
"articleId": "522f918d1ef00a6bca026ca0", | ||
"createdBy": { | ||
"id": 73423, | ||
"firstName": "John", | ||
"lastName": "Appleseed" | ||
}, | ||
"createdAt": "2013-09-11T21:20:42Z" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"id": "5215163545667acd25394b5c", | ||
"collectionId": "5214c77c45667acd25394b51", | ||
"categoryIds": [ | ||
"5214c77d45667acd25394b52" | ||
], | ||
"slug": "my-article", | ||
"name": "My Article", | ||
"preview": "This is my article.", | ||
"url": "https://docs.helpscout.net/article/14-my-article", | ||
"docsUrl": "/docs/5214c77c45667acd25394b51/article/5215163545667acd25394b5c", | ||
"number": 14, | ||
"status": "published", | ||
"visibility": "public" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"id": "5214c83d45667acd25394b54", | ||
"number": 133, | ||
"slug": "my-category", | ||
"visibility": "public", | ||
"collectionId": "5214c83d45667acd25394b53", | ||
"order": 1, | ||
"defaultSort": "custom", | ||
"name": "My Category", | ||
"description": "", | ||
"articleCount": 21, | ||
"publishedArticleCount": 19, | ||
"publicUrl": "https://mysite.helpscoutdocs.com/category/133-my-category", | ||
"createdBy": 73423, | ||
"updatedBy": null, | ||
"createdAt": "2013-08-21T14:01:33Z", | ||
"updatedAt": null | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"id": "5214c83d45667acd25394b53", | ||
"siteId": "52404efc4566740003092640", | ||
"number": 33, | ||
"slug": "my-collection", | ||
"visibility": "public", | ||
"order": 1, | ||
"name": "My Collection", | ||
"description": "Description of my collection", | ||
"publicUrl": "https://my-docs.helpscoutdocs.com/collection/1-test", | ||
"articleCount": 3, | ||
"publishedArticleCount": 1, | ||
"createdBy": 73423, | ||
"updatedBy": 73423, | ||
"createdAt": "2013-08-21T14:01:33Z", | ||
"updatedAt": "2013-08-21T14:01:33Z" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"id": 23478, | ||
"firstName": "John", | ||
"lastName": "Appleseed" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"redirect": { | ||
"id": "573df74195ac0e2ad08ab695", | ||
"siteId": "52444ccf3e3e9bd67a3dc68c", | ||
"urlMapping": "/previous/url/1234", | ||
"documentId": "525217bae4b0cb13e565bb9d", | ||
"type": "article", | ||
"redirect": "https://docs.helpscout.net/article/488-transfer-account", | ||
"createdBy": 4577, | ||
"modifiedBy": 4577, | ||
"createdAt": "2016-05-19T17:26:25Z", | ||
"modifiedAt": "2016-05-19T17:26:25Z" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"id": 23478, | ||
"status": "active", | ||
"subDomain": "helpscout", | ||
"cname": "docs.helpscout.net", | ||
"hasPublicSite": true, | ||
"companyName": "Help Scout", | ||
"title": "Help Scout Support", | ||
"logoUrl": "http://helpscout.net/logo.png", | ||
"logoWidth": 174, | ||
"logoHeight": 40, | ||
"favIconUrl": "http://helpscout.net/favicon.png", | ||
"touchIconUrl": "http://helpscout.net/touchicon.png", | ||
"homeUrl": "http://helpscout.net", | ||
"homeLinkText": "Home", | ||
"bgColor": "#444444", | ||
"description": "Frequently asked questions and support documentation for Help Scout", | ||
"hasContactForm": true, | ||
"mailboxId": 968, | ||
"contactEmail": null, | ||
"styleSheetUrl": "http://helpscout.net/docs-style.css", | ||
"headerCode": null, | ||
"createdBy": 29456, | ||
"updatedBy": 29456, | ||
"createdAt": "2013-12-10T15:09:52Z", | ||
"updatedAt": "2013-12-10T15:09:52Z" | ||
} |