2024-08-16 15:14:44 +00:00
|
|
|
<?php
|
|
|
|
// ScopedServerTest.php
|
|
|
|
// Created: 2024-08-16
|
|
|
|
// Updated: 2024-08-16
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
|
2024-08-16 15:20:15 +00:00
|
|
|
use Aiwass\Server\{RpcServer,RpcServerScoped};
|
2024-08-16 15:14:44 +00:00
|
|
|
|
|
|
|
#[CoversClass(RpcServerScoped::class)]
|
|
|
|
#[UsesClass(RpcServer::class)]
|
|
|
|
final class ScopedServerTest extends TestCase {
|
|
|
|
public function testServerScoping(): void {
|
|
|
|
$base = new RpcServer;
|
|
|
|
$base->registerQueryAction('test', fn() => 'test');
|
|
|
|
|
|
|
|
$scopedToBeans = $base->scopeTo('beans:');
|
|
|
|
$scopedToBeans->registerQueryAction('test', fn() => 'test in beans');
|
|
|
|
|
|
|
|
$scopedToGarf = $base->scopeTo('garf:');
|
|
|
|
$scopedToGarfield = $scopedToGarf->scopeTo('ield:');
|
|
|
|
$scopedToGarfield->registerQueryAction('test', fn() => 'test in garfield');
|
|
|
|
|
|
|
|
$baseTest = $base->getActionInfo('test');
|
|
|
|
$this->assertNotNull($baseTest);
|
|
|
|
$this->assertEquals('test', $baseTest->getName());
|
|
|
|
|
|
|
|
$baseBeansTest = $base->getActionInfo('beans:test');
|
|
|
|
$scopedBeansTest = $scopedToBeans->getActionInfo('test');
|
|
|
|
$this->assertNotNull($baseBeansTest);
|
|
|
|
$this->assertSame($baseBeansTest, $scopedBeansTest);
|
|
|
|
$this->assertEquals('beans:test', $scopedBeansTest->getName());
|
|
|
|
|
|
|
|
$baseGarfieldTest = $base->getActionInfo('garf:ield:test');
|
|
|
|
$scopedGarfieldTest = $scopedToGarfield->getActionInfo('test');
|
|
|
|
$this->assertNotNull($baseGarfieldTest);
|
|
|
|
$this->assertSame($baseGarfieldTest, $scopedGarfieldTest);
|
|
|
|
$this->assertEquals('garf:ield:test', $scopedGarfieldTest->getName());
|
|
|
|
}
|
|
|
|
}
|