self->assertEquals('it is beans', $beans); return 'query registered using action attribute'; } #[RpcQuery('aiwass:test:query2')] public static function staticQueryRegisteredUsingQueryAttribute(string $required, string $optional = 'the'): string { self::$that->assertEquals('internet', $required); self::$that->assertEquals('the', $optional); return 'static query registered using query attribute'; } #[RpcAction('aiwass:test:proc2')] public function dynamicProcedureRegisteredUsingProcedureAttribute(string $optional = 'meow'): string { $this->self->assertEquals('meow', $optional); return 'dynamic procedure registered using procedure attribute'; } #[RpcQuery('aiwass:test:query3')] #[RpcAction('aiwass:test:proc3')] public function multiple(): string { return 'a dynamic method registered as both a query and a procedure'; } public function hasNoAttr(): string { return 'not an action handler'; } }; $server = new HttpRpcServer; $server->register($handler); $this->assertNull($server->getProcedureInfo('aiwass:none')); $act1 = $server->getProcedureInfo('aiwass:test:proc1'); $this->assertNotNull($act1); $this->assertTrue($act1->isAction()); $this->assertEquals('aiwass:test:proc1', $act1->getName()); $this->assertEquals('procedure registered using action attribute', $act1->invokeHandler()); $act2 = $server->getProcedureInfo('aiwass:test:proc2'); $this->assertNotNull($act2); $this->assertTrue($act2->isAction()); $this->assertEquals('aiwass:test:proc2', $act2->getName()); $this->assertEquals('dynamic procedure registered using procedure attribute', $act2->invokeHandler()); $query1 = $server->getProcedureInfo('aiwass:test:query1'); $this->assertNotNull($query1); $this->assertFalse($query1->isAction()); $this->assertEquals('aiwass:test:query1', $query1->getName()); $this->assertEquals('query registered using action attribute', $query1->invokeHandler(['beans' => 'it is beans'])); $query2 = $server->getProcedureInfo('aiwass:test:query2'); $this->assertNotNull($query2); $this->assertFalse($query2->isAction()); $this->assertEquals('aiwass:test:query2', $query2->getName()); $this->assertEquals('static query registered using query attribute', $query2->invokeHandler(['required' => 'internet'])); $query3 = $server->getProcedureInfo('aiwass:test:query3'); $proc3 = $server->getProcedureInfo('aiwass:test:proc3'); $this->assertNotNull($query3); $this->assertNotNull($proc3); $this->assertFalse($query3->isAction()); $this->asserttrue($proc3->isAction()); $this->assertEquals('aiwass:test:query3', $query3->getName()); $this->assertEquals('aiwass:test:proc3', $proc3->getName()); $this->assertEquals($query3->getHandler(), $proc3->getHandler()); $this->assertEquals('a dynamic method registered as both a query and a procedure', $query3->invokeHandler()); $this->assertEquals('a dynamic method registered as both a query and a procedure', $proc3->invokeHandler()); $this->assertNull($server->getProcedureInfo('doesnotexist')); $this->expectException(RuntimeException::class); $query1->invokeHandler(['notbeans' => 'it is not beans']); } }