rpcii-php/tests/ScopedServerTest.php

43 lines
1.6 KiB
PHP
Raw Normal View History

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};
use Aiwass\{RpcServer,RpcServerScoped};
#[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());
}
}