Skip to content

Commit bde9f69

Browse files
authored
Merge pull request #56 from bigcommerce/add-service-method
Add helper method for getting service name from stub
2 parents a6210cf + 60a5d6d commit bde9f69

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/Grphp/Client/Interceptors/Base.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function setRequest(&$request)
7373
}
7474

7575
/**
76-
* Gets the fully qualified method name, e.g. grphp.catalog.products/GetProduct
76+
* Gets the fully qualified method name, e.g. grphp.test.Things/GetThing
7777
*
7878
* @return string
7979
* @throws StubNotFoundException
@@ -89,6 +89,24 @@ public function getFullyQualifiedMethodName(): string
8989
return $stub->getServiceName() . '/' . ucfirst($methodName);
9090
}
9191

92+
/**
93+
* Gets the fully qualified service name, e.g. grphp.test.Things
94+
*
95+
* @return string
96+
* @throws StubNotFoundException
97+
*/
98+
public function getServiceName(): string
99+
{
100+
$stub = $this->getStub();
101+
102+
if (empty($stub)) {
103+
$method = $this->getMethod();
104+
throw new StubNotFoundException("Stub not found for $method");
105+
}
106+
107+
return $stub->getServiceName();
108+
}
109+
92110
/**
93111
* Get the expected response protobuf message class
94112
*

tests/Unit/Grphp/Client/Interceptors/BaseTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ public function testGetFullyQualifiedMethodName(): void
102102
$this->assertEquals('grphp.test.Things/GetThing', $interceptor->getFullyQualifiedMethodName());
103103
}
104104

105+
public function testGetServiceName(): void
106+
{
107+
$requestMessage = new GetThingReq();
108+
$requestMessage->setId(1);
109+
$client = new ThingsClient('127.0.0.1:9000', [ 'credentials' => null ]);
110+
$method = 'getThing';
111+
112+
$interceptor = new TestInterceptor();
113+
$interceptor->setMethod($method);
114+
$interceptor->setStub($client);
115+
$this->assertEquals('grphp.test.Things', $interceptor->getServiceName());
116+
}
117+
105118
// When then stub is not set for some wild reason
106119
public function testGetFullyQualifiedMethodNameWhenNoStub(): void
107120
{

0 commit comments

Comments
 (0)