Simplify json testing

This commit is contained in:
Philipp 2021-12-09 20:53:29 +01:00
parent 6a813eec92
commit 354c2d828a
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
17 changed files with 45 additions and 66 deletions

View file

@ -15,7 +15,7 @@ class RateLimitStatusTest extends ApiTest
$rateLimitStatus = new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']);
$response = $rateLimitStatus->run();
$result = json_decode($response->getBody());
$result = $this->toJson($response);
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
self::assertEquals(150, $result->remaining_hits);

View file

@ -17,11 +17,7 @@ class UpdateProfileTest extends ApiTest
$updateProfile = new UpdateProfile(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => 'json']);
$response = $updateProfile->run(['name' => 'new_name', 'description' => 'new_description']);
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
self::assertEquals('new_name', $json->name);
self::assertEquals('new_description', $json->description);

View file

@ -17,11 +17,7 @@ class ListsTest extends ApiTest
$lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
self::assertIsArray($json->users);
}

View file

@ -17,11 +17,7 @@ class ListsTest extends ApiTest
$lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
self::assertIsArray($json->users);
}

View file

@ -19,11 +19,7 @@ class ListsTest extends ApiTest
$lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
self::assertIsArray($json->users);
}

View file

@ -19,11 +19,7 @@ class IncomingTest extends ApiTest
$lists = new Incoming(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
self::assertIsArray($json->ids);
}

View file

@ -31,11 +31,7 @@ class StatusesTest extends ApiTest
$lists = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run(['list_id' => 1, 'page' => -1, 'max_id' => 10]);
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
$json = $this->toJson($response);
foreach ($json as $status) {
self::assertIsString($status->text);

View file

@ -72,12 +72,13 @@ class UploadTest extends ApiTest
];
$response = (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run();
$media = json_decode($response->getBody(), true);
self::assertEquals('image/png', $media['image']['image_type']);
self::assertEquals(1, $media['image']['w']);
self::assertEquals(1, $media['image']['h']);
self::assertNotEmpty($media['image']['friendica_preview_url']);
$media = $this->toJson($response);
self::assertEquals('image/png', $media->image->image_type);
self::assertEquals(1, $media->image->w);
self::assertEquals(1, $media->image->h);
self::assertNotEmpty($media->image->friendica_preview_url);
}
/**

View file

@ -14,7 +14,7 @@ class SavedSearchesTest extends ApiTest
$savedSearch = new SavedSearches(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']);
$response = $savedSearch->run();
$result = json_decode($response->getBody());
$result = $this->toJson($response);
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
self::assertEquals(1, $result[0]->id);