Skip to content

Commit 68c9548

Browse files
committed
auto generated model tests based on json examples
1 parent 97f76b6 commit 68c9548

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3231
-0
lines changed

tests/Generated/AccountTest.php

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Generated;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Vazaha\Mastodon\Models\AccountModel;
9+
10+
class AccountTest extends TestCase
11+
{
12+
protected string $json;
13+
14+
protected function setUp(): void
15+
{
16+
$this->json = <<<'JSON'
17+
{
18+
"id": "23634",
19+
"username": "noiob",
20+
"acct": "[email protected]",
21+
"display_name": "ikea shark fan account",
22+
"locked": false,
23+
"bot": false,
24+
"created_at": "2017-02-08T02:00:53.274Z",
25+
"note": "<p>:ms_rainbow_flag: :ms_bisexual_flagweb: :ms_nonbinary_flag: <a href=\"https://awoo.space/tags/awoo\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>awoo</span}.space <a href=\"https://awoo.space/tags/admin\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>admin</span} ~ <a href=\"https://awoo.space/tags/bi\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>bi</span} ~ <a href=\"https://awoo.space/tags/nonbinary\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>nonbinary</span} ~ compsci student ~ likes video <a href=\"https://awoo.space/tags/games\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>games</span} and weird/ old electronics and will post obsessively about both ~ avatar by <span class=\"h-card\"><a href=\"https://weirder.earth/@dzuk\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>dzuk</span}</span></p>",
26+
"url": "https://awoo.space/@noiob",
27+
"avatar": "https://files.mastodon.social/accounts/avatars/000/023/634/original/6ca8804dc46800ad.png",
28+
"avatar_static": "https://files.mastodon.social/accounts/avatars/000/023/634/original/6ca8804dc46800ad.png",
29+
"header": "https://files.mastodon.social/accounts/headers/000/023/634/original/256eb8d7ac40f49a.png",
30+
"header_static": "https://files.mastodon.social/accounts/headers/000/023/634/original/256eb8d7ac40f49a.png",
31+
"followers_count": 547,
32+
"following_count": 404,
33+
"statuses_count": 28468,
34+
"last_status_at": "2019-11-17T00:02:23.693Z",
35+
"emojis": [
36+
{
37+
"shortcode": "ms_rainbow_flag",
38+
"url": "https://files.mastodon.social/custom_emojis/images/000/028/691/original/6de008d6281f4f59.png",
39+
"static_url": "https://files.mastodon.social/custom_emojis/images/000/028/691/static/6de008d6281f4f59.png",
40+
"visible_in_picker": true
41+
},
42+
{
43+
"shortcode": "ms_bisexual_flag",
44+
"url": "https://files.mastodon.social/custom_emojis/images/000/050/744/original/02f94a5fca7eaf78.png",
45+
"static_url": "https://files.mastodon.social/custom_emojis/images/000/050/744/static/02f94a5fca7eaf78.png",
46+
"visible_in_picker": true
47+
},
48+
{
49+
"shortcode": "ms_nonbinary_flag",
50+
"url": "https://files.mastodon.social/custom_emojis/images/000/105/099/original/8106088bd4782072.png",
51+
"static_url": "https://files.mastodon.social/custom_emojis/images/000/105/099/static/8106088bd4782072.png",
52+
"visible_in_picker": true
53+
}
54+
],
55+
"fields": [
56+
{
57+
"name": "Pronouns",
58+
"value": "they/them",
59+
"verified_at": null
60+
},
61+
{
62+
"name": "Alt",
63+
"value": "<span class=\"h-card\"><a href=\"https://cybre.space/@noiob\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>noiob</span}</span>",
64+
"verified_at": null
65+
},
66+
{
67+
"name": "Bots",
68+
"value": "<span class=\"h-card\"><a href=\"https://botsin.space/@darksouls\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>darksouls</span}</span>, <span class=\"h-card\"><a href=\"https://botsin.space/@nierautomata\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>nierautomata</span}</span>, <span class=\"h-card\"><a href=\"https://mastodon.social/@fedi\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>fedi</span}</span>, code for <span class=\"h-card\"><a href=\"https://botsin.space/@awoobot\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>awoobot</span}</span>",
69+
"verified_at": null
70+
},
71+
{
72+
"name": "Website",
73+
"value": "<a href=\"http://shork.xyz\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">http://</span><span class=\"\">shork.xyz</span><span class=\"invisible\"></span}",
74+
"verified_at": "2019-11-10T10:31:10.744+00:00"
75+
}
76+
]
77+
}
78+
79+
JSON;
80+
}
81+
82+
public function testModelInstantation(): void
83+
{
84+
self::assertTrue(true);
85+
86+
$array = json_decode($this->json, true);
87+
88+
if (!is_array($array)) {
89+
// too bad...
90+
return;
91+
}
92+
93+
$model = AccountModel::fromArray($array);
94+
95+
foreach ($array as $property => $value) {
96+
$property = AccountModel::sanitizePropertyName($property);
97+
98+
self::assertObjectHasProperty($property, $model);
99+
100+
$modelValue = $model->{$property};
101+
102+
if (!is_string($modelValue) && !is_int($modelValue)) {
103+
// TODO find some other way to test this
104+
continue;
105+
}
106+
107+
self::assertEquals($value, $model->{$property});
108+
}
109+
}
110+
}

