Skip to content

Commit c54fa72

Browse files
committed
Formatting
1 parent 75dae07 commit c54fa72

12 files changed

Lines changed: 45 additions & 35 deletions

src/RelayBuilder.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Prism\Relay;
66

77
use Prism\Prism\Tool;
8+
use Prism\Relay\Exceptions\ServerConfigurationException;
9+
use Prism\Relay\Exceptions\ToolDefinitionException;
810

911
class RelayBuilder
1012
{
@@ -13,7 +15,7 @@ public function __construct(private readonly string $token) {}
1315
/**
1416
* @param array<string, mixed>|null $config
1517
*
16-
* @throws \Prism\Relay\Exceptions\ServerConfigurationException
18+
* @throws ServerConfigurationException
1719
*/
1820
public function make(string $serverName, ?array $config = null): Relay
1921
{
@@ -24,8 +26,8 @@ public function make(string $serverName, ?array $config = null): Relay
2426
* @param array<string, mixed>|null $config
2527
* @return array<int, Tool>
2628
*
27-
* @throws \Prism\Relay\Exceptions\ServerConfigurationException
28-
* @throws \Prism\Relay\Exceptions\ToolDefinitionException
29+
* @throws ServerConfigurationException
30+
* @throws ToolDefinitionException
2931
*/
3032
public function tools(string $serverName, ?array $config = null): array
3133
{

src/RelayServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function register(): void
1414
$this->mergeConfigFrom(
1515
__DIR__.'/../config/relay.php', 'relay'
1616
);
17-
$this->app->bind('relay', fn (): \Prism\Relay\RelayFactory => new RelayFactory);
17+
$this->app->bind('relay', fn (): RelayFactory => new RelayFactory);
1818
}
1919

2020
public function boot(): void

src/Transport/StdioTransport.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ protected function env(): array
146146
protected function launchProcess(): void
147147
{
148148
try {
149-
if (! $this->process instanceof \Symfony\Component\Process\Process) {
149+
if (! $this->process instanceof Process) {
150150
throw new TransportException('Process not initialized');
151151
}
152152

@@ -165,7 +165,7 @@ protected function launchProcess(): void
165165
protected function verifyProcessStarted(): void
166166
{
167167
if (! $this->isProcessRunning()) {
168-
if (! $this->process instanceof \Symfony\Component\Process\Process) {
168+
if (! $this->process instanceof Process) {
169169
throw new TransportException('Process not initialized');
170170
}
171171

@@ -194,7 +194,7 @@ protected function cleanup(): void
194194

195195
protected function sendPingRequest(): void
196196
{
197-
if (! $this->inputStream instanceof \Symfony\Component\Process\InputStream) {
197+
if (! $this->inputStream instanceof InputStream) {
198198
throw new TransportException('Input stream not initialized');
199199
}
200200

@@ -242,7 +242,7 @@ protected function ensureProcessIsRunning(): void
242242
*/
243243
protected function prepareRequest(string $method, array $params = []): void
244244
{
245-
if (! $this->inputStream instanceof \Symfony\Component\Process\InputStream || ! $this->process instanceof \Symfony\Component\Process\Process) {
245+
if (! $this->inputStream instanceof InputStream || ! $this->process instanceof Process) {
246246
throw new TransportException('Transport not properly initialized');
247247
}
248248

@@ -274,7 +274,7 @@ protected function prepareRequest(string $method, array $params = []): void
274274
*/
275275
protected function waitForResponse(): array
276276
{
277-
if (! $this->process instanceof \Symfony\Component\Process\Process) {
277+
if (! $this->process instanceof Process) {
278278
throw new TransportException('Process not initialized');
279279
}
280280

@@ -433,7 +433,7 @@ protected function handleJsonRpcError(array $error): void
433433
protected function handleResponseTimeout(string $responseBuffer, int $timeout): array
434434
{
435435
if (! $this->isProcessRunning()) {
436-
if (! $this->process instanceof \Symfony\Component\Process\Process) {
436+
if (! $this->process instanceof Process) {
437437
throw new TransportException('Process terminated unexpectedly and is no longer available');
438438
}
439439

@@ -456,7 +456,7 @@ protected function handleResponseTimeout(string $responseBuffer, int $timeout):
456456

457457
protected function closeInputStream(): void
458458
{
459-
if ($this->inputStream instanceof \Symfony\Component\Process\InputStream) {
459+
if ($this->inputStream instanceof InputStream) {
460460
$this->inputStream->close();
461461
$this->inputStream = null;
462462
}

tests/Feature/Facades/RelayFacadeTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Tests\Feature\Facades;
66

7+
use Prism\Prism\Tool;
8+
use Prism\Relay\Enums\Transport;
79
use Prism\Relay\Facades\Relay;
810
use Prism\Relay\Relay as RelayClass;
911
use Prism\Relay\RelayFactory;
@@ -43,8 +45,8 @@
4345
->once()
4446
->with('tools_test')
4547
->andReturn([
46-
new \Prism\Prism\Tool,
47-
new \Prism\Prism\Tool,
48+
new Tool,
49+
new Tool,
4850
]);
4951

5052
app()->instance('relay', $mock);
@@ -58,7 +60,7 @@
5860

5961
it('can make relay with custom config through facade', function (): void {
6062
$customConfig = [
61-
'transport' => \Prism\Relay\Enums\Transport::Http,
63+
'transport' => Transport::Http,
6264
'url' => 'http://custom.example.com/api',
6365
'timeout' => 45,
6466
];
@@ -73,7 +75,7 @@
7375

7476
it('can get tools with custom config through facade', function (): void {
7577
$customConfig = [
76-
'transport' => \Prism\Relay\Enums\Transport::Http,
78+
'transport' => Transport::Http,
7779
'url' => 'http://tools.example.com/api',
7880
'timeout' => 30,
7981
];
@@ -84,7 +86,7 @@
8486
->once()
8587
->with('custom_tools_server', $customConfig)
8688
->andReturn([
87-
new \Prism\Prism\Tool,
89+
new Tool,
8890
]);
8991

9092
app()->instance('relay', $mock);

tests/Pest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4+
use Tests\TestCase;
45

56
/*
67
|--------------------------------------------------------------------------
@@ -10,4 +11,4 @@
1011
| Custom functions to be used in tests.
1112
|
1213
*/
13-
uses(Tests\TestCase::class)->in(__DIR__);
14+
uses(TestCase::class)->in(__DIR__);

tests/TestDoubles/RelayFake.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Tests\TestDoubles;
66

7+
use Prism\Relay\Exceptions\ServerConfigurationException;
8+
use Prism\Relay\Exceptions\ToolDefinitionException;
79
use Prism\Relay\Relay;
810
use Prism\Relay\Transport\Transport;
911

@@ -23,7 +25,7 @@ class RelayFake extends Relay
2325
/**
2426
* Sets a custom transport for testing purposes.
2527
*
26-
* @throws \Prism\Relay\Exceptions\ServerConfigurationException
28+
* @throws ServerConfigurationException
2729
*/
2830
public function setTransport(Transport $transport): self
2931
{
@@ -59,13 +61,13 @@ public function shouldThrowOnTools(string $message = 'Failed to fetch tools'): s
5961
/**
6062
* @return array<int, array<string, mixed>>
6163
*
62-
* @throws \Prism\Relay\Exceptions\ToolDefinitionException
64+
* @throws ToolDefinitionException
6365
*/
6466
#[\Override]
6567
protected function fetchToolDefinitions(): array
6668
{
6769
if ($this->shouldThrowOnTools) {
68-
throw new \Prism\Relay\Exceptions\ToolDefinitionException($this->toolsExceptionMessage);
70+
throw new ToolDefinitionException($this->toolsExceptionMessage);
6971
}
7072

7173
if ($this->toolDefinitions !== []) {

tests/TestDoubles/StdioTransportFake.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Tests\TestDoubles;
66

77
use Mockery;
8+
use Prism\Relay\Exceptions\ServerConfigurationException;
89
use Prism\Relay\Exceptions\TransportException;
910
use Prism\Relay\Transport\StdioTransport;
1011
use Symfony\Component\Process\InputStream;
@@ -34,7 +35,7 @@ class StdioTransportFake extends StdioTransport
3435
protected ?string $lastMethod = null;
3536

3637
/**
37-
* @throws \Prism\Relay\Exceptions\ServerConfigurationException
38+
* @throws ServerConfigurationException
3839
*/
3940
public function __construct(array $config)
4041
{
@@ -159,7 +160,7 @@ public function shouldTimeoutResponse(): self
159160
public function shouldBeRunning(bool $running = true): self
160161
{
161162
$this->processIsRunning = $running;
162-
if ($this->process instanceof \Symfony\Component\Process\Process) {
163+
if ($this->process instanceof Process) {
163164
$this->process->shouldReceive('isRunning')->andReturn($running)->byDefault();
164165
}
165166

tests/Unit/RelayFactoryTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare(strict_types=1);
44

5+
use Prism\Relay\Enums\Transport;
56
use Prism\Relay\Exceptions\ServerConfigurationException;
67
use Prism\Relay\Relay;
78
use Prism\Relay\RelayFactory;
@@ -24,7 +25,7 @@
2425
it('throws exception for non-existent server', function (): void {
2526
$factory = new RelayFactory;
2627

27-
expect(fn (): \Prism\Relay\Relay => $factory->make('non_existent_server'))
28+
expect(fn (): Relay => $factory->make('non_existent_server'))
2829
->toThrow(ServerConfigurationException::class, "MCP server 'non_existent_server' is not configured.");
2930
});
3031

@@ -51,7 +52,7 @@
5152

5253
it('creates a Relay instance with custom config', function (): void {
5354
$customConfig = [
54-
'transport' => \Prism\Relay\Enums\Transport::Http,
55+
'transport' => Transport::Http,
5556
'url' => 'http://custom.example.com/api',
5657
'timeout' => 45,
5758
];
@@ -67,7 +68,7 @@
6768

6869
it('creates Relay with custom config when config parameter is provided', function (): void {
6970
$customConfig = [
70-
'transport' => \Prism\Relay\Enums\Transport::Stdio,
71+
'transport' => Transport::Stdio,
7172
'command' => ['echo', 'test'],
7273
'timeout' => 60,
7374
'env' => ['TEST_VAR' => 'test_value'],
@@ -106,7 +107,7 @@
106107

107108
it('tools method works with custom config', function (): void {
108109
$customConfig = [
109-
'transport' => \Prism\Relay\Enums\Transport::Http,
110+
'transport' => Transport::Http,
110111
'url' => 'http://tools.example.com/api',
111112
'timeout' => 30,
112113
];
@@ -119,8 +120,8 @@
119120
// Test method signature (this will call the method but we expect it might fail due to no real server)
120121
try {
121122
$factory->tools('tools_server', $customConfig);
122-
} catch (\Throwable $e) {
123+
} catch (Throwable $e) {
123124
// Expected to fail since we don't have a real MCP server, but method should accept the parameters
124-
expect($e)->toBeInstanceOf(\Throwable::class);
125+
expect($e)->toBeInstanceOf(Throwable::class);
125126
}
126127
});

tests/Unit/RelayOAuthTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
$relay = new Relay($this->serverName);
4343

44-
expect(fn (): \Prism\Relay\Relay => $relay->withToken('my-oauth-token'))
44+
expect(fn (): Relay => $relay->withToken('my-oauth-token'))
4545
->toThrow(ServerConfigurationException::class, 'OAuth access tokens are only supported with HTTP transport');
4646
});
4747

@@ -101,7 +101,7 @@ public function getCacheKey(): string
101101
});
102102

103103
it('two different tokens produce two different cache keys', function (): void {
104-
$makeRelay = fn (): \Prism\Relay\Relay => new class($this->serverName) extends Relay
104+
$makeRelay = fn (): Relay => new class($this->serverName) extends Relay
105105
{
106106
public function getCacheKey(): string
107107
{

tests/Unit/RelayTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
it('throws exception for non-existent server', function (): void {
3232
$nonExistentServer = 'non_existent_server';
33-
expect(fn (): \Tests\TestDoubles\RelayFake => new RelayFake($nonExistentServer))
33+
expect(fn (): RelayFake => new RelayFake($nonExistentServer))
3434
->toThrow(ServerConfigurationException::class);
3535
});
3636

0 commit comments

Comments
 (0)