From 44989f3aaeff59984855f96046e97163b5071686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ha=C5=82as?= Date: Sat, 2 May 2026 09:43:26 +0200 Subject: [PATCH 1/2] M1I09: SocketFactory (fallback chain) --- src/Server/Socket/SocketFactory.php | 31 +++++++++++++++++++ tests/Server/Socket/SocketFactoryTest.php | 37 +++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/Server/Socket/SocketFactory.php create mode 100644 tests/Server/Socket/SocketFactoryTest.php diff --git a/src/Server/Socket/SocketFactory.php b/src/Server/Socket/SocketFactory.php new file mode 100644 index 0000000..5625aa7 --- /dev/null +++ b/src/Server/Socket/SocketFactory.php @@ -0,0 +1,31 @@ + self::createReuseOrFallback(), + ProxyType::FORK_SHARED => new ForkSharedProxy(), + ProxyType::MASTER => new MasterProxy(), + }; + } + + private static function createReuseOrFallback(): SocketProxyInterface + { + $proxy = new ReusePortProxy(); + + if ($proxy->isSupported()) { + return $proxy; + } + + return new ForkSharedProxy(); + } +} diff --git a/tests/Server/Socket/SocketFactoryTest.php b/tests/Server/Socket/SocketFactoryTest.php new file mode 100644 index 0000000..3d6b320 --- /dev/null +++ b/tests/Server/Socket/SocketFactoryTest.php @@ -0,0 +1,37 @@ +assertInstanceOf(MasterProxy::class, $proxy); + } + + public function testCreateForkSharedReturnsForkSharedProxy(): void + { + $proxy = SocketFactory::create(ProxyType::FORK_SHARED, 8080, ProtocolType::HTTP); + + $this->assertInstanceOf(ForkSharedProxy::class, $proxy); + } + + public function testCreateReusePortFallbacksToForkShared(): void + { + $proxy = SocketFactory::create(ProxyType::REUSE_PORT, 8080, ProtocolType::HTTP); + + $this->assertTrue($proxy instanceof ReusePortProxy || $proxy instanceof ForkSharedProxy); + } +} From 23b5e2195c5eee1754a478c19eb70728ac24d2a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ha=C5=82as?= Date: Sat, 2 May 2026 09:48:53 +0200 Subject: [PATCH 2/2] M1I09: strengthen fallback test with explicit supported/unsupported paths --- tests/Server/Socket/SocketFactoryTest.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/Server/Socket/SocketFactoryTest.php b/tests/Server/Socket/SocketFactoryTest.php index 3d6b320..0851fda 100644 --- a/tests/Server/Socket/SocketFactoryTest.php +++ b/tests/Server/Socket/SocketFactoryTest.php @@ -28,10 +28,25 @@ public function testCreateForkSharedReturnsForkSharedProxy(): void $this->assertInstanceOf(ForkSharedProxy::class, $proxy); } - public function testCreateReusePortFallbacksToForkShared(): void + public function testCreateReusePortReturnsReusePortWhenSupported(): void { + if (!(new ReusePortProxy())->isSupported()) { + $this->markTestSkipped('SO_REUSEPORT not supported on this platform'); + } + + $proxy = SocketFactory::create(ProxyType::REUSE_PORT, 8080, ProtocolType::HTTP); + + $this->assertInstanceOf(ReusePortProxy::class, $proxy); + } + + public function testCreateReusePortFallsBackToForkSharedWhenNotSupported(): void + { + if ((new ReusePortProxy())->isSupported()) { + $this->markTestSkipped('SO_REUSEPORT is supported on this platform'); + } + $proxy = SocketFactory::create(ProxyType::REUSE_PORT, 8080, ProtocolType::HTTP); - $this->assertTrue($proxy instanceof ReusePortProxy || $proxy instanceof ForkSharedProxy); + $this->assertInstanceOf(ForkSharedProxy::class, $proxy); } }