2018-04-13 13:52:39 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
|
|
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Flarum\Tests\Api\Controller;
|
|
|
|
|
|
|
|
use Flarum\Tests\Test\TestCase;
|
|
|
|
use Flarum\User\User;
|
2018-05-14 19:32:19 +08:00
|
|
|
use Illuminate\Support\Arr;
|
2018-04-13 13:52:39 +08:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2018-05-30 06:12:06 +08:00
|
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
2018-04-13 13:52:39 +08:00
|
|
|
|
|
|
|
abstract class ApiControllerTestCase extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
2018-05-30 06:12:06 +08:00
|
|
|
* @var RequestHandlerInterface
|
2018-04-13 13:52:39 +08:00
|
|
|
*/
|
|
|
|
protected $controller;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var null|User
|
|
|
|
*/
|
|
|
|
protected $actor = null;
|
|
|
|
|
2018-05-14 19:32:19 +08:00
|
|
|
protected function callWith(array $body = [], array $queryParams = []): ResponseInterface
|
2018-04-13 13:52:39 +08:00
|
|
|
{
|
2018-05-14 19:32:19 +08:00
|
|
|
if (! Arr::get($body, 'data') && Arr::isAssoc($body)) {
|
|
|
|
$body = ['data' => ['attributes' => $body]];
|
|
|
|
}
|
|
|
|
|
2018-04-13 13:52:39 +08:00
|
|
|
return $this->call(
|
|
|
|
$this->controller,
|
|
|
|
$this->actor,
|
2018-05-14 19:32:19 +08:00
|
|
|
$queryParams,
|
|
|
|
$body
|
2018-04-13 13:52:39 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
$this->actor = null;
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
}
|