2024-08-16 15:14:44 +00:00
|
|
|
<?php
|
|
|
|
// ScopedServerTest.php
|
|
|
|
// Created: 2024-08-16
|
2024-11-13 23:17:29 +00:00
|
|
|
// 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};
|
2024-11-13 23:17:29 +00:00
|
|
|
use RPCii\Server\{HttpRpcServer,ScopedRpcServer};
|
2024-08-16 15:14:44 +00:00
|
|
|
|
2024-11-13 23:17:29 +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 {
|
2024-11-13 23:17:29 +00:00
|
|
|
$base = new HttpRpcServer;
|
|
|
|
$base->registerQueryProcedure('test', fn() => 'test');
|
2024-08-16 15:14:44 +00:00
|
|
|
|
|
|
|
$scopedToBeans = $base->scopeTo('beans:');
|
2024-11-13 23:17:29 +00:00
|
|
|
$scopedToBeans->registerQueryProcedure('test', fn() => 'test in beans');
|
2024-08-16 15:14:44 +00:00
|
|
|
|
|
|
|
$scopedToGarf = $base->scopeTo('garf:');
|
|
|
|
$scopedToGarfield = $scopedToGarf->scopeTo('ield:');
|
2024-11-13 23:17:29 +00:00
|
|
|
$scopedToGarfield->registerQueryProcedure('test', fn() => 'test in garfield');
|
2024-08-16 15:14:44 +00:00
|
|
|
|
2024-11-13 23:17:29 +00:00
|
|
|
$baseTest = $base->getProcedureInfo('test');
|
2024-08-16 15:14:44 +00:00
|
|
|
$this->assertNotNull($baseTest);
|
|
|
|
$this->assertEquals('test', $baseTest->getName());
|
|
|
|
|
2024-11-13 23:17:29 +00:00
|
|
|
$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());
|
|
|
|
|
2024-11-13 23:17:29 +00:00
|
|
|
$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());
|
|
|
|
}
|
|
|
|
}
|