mirror of
https://github.com/friendica/friendica
synced 2025-04-20 14:30:11 +00:00
Simplify json testing
This commit is contained in:
parent
6a813eec92
commit
354c2d828a
17 changed files with 45 additions and 66 deletions
|
@ -22,6 +22,7 @@
|
|||
namespace Friendica\Test\src\Module\Api;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Capabilities\ICanCreateResponses;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Database\Database;
|
||||
|
@ -32,6 +33,7 @@ use Friendica\Test\FixtureTest;
|
|||
use Friendica\Test\Util\AppDouble;
|
||||
use Friendica\Test\Util\AuthenticationDouble;
|
||||
use Friendica\Test\Util\AuthTestConfig;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
abstract class ApiTest extends FixtureTest
|
||||
{
|
||||
|
@ -50,6 +52,24 @@ abstract class ApiTest extends FixtureTest
|
|||
// We could probably do more checks here.
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a response into a JSON class
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function toJson(ResponseInterface $response)
|
||||
{
|
||||
self::assertEquals(ICanCreateResponses::TYPE_JSON, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
|
||||
|
||||
$body = (string)$response->getBody();
|
||||
|
||||
self::assertJson($body);
|
||||
|
||||
return json_decode($body);
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
@ -63,7 +83,7 @@ abstract class ApiTest extends FixtureTest
|
|||
DI::app()->setIsLoggedIn(true);
|
||||
|
||||
AuthTestConfig::$authenticated = true;
|
||||
AuthTestConfig::$user_id = 42;
|
||||
AuthTestConfig::$user_id = 42;
|
||||
|
||||
$this->installAuthTest();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue