appwrite/tests/unit/SDK/Specification/FormatTest.php

67 lines
2.5 KiB
PHP
Raw Normal View History

2026-04-10 04:07:01 +00:00
<?php
namespace Tests\Unit\SDK\Specification;
use Appwrite\SDK\Specification\Format;
use PHPUnit\Framework\TestCase;
use Utopia\DI\Container;
2026-04-10 04:39:33 +00:00
class TestFormat extends Format
{
public function getName(): string
{
return 'test';
}
public function parse(): array
{
return [];
}
public function requestParameterConfig(string $service, string $method, string $param, bool $optional, bool $nullable, mixed $default): array
{
return $this->getRequestParameterConfig($service, $method, $param, $optional, $nullable, $default);
}
}
2026-04-10 04:07:01 +00:00
class FormatTest extends TestCase
{
2026-04-10 04:39:33 +00:00
private TestFormat $format;
2026-04-10 04:07:01 +00:00
protected function setUp(): void
{
parent::setUp();
2026-04-10 04:39:33 +00:00
$this->format = new TestFormat(new Container(), [], [], [], [], 0, 'console');
2026-04-10 04:07:01 +00:00
}
public function testProjectRequestParameterOverrides(): void
{
$createWebPlatform = $this->format->requestParameterConfig('project', 'createWebPlatform', 'hostname', true, false, '');
$updateWebPlatform = $this->format->requestParameterConfig('project', 'updateWebPlatform', 'hostname', true, false, '');
$listPlatforms = $this->format->requestParameterConfig('project', 'listPlatforms', 'queries', true, false, []);
$this->assertTrue($createWebPlatform['required']);
$this->assertFalse($createWebPlatform['emitDefault']);
$this->assertTrue($updateWebPlatform['required']);
$this->assertFalse($updateWebPlatform['emitDefault']);
$this->assertTrue($listPlatforms['emitDefault']);
2026-04-10 04:07:01 +00:00
}
public function testProjectPlatformResponseTypeUsesSharedEnumName(): void
{
$this->assertSame('PlatformType', $this->format->getResponseEnumName('platformAndroid', 'type'));
$this->assertSame('PlatformType', $this->format->getResponseEnumName('platformWeb', 'type'));
2026-04-10 04:39:33 +00:00
$this->assertSame('PlatformType', $this->format->getResponseEnumName('platformApple', 'type'));
$this->assertSame('PlatformType', $this->format->getResponseEnumName('platformWindows', 'type'));
$this->assertSame('PlatformType', $this->format->getResponseEnumName('platformLinux', 'type'));
$this->assertNull($this->format->getResponseEnumName('platformList', 'type'));
2026-04-10 04:07:01 +00:00
}
public function testExistingResponseEnumMappingsRemainUnchanged(): void
{
$this->assertSame('HealthCheckStatus', $this->format->getResponseEnumName('healthStatus', 'status'));
$this->assertNull($this->format->getResponseEnumName('key', 'name'));
}
}