mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
filter by backend
This commit is contained in:
parent
fa7a6f9b0a
commit
df83a46e20
17 changed files with 265 additions and 38 deletions
53
test/Controllers/ControllerTest.php
Normal file
53
test/Controllers/ControllerTest.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Controllers;
|
||||
|
||||
use Demostf\API\Test\TestCase;
|
||||
use flight\net\Request;
|
||||
use flight\net\Response;
|
||||
use flight\util\Collection;
|
||||
|
||||
abstract class ControllerTest extends TestCase {
|
||||
/** @var string $responseData */
|
||||
private $responseData;
|
||||
|
||||
protected function getRequest(array $get = [], array $post = [], array $files = []): Request {
|
||||
/** @var Request $mock */
|
||||
$mock = $this->getMockBuilder(Request::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods([])
|
||||
->getMock();
|
||||
|
||||
$mock->query = new Collection($get);
|
||||
$mock->data = new Collection($post);
|
||||
$mock->files = new Collection($files);
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
protected function getResponse() {
|
||||
/** @var Response|\PHPUnit_Framework_MockObject_MockObject $mock */
|
||||
$mock = $this->getMockBuilder(Response::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['send'])
|
||||
->getMock();
|
||||
|
||||
$mock->expects($this->any())
|
||||
->method('send')
|
||||
->willReturnCallback(function () use ($mock) {
|
||||
$reflection = new \ReflectionClass($mock);
|
||||
$bodyProperty = $reflection->getProperty('body');
|
||||
$bodyProperty->setAccessible(true);
|
||||
|
||||
$this->responseData = $bodyProperty->getValue($mock);
|
||||
});
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
protected function getResponseData() {
|
||||
return $this->responseData;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue