mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
80 lines
2.6 KiB
PHP
80 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\SDK\Specification;
|
|
|
|
use Appwrite\SDK\Specification\Format;
|
|
use Appwrite\Utopia\Response\Model\HealthStatus;
|
|
use Appwrite\Utopia\Response\Model\PlatformAndroid;
|
|
use Appwrite\Utopia\Response\Model\PlatformApple;
|
|
use Appwrite\Utopia\Response\Model\PlatformLinux;
|
|
use Appwrite\Utopia\Response\Model\PlatformList;
|
|
use Appwrite\Utopia\Response\Model\PlatformWeb;
|
|
use Appwrite\Utopia\Response\Model\PlatformWindows;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Utopia\DI\Container;
|
|
|
|
class TestFormat extends Format
|
|
{
|
|
public function getName(): string
|
|
{
|
|
return 'test';
|
|
}
|
|
|
|
public function parse(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function requestParameterConfig(bool $optional, bool $nullable, mixed $default, string $methodName = '', string $paramName = ''): array
|
|
{
|
|
return $this->getRequestParameterConfig($optional, $nullable, $default, $methodName, $paramName);
|
|
}
|
|
}
|
|
|
|
class FormatTest extends TestCase
|
|
{
|
|
private TestFormat $format;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->format = new TestFormat(new Container(), [], [], [], [], 0, 'console');
|
|
}
|
|
|
|
public function testProjectRequestParameterOverrides(): void
|
|
{
|
|
$createWebPlatform = $this->format->requestParameterConfig(true, false, '', 'project.createWebPlatform', 'hostname');
|
|
$updateWebPlatform = $this->format->requestParameterConfig(true, false, '', 'project.updateWebPlatform', 'hostname');
|
|
$listPlatforms = $this->format->requestParameterConfig(true, false, [], 'project.listPlatforms', 'queries');
|
|
|
|
$this->assertTrue($createWebPlatform['required']);
|
|
$this->assertFalse($createWebPlatform['emitDefault']);
|
|
$this->assertTrue($updateWebPlatform['required']);
|
|
$this->assertFalse($updateWebPlatform['emitDefault']);
|
|
$this->assertTrue($listPlatforms['emitDefault']);
|
|
}
|
|
|
|
public function testProjectPlatformResponseTypeUsesSharedEnumMetadata(): void
|
|
{
|
|
$models = [
|
|
new PlatformAndroid(),
|
|
new PlatformWeb(),
|
|
new PlatformApple(),
|
|
new PlatformWindows(),
|
|
new PlatformLinux(),
|
|
];
|
|
|
|
foreach ($models as $model) {
|
|
$this->assertSame('PlatformType', $model->getRules()['type']['enumSDKName']);
|
|
}
|
|
|
|
$this->assertArrayNotHasKey('enumSDKName', (new PlatformList())->getRules()['platforms']);
|
|
}
|
|
|
|
public function testExistingResponseEnumMetadataRemainsUnchanged(): void
|
|
{
|
|
$this->assertSame('HealthCheckStatus', (new HealthStatus())->getRules()['status']['enumSDKName']);
|
|
}
|
|
}
|