33namespace Utopia \Tests ;
44
55use PHPUnit \Framework \TestCase ;
6- use Utopia \Proxy \Adapter \ HTTP \ Swoole as HTTPAdapter ;
7- use Utopia \Proxy \Adapter \SMTP \ Swoole as SMTPAdapter ;
8- use Utopia \Proxy \Adapter \ TCP \ Swoole as TCPAdapter ;
6+ use Utopia \Proxy \Adapter ;
7+ use Utopia \Proxy \Adapter \TCP as TCPAdapter ;
8+ use Utopia \Proxy \Protocol ;
99use Utopia \Proxy \Resolver \Exception as ResolverException ;
1010
1111class AdapterActionsTest extends TestCase
@@ -23,9 +23,9 @@ protected function setUp(): void
2323
2424 public function test_resolver_is_assigned_to_adapters (): void
2525 {
26- $ http = new HTTPAdapter ($ this ->resolver );
26+ $ http = new Adapter ($ this ->resolver , name: ' HTTP ' , protocol: Protocol:: HTTP );
2727 $ tcp = new TCPAdapter ($ this ->resolver , port: 5432 );
28- $ smtp = new SMTPAdapter ($ this ->resolver );
28+ $ smtp = new Adapter ($ this ->resolver , name: ' SMTP ' , protocol: Protocol:: SMTP );
2929
3030 $ this ->assertSame ($ this ->resolver , $ http ->resolver );
3131 $ this ->assertSame ($ this ->resolver , $ tcp ->resolver );
@@ -35,18 +35,18 @@ public function test_resolver_is_assigned_to_adapters(): void
3535 public function test_resolve_routes_and_returns_endpoint (): void
3636 {
3737 $ this ->resolver ->setEndpoint ('127.0.0.1:8080 ' );
38- $ adapter = new HTTPAdapter ($ this ->resolver );
38+ $ adapter = new Adapter ($ this ->resolver , name: ' HTTP ' , protocol: Protocol:: HTTP );
3939 $ adapter ->setSkipValidation (true );
4040
4141 $ result = $ adapter ->route ('api.example.com ' );
4242
4343 $ this ->assertSame ('127.0.0.1:8080 ' , $ result ->endpoint );
44- $ this ->assertSame (' http ' , $ result ->protocol );
44+ $ this ->assertSame (Protocol:: HTTP , $ result ->protocol );
4545 }
4646
4747 public function test_notify_connect_delegates_to_resolver (): void
4848 {
49- $ adapter = new HTTPAdapter ($ this ->resolver );
49+ $ adapter = new Adapter ($ this ->resolver , name: ' HTTP ' , protocol: Protocol:: HTTP );
5050
5151 $ adapter ->notifyConnect ('resource-123 ' , ['extra ' => 'data ' ]);
5252
@@ -58,7 +58,7 @@ public function test_notify_connect_delegates_to_resolver(): void
5858
5959 public function test_notify_close_delegates_to_resolver (): void
6060 {
61- $ adapter = new HTTPAdapter ($ this ->resolver );
61+ $ adapter = new Adapter ($ this ->resolver , name: ' HTTP ' , protocol: Protocol:: HTTP );
6262
6363 $ adapter ->notifyClose ('resource-123 ' , ['extra ' => 'data ' ]);
6464
@@ -70,29 +70,29 @@ public function test_notify_close_delegates_to_resolver(): void
7070
7171 public function test_track_activity_delegates_to_resolver_with_throttling (): void
7272 {
73- $ adapter = new HTTPAdapter ($ this ->resolver );
73+ $ adapter = new Adapter ($ this ->resolver , name: ' HTTP ' , protocol: Protocol:: HTTP );
7474 $ adapter ->setActivityInterval (1 ); // 1 second throttle
7575
7676 // First call should trigger activity tracking
77- $ adapter ->trackActivity ('resource-123 ' );
77+ $ adapter ->track ('resource-123 ' );
7878 $ this ->assertCount (1 , $ this ->resolver ->getActivities ());
7979
8080 // Immediate second call should be throttled
81- $ adapter ->trackActivity ('resource-123 ' );
81+ $ adapter ->track ('resource-123 ' );
8282 $ this ->assertCount (1 , $ this ->resolver ->getActivities ());
8383
8484 // Wait for throttle interval to pass
8585 sleep (2 );
8686
8787 // Third call should trigger activity tracking
88- $ adapter ->trackActivity ('resource-123 ' );
88+ $ adapter ->track ('resource-123 ' );
8989 $ this ->assertCount (2 , $ this ->resolver ->getActivities ());
9090 }
9191
9292 public function test_routing_error_throws_exception (): void
9393 {
9494 $ this ->resolver ->setException (new ResolverException ('No backend found ' ));
95- $ adapter = new HTTPAdapter ($ this ->resolver );
95+ $ adapter = new Adapter ($ this ->resolver , name: ' HTTP ' , protocol: Protocol:: HTTP );
9696
9797 $ this ->expectException (ResolverException::class);
9898 $ this ->expectExceptionMessage ('No backend found ' );
@@ -103,7 +103,7 @@ public function test_routing_error_throws_exception(): void
103103 public function test_empty_endpoint_throws_exception (): void
104104 {
105105 $ this ->resolver ->setEndpoint ('' );
106- $ adapter = new HTTPAdapter ($ this ->resolver );
106+ $ adapter = new Adapter ($ this ->resolver , name: ' HTTP ' , protocol: Protocol:: HTTP );
107107
108108 $ this ->expectException (ResolverException::class);
109109 $ this ->expectExceptionMessage ('Resolver returned empty endpoint ' );
@@ -115,7 +115,7 @@ public function test_skip_validation_allows_private_i_ps(): void
115115 {
116116 // 10.0.0.1 is a private IP that would normally be blocked
117117 $ this ->resolver ->setEndpoint ('10.0.0.1:8080 ' );
118- $ adapter = new HTTPAdapter ($ this ->resolver );
118+ $ adapter = new Adapter ($ this ->resolver , name: ' HTTP ' , protocol: Protocol:: HTTP );
119119 $ adapter ->setSkipValidation (true );
120120
121121 // Should not throw exception with validation disabled
0 commit comments