1
0
Fork 0
mirror of synced 2024-06-14 00:34:51 +12:00
appwrite/tests/unit/Utopia/RequestTest.php
2024-03-07 16:20:34 +01:00

54 lines
1.7 KiB
PHP

<?php
namespace Tests\Unit\Utopia;
use Appwrite\Utopia\Request;
use PHPUnit\Framework\TestCase;
use Swoole\Http\Request as SwooleRequest;
use Tests\Unit\Utopia\Request\Filters\First;
use Tests\Unit\Utopia\Request\Filters\Second;
use Utopia\Route;
class RequestTest extends TestCase
{
protected ?Request $request = null;
public function setUp(): void
{
$this->request = new Request(new SwooleRequest());
}
public function testFilters(): void
{
$this->assertFalse($this->request->hasFilters());
$this->assertIsArray($this->request->getFilters());
$this->assertEmpty($this->request->getFilters());
$this->request->addFilter(new First());
$this->request->addFilter(new Second());
$this->assertTrue($this->request->hasFilters());
$this->assertCount(2, $this->request->getFilters());
$route = new Route(Request::METHOD_GET, '/test');
$route->label('sdk.method', 'method');
$route->label('sdk.namespace', 'namespace');
// set test header to prevent header populaten inside the request class
$this->request->addHeader('EXAMPLE', 'VALUE');
$this->request->setRoute($route);
$this->request->setQueryString([
'initial' => true,
'first' => false
]);
$output = $this->request->getParams();
$this->assertArrayHasKey('initial', $output);
$this->assertTrue($output['initial']);
$this->assertArrayHasKey('first', $output);
$this->assertTrue($output['first']);
$this->assertArrayHasKey('second', $output);
$this->assertTrue($output['second']);
$this->assertArrayNotHasKey('deleted', $output);
}
}