Replaced old /api endpoint with ApiController
parent
93e578e555
commit
e948091066
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Controllers;
|
||||
|
||||
use Engelsystem\Http\Response;
|
||||
|
||||
class ApiController extends BaseController
|
||||
{
|
||||
/** @var Response */
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
* @param Response $response
|
||||
*/
|
||||
public function __construct(Response $response)
|
||||
{
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return $this->response
|
||||
->setStatusCode(501)
|
||||
->withHeader('content-type', 'application/json')
|
||||
->withContent(json_encode(['error' => 'Not implemented']));
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Test\Unit\Controllers;
|
||||
|
||||
use Engelsystem\Controllers\ApiController;
|
||||
use Engelsystem\Http\Response;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ApiControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Engelsystem\Controllers\ApiController::__construct
|
||||
* @covers \Engelsystem\Controllers\ApiController::index
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
$controller = new ApiController(new Response());
|
||||
|
||||
$response = $controller->index();
|
||||
|
||||
$this->assertEquals(501, $response->getStatusCode());
|
||||
$this->assertEquals(['application/json'], $response->getHeader('content-type'));
|
||||
$this->assertJson($response->getContent());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue