rpcii-php/tests/ScopedServerTest.php

43 lines
1.6 KiB
PHP
Raw Permalink Normal View History

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