tests/Generated/Admin/AccountTest.php

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Generated\Admin;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Vazaha\Mastodon\Models\Admin\AccountModel;
9+
10+
class AccountTest extends TestCase
11+
{
12+
protected string $json;
13+
14+
protected function setUp(): void
15+
{
16+
$this->json = <<<'JSON'
17+
{
18+
"id": "108965278956942133",
19+
"username": "admin",
20+
"domain": null,
21+
"created_at": "2022-09-08T23:03:26.762Z",
22+
"email": "[email protected]",
23+
"ip": "192.168.42.1",
24+
"role": {
25+
"id": 3,
26+
"name": "Owner",
27+
"color": "",
28+
"position": 1000,
29+
"permissions": 1,
30+
"highlighted": true,
31+
"created_at": "2022-09-08T22:48:07.983Z",
32+
"updated_at": "2022-09-08T22:48:07.983Z"
33+
},
34+
"confirmed": true,
35+
"suspended": false,
36+
"silenced": false,
37+
"disabled": false,
38+
"approved": true,
39+
"locale": null,
40+
"invite_request": null,
41+
"ips": [
42+
{
43+
"ip": "192.168.42.1",
44+
"used_at": "2022-09-15T01:38:58.851Z"
45+
}
46+
],
47+
"account": {
48+
"id": "108965278956942133",
49+
"username": "admin",
50+
"acct": "admin",
51+
"display_name": "",
52+
"locked": false,
53+
"bot": false,
54+
"discoverable": null,
55+
"group": false,
56+
"created_at": "2022-09-08T00:00:00.000Z",
57+
"note": "",
58+
"url": "http://mastodon.local/@admin",
59+
"avatar": "http://mastodon.local/avatars/original/missing.png",
60+
"avatar_static": "http://mastodon.local/avatars/original/missing.png",
61+
"header": "http://mastodon.local/headers/original/missing.png",
62+
"header_static": "http://mastodon.local/headers/original/missing.png",
63+
"followers_count": 0,
64+
"following_count": 0,
65+
"statuses_count": 0,
66+
"last_status_at": null,
67+
"emojis": [],
68+
"fields": []
69+
}
70+
}
71+
72+
JSON;
73+
}
74+
75+
public function testModelInstantation(): void
76+
{
77+
self::assertTrue(true);
78+
79+
$array = json_decode($this->json, true);
80+
81+
if (!is_array($array)) {
82+
// too bad...
83+
return;
84+
}
85+
86+
$model = AccountModel::fromArray($array);
87+
88+
foreach ($array as $property => $value) {
89+
$property = AccountModel::sanitizePropertyName($property);
90+
91+
self::assertObjectHasProperty($property, $model);
92+
93+
$modelValue = $model->{$property};
94+
95+
if (!is_string($modelValue) && !is_int($modelValue)) {
96+
// TODO find some other way to test this
97+
continue;
98+
}
99+
100+
self::assertEquals($value, $model->{$property});
101+
}
102+
}
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Generated\Admin;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Vazaha\Mastodon\Models\Admin\CanonicalEmailBlockModel;
9+
10+
class CanonicalEmailBlockTest extends TestCase
11+
{
12+
protected string $json;
13+
14+
protected function setUp(): void
15+
{
16+
$this->json = <<<'JSON'
17+
{
18+
"id": "2",
19+
"canonical_email_hash": "b344e55d11b3fc25d0d53194e0475838bf17e9be67ce3e6469956222d9a34f9c"
20+
}
21+
22+
JSON;
23+
}
24+
25+
public function testModelInstantation(): void
26+
{
27+
self::assertTrue(true);
28+
29+
$array = json_decode($this->json, true);
30+
31+
if (!is_array($array)) {
32+
// too bad...
33+
return;
34+
}
35+
36+
$model = CanonicalEmailBlockModel::fromArray($array);
37+
38+
foreach ($array as $property => $value) {
39+
$property = CanonicalEmailBlockModel::sanitizePropertyName($property);
40+
41+
self::assertObjectHasProperty($property, $model);
42+
43+
$modelValue = $model->{$property};
44+
45+
if (!is_string($modelValue) && !is_int($modelValue)) {
46+
// TODO find some other way to test this
47+
continue;
48+
}
49+
50+
self::assertEquals($value, $model->{$property});
51+
}
52+
}
53+
}
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Generated\Admin;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Vazaha\Mastodon\Models\Admin\DomainAllowModel;
9+
10+
class DomainAllowTest extends TestCase
11+
{
12+
protected string $json;
13+
14+
protected function setUp(): void
15+
{
16+
$this->json = <<<'JSON'
17+
{
18+
"id": "1",
19+
"domain": "mastodon.social",
20+
"created_at": "2022-09-14T21:23:02.755Z"
21+
}
22+
23+
JSON;
24+
}
25+
26+
public function testModelInstantation(): void
27+
{
28+
self::assertTrue(true);
29+
30+
$array = json_decode($this->json, true);
31+
32+
if (!is_array($array)) {
33+
// too bad...
34+
return;
35+
}
36+
37+
$model = DomainAllowModel::fromArray($array);
38+
39+
foreach ($array as $property => $value) {
40+
$property = DomainAllowModel::sanitizePropertyName($property);
41+
42+
self::assertObjectHasProperty($property, $model);
43+
44+
$modelValue = $model->{$property};
45+
46+
if (!is_string($modelValue) && !is_int($modelValue)) {
47+
// TODO find some other way to test this
48+
continue;
49+
}
50+
51+
self::assertEquals($value, $model->{$property});
52+
}
53+
}
54+
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Generated\Admin;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Vazaha\Mastodon\Models\Admin\DomainBlockModel;
9+
10+
class DomainBlockTest extends TestCase
11+
{
12+
protected string $json;
13+
14+
protected function setUp(): void
15+
{
16+
$this->json = <<<'JSON'
17+
{
18+
"id": "1",
19+
"domain": "example.com",
20+
"created_at": "2022-11-16T08:15:34.238Z",
21+
"severity": "noop",
22+
"reject_media": false,
23+
"reject_reports": false,
24+
"private_comment": null,
25+
"public_comment": null,
26+
"obfuscate": false
27+
}
28+
29+
JSON;
30+
}
31+
32+
public function testModelInstantation(): void
33+
{
34+
self::assertTrue(true);
35+
36+
$array = json_decode($this->json, true);
37+
38+
if (!is_array($array)) {
39+
// too bad...
40+
return;
41+
}
42+
43+
$model = DomainBlockModel::fromArray($array);
44+
45+
foreach ($array as $property => $value) {
46+
$property = DomainBlockModel::sanitizePropertyName($property);
47+
48+
self::assertObjectHasProperty($property, $model);
49+
50+
$modelValue = $model->{$property};
51+
52+
if (!is_string($modelValue) && !is_int($modelValue)) {
53+
// TODO find some other way to test this
54+
continue;
55+
}
56+
57+
self::assertEquals($value, $model->{$property});
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)