From 38ca9e5538719491cc65affaf05dfa9a125d716e Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Tue, 6 Jan 2026 15:28:36 +0530 Subject: [PATCH 1/3] use `assertSame` in tests --- tests/Pools/ConnectionTest.php | 42 +++++++-------- tests/Pools/GroupTest.php | 36 ++++++------- tests/Pools/PoolTest.php | 96 +++++++++++++++++----------------- 3 files changed, 87 insertions(+), 87 deletions(-) diff --git a/tests/Pools/ConnectionTest.php b/tests/Pools/ConnectionTest.php index 1a8a126..348f3ae 100644 --- a/tests/Pools/ConnectionTest.php +++ b/tests/Pools/ConnectionTest.php @@ -22,34 +22,34 @@ public function setUp(): void public function testGetID(): void { - $this->assertEquals(null, $this->object->getID()); + $this->assertSame('', $this->object->getID()); $this->object->setID('test'); - $this->assertEquals('test', $this->object->getID()); + $this->assertSame('test', $this->object->getID()); } public function testSetID(): void { - $this->assertEquals(null, $this->object->getID()); + $this->assertSame('', $this->object->getID()); $this->assertInstanceOf(Connection::class, $this->object->setID('test')); - $this->assertEquals('test', $this->object->getID()); + $this->assertSame('test', $this->object->getID()); } public function testGetResource(): void { - $this->assertEquals('x', $this->object->getResource()); + $this->assertSame('x', $this->object->getResource()); } public function testSetResource(): void { - $this->assertEquals('x', $this->object->getResource()); + $this->assertSame('x', $this->object->getResource()); $this->assertInstanceOf(Connection::class, $this->object->setResource('y')); - $this->assertEquals('y', $this->object->getResource()); + $this->assertSame('y', $this->object->getResource()); } public function testSetPool(): void @@ -74,30 +74,30 @@ public function testGetPool(): void } $this->assertInstanceOf(Pool::class, $pool); - $this->assertEquals('test', $pool->getName()); + $this->assertSame('test', $pool->getName()); } public function testReclaim(): void { $pool = new Pool('test', 2, fn () => 'x'); - $this->assertEquals(2, $pool->count()); + $this->assertSame(2, $pool->count()); $connection1 = $pool->pop(); - $this->assertEquals(1, $pool->count()); + $this->assertSame(1, $pool->count()); $connection2 = $pool->pop(); - $this->assertEquals(0, $pool->count()); + $this->assertSame(0, $pool->count()); $this->assertInstanceOf(Pool::class, $connection1->reclaim()); - $this->assertEquals(1, $pool->count()); + $this->assertSame(1, $pool->count()); $this->assertInstanceOf(Pool::class, $connection2->reclaim()); - $this->assertEquals(2, $pool->count()); + $this->assertSame(2, $pool->count()); } public function testReclaimException(): void @@ -114,27 +114,27 @@ public function testDestroy(): void return $i <= 2 ? 'x' : 'y'; }); - $this->assertEquals(2, $object->count()); + $this->assertSame(2, $object->count()); $connection1 = $object->pop(); $connection2 = $object->pop(); - $this->assertEquals(0, $object->count()); + $this->assertSame(0, $object->count()); - $this->assertEquals('x', $connection1->getResource()); - $this->assertEquals('x', $connection2->getResource()); + $this->assertSame('x', $connection1->getResource()); + $this->assertSame('x', $connection2->getResource()); $connection1->destroy(); $connection2->destroy(); - $this->assertEquals(2, $object->count()); + $this->assertSame(2, $object->count()); $connection1 = $object->pop(); $connection2 = $object->pop(); - $this->assertEquals(0, $object->count()); + $this->assertSame(0, $object->count()); - $this->assertEquals('y', $connection1->getResource()); - $this->assertEquals('y', $connection2->getResource()); + $this->assertSame('y', $connection1->getResource()); + $this->assertSame('y', $connection2->getResource()); } } diff --git a/tests/Pools/GroupTest.php b/tests/Pools/GroupTest.php index de1c7ec..bb851ef 100644 --- a/tests/Pools/GroupTest.php +++ b/tests/Pools/GroupTest.php @@ -52,39 +52,39 @@ public function testReset(): void { $this->object->add(new Pool('test', 5, fn () => 'x')); - $this->assertEquals(5, $this->object->get('test')->count()); + $this->assertSame(5, $this->object->get('test')->count()); $this->object->get('test')->pop(); $this->object->get('test')->pop(); $this->object->get('test')->pop(); - $this->assertEquals(2, $this->object->get('test')->count()); + $this->assertSame(2, $this->object->get('test')->count()); $this->object->reclaim(); - $this->assertEquals(5, $this->object->get('test')->count()); + $this->assertSame(5, $this->object->get('test')->count()); } public function testReconnectAttempts(): void { $this->object->add(new Pool('test', 5, fn () => 'x')); - $this->assertEquals(3, $this->object->get('test')->getReconnectAttempts()); + $this->assertSame(3, $this->object->get('test')->getReconnectAttempts()); $this->object->setReconnectAttempts(5); - $this->assertEquals(5, $this->object->get('test')->getReconnectAttempts()); + $this->assertSame(5, $this->object->get('test')->getReconnectAttempts()); } public function testReconnectSleep(): void { $this->object->add(new Pool('test', 5, fn () => 'x')); - $this->assertEquals(1, $this->object->get('test')->getReconnectSleep()); + $this->assertSame(1, $this->object->get('test')->getReconnectSleep()); $this->object->setReconnectSleep(2); - $this->assertEquals(2, $this->object->get('test')->getReconnectSleep()); + $this->assertSame(2, $this->object->get('test')->getReconnectSleep()); } public function testUse(): void @@ -97,22 +97,22 @@ public function testUse(): void $this->object->add($pool2); $this->object->add($pool3); - $this->assertEquals(1, $pool1->count()); - $this->assertEquals(1, $pool2->count()); - $this->assertEquals(1, $pool3->count()); + $this->assertSame(1, $pool1->count()); + $this->assertSame(1, $pool2->count()); + $this->assertSame(1, $pool3->count()); // @phpstan-ignore argument.type $this->object->use(['pool1', 'pool3'], function ($one, $three) use ($pool1, $pool2, $pool3): void { - $this->assertEquals('1', $one); - $this->assertEquals('3', $three); + $this->assertSame('1', $one); + $this->assertSame('3', $three); - $this->assertEquals(0, $pool1->count()); - $this->assertEquals(1, $pool2->count()); - $this->assertEquals(0, $pool3->count()); + $this->assertSame(0, $pool1->count()); + $this->assertSame(1, $pool2->count()); + $this->assertSame(0, $pool3->count()); }); - $this->assertEquals(1, $pool1->count()); - $this->assertEquals(1, $pool2->count()); - $this->assertEquals(1, $pool3->count()); + $this->assertSame(1, $pool1->count()); + $this->assertSame(1, $pool2->count()); + $this->assertSame(1, $pool3->count()); } } diff --git a/tests/Pools/PoolTest.php b/tests/Pools/PoolTest.php index 890340e..c7ffb96 100644 --- a/tests/Pools/PoolTest.php +++ b/tests/Pools/PoolTest.php @@ -23,80 +23,80 @@ public function setUp(): void public function testGetName(): void { - $this->assertEquals('test', $this->object->getName()); + $this->assertSame('test', $this->object->getName()); } public function testGetSize(): void { - $this->assertEquals(5, $this->object->getSize()); + $this->assertSame(5, $this->object->getSize()); } public function testGetReconnectAttempts(): void { - $this->assertEquals(3, $this->object->getReconnectAttempts()); + $this->assertSame(3, $this->object->getReconnectAttempts()); } public function testSetReconnectAttempts(): void { - $this->assertEquals(3, $this->object->getReconnectAttempts()); + $this->assertSame(3, $this->object->getReconnectAttempts()); $this->object->setReconnectAttempts(20); - $this->assertEquals(20, $this->object->getReconnectAttempts()); + $this->assertSame(20, $this->object->getReconnectAttempts()); } public function testGetReconnectSleep(): void { - $this->assertEquals(1, $this->object->getReconnectSleep()); + $this->assertSame(1, $this->object->getReconnectSleep()); } public function testSetReconnectSleep(): void { - $this->assertEquals(1, $this->object->getReconnectSleep()); + $this->assertSame(1, $this->object->getReconnectSleep()); $this->object->setReconnectSleep(20); - $this->assertEquals(20, $this->object->getReconnectSleep()); + $this->assertSame(20, $this->object->getReconnectSleep()); } public function testGetRetryAttempts(): void { - $this->assertEquals(3, $this->object->getRetryAttempts()); + $this->assertSame(3, $this->object->getRetryAttempts()); } public function testSetRetryAttempts(): void { - $this->assertEquals(3, $this->object->getRetryAttempts()); + $this->assertSame(3, $this->object->getRetryAttempts()); $this->object->setRetryAttempts(20); - $this->assertEquals(20, $this->object->getRetryAttempts()); + $this->assertSame(20, $this->object->getRetryAttempts()); } public function testGetRetrySleep(): void { - $this->assertEquals(1, $this->object->getRetrySleep()); + $this->assertSame(1, $this->object->getRetrySleep()); } public function testSetRetrySleep(): void { - $this->assertEquals(1, $this->object->getRetrySleep()); + $this->assertSame(1, $this->object->getRetrySleep()); $this->object->setRetrySleep(20); - $this->assertEquals(20, $this->object->getRetrySleep()); + $this->assertSame(20, $this->object->getRetrySleep()); } public function testPop(): void { - $this->assertEquals(5, $this->object->count()); + $this->assertSame(5, $this->object->count()); $connection = $this->object->pop(); - $this->assertEquals(4, $this->object->count()); + $this->assertSame(4, $this->object->count()); $this->assertInstanceOf(Connection::class, $connection); - $this->assertEquals('x', $connection->getResource()); + $this->assertSame('x', $connection->getResource()); // Pool should be empty $this->expectException(Exception::class); @@ -110,57 +110,57 @@ public function testPop(): void public function testUse(): void { - $this->assertEquals(5, $this->object->count()); + $this->assertSame(5, $this->object->count()); $this->object->use(function ($resource): void { - $this->assertEquals(4, $this->object->count()); - $this->assertEquals('x', $resource); + $this->assertSame(4, $this->object->count()); + $this->assertSame('x', $resource); }); - $this->assertEquals(5, $this->object->count()); + $this->assertSame(5, $this->object->count()); } public function testPush(): void { - $this->assertEquals(5, $this->object->count()); + $this->assertSame(5, $this->object->count()); $connection = $this->object->pop(); - $this->assertEquals(4, $this->object->count()); + $this->assertSame(4, $this->object->count()); $this->assertInstanceOf(Connection::class, $connection); - $this->assertEquals('x', $connection->getResource()); + $this->assertSame('x', $connection->getResource()); $this->assertInstanceOf(Pool::class, $this->object->push($connection)); - $this->assertEquals(5, $this->object->count()); + $this->assertSame(5, $this->object->count()); } public function testCount(): void { - $this->assertEquals(5, $this->object->count()); + $this->assertSame(5, $this->object->count()); $connection = $this->object->pop(); - $this->assertEquals(4, $this->object->count()); + $this->assertSame(4, $this->object->count()); $this->object->push($connection); - $this->assertEquals(5, $this->object->count()); + $this->assertSame(5, $this->object->count()); } public function testReclaim(): void { - $this->assertEquals(5, $this->object->count()); + $this->assertSame(5, $this->object->count()); $this->object->pop(); $this->object->pop(); $this->object->pop(); - $this->assertEquals(2, $this->object->count()); + $this->assertSame(2, $this->object->count()); $this->object->reclaim(); - $this->assertEquals(5, $this->object->count()); + $this->assertSame(5, $this->object->count()); } public function testIsEmpty(): void @@ -171,20 +171,20 @@ public function testIsEmpty(): void $this->object->pop(); $this->object->pop(); - $this->assertEquals(true, $this->object->isEmpty()); + $this->assertSame(true, $this->object->isEmpty()); } public function testIsFull(): void { - $this->assertEquals(true, $this->object->isFull()); + $this->assertSame(true, $this->object->isFull()); $connection = $this->object->pop(); - $this->assertEquals(false, $this->object->isFull()); + $this->assertSame(false, $this->object->isFull()); $this->object->push($connection); - $this->assertEquals(true, $this->object->isFull()); + $this->assertSame(true, $this->object->isFull()); $this->object->pop(); $this->object->pop(); @@ -192,11 +192,11 @@ public function testIsFull(): void $this->object->pop(); $this->object->pop(); - $this->assertEquals(false, $this->object->isFull()); + $this->assertSame(false, $this->object->isFull()); $this->object->reclaim(); - $this->assertEquals(true, $this->object->isFull()); + $this->assertSame(true, $this->object->isFull()); $this->object->pop(); $this->object->pop(); @@ -204,7 +204,7 @@ public function testIsFull(): void $this->object->pop(); $this->object->pop(); - $this->assertEquals(false, $this->object->isFull()); + $this->assertSame(false, $this->object->isFull()); } public function testRetry(): void @@ -238,27 +238,27 @@ public function testDestroy(): void return $i <= 2 ? 'x' : 'y'; }); - $this->assertEquals(2, $object->count()); + $this->assertSame(2, $object->count()); $connection1 = $object->pop(); $connection2 = $object->pop(); - $this->assertEquals(0, $object->count()); + $this->assertSame(0, $object->count()); - $this->assertEquals('x', $connection1->getResource()); - $this->assertEquals('x', $connection2->getResource()); + $this->assertSame('x', $connection1->getResource()); + $this->assertSame('x', $connection2->getResource()); $object->destroy(); - $this->assertEquals(2, $object->count()); + $this->assertSame(2, $object->count()); $connection1 = $object->pop(); $connection2 = $object->pop(); - $this->assertEquals(0, $object->count()); + $this->assertSame(0, $object->count()); - $this->assertEquals('y', $connection1->getResource()); - $this->assertEquals('y', $connection2->getResource()); + $this->assertSame('y', $connection1->getResource()); + $this->assertSame('y', $connection2->getResource()); } public function testTelemetry(): void @@ -279,7 +279,7 @@ public function testTelemetry(): void } }; - $this->assertEquals(5, $this->object->count()); + $this->assertSame(5, $this->object->count()); $allocate(3, function () use ($telemetry): void { /** @var object{values: array} $openGauge */ @@ -293,7 +293,7 @@ public function testTelemetry(): void $this->assertEquals([0, 0, 0], $idleGauge->values); }); - $this->assertEquals(5, $this->object->count()); + $this->assertSame(5, $this->object->count()); $allocate(1, function () use ($telemetry): void { /** @var object{values: array} $openGauge */ From d0ef853c26541dd2dbd3f375028962a3db8c6317 Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Thu, 15 Jan 2026 16:24:49 +0530 Subject: [PATCH 2/3] some more --- tests/Pools/Adapter/SwooleTest.php | 26 +++++++++++----------- tests/Pools/Scopes/ConnectionTestScope.php | 26 +++++++++++----------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/Pools/Adapter/SwooleTest.php b/tests/Pools/Adapter/SwooleTest.php index 9434d11..2864272 100644 --- a/tests/Pools/Adapter/SwooleTest.php +++ b/tests/Pools/Adapter/SwooleTest.php @@ -103,13 +103,13 @@ public function testSwooleCoroutineRaceCondition(): void // Assertions inside coroutine context $this->assertEmpty($errors, 'Errors occurred: ' . implode(', ', $errors)); - $this->assertEquals(10, $successCount, 'All 10 coroutines should successfully complete'); + $this->assertSame(10, $successCount, 'All 10 coroutines should successfully complete'); // Pool should be full again after all connections are reclaimed - $this->assertEquals(5, $pool->count(), 'Pool should have all 5 connections back'); + $this->assertSame(5, $pool->count(), 'Pool should have all 5 connections back'); // Should only create exactly pool size connections (no race conditions with new implementation) - $this->assertEquals(5, $connectionCounter, 'Should create exactly 5 connections (pool size)'); + $this->assertSame(5, $connectionCounter, 'Should create exactly 5 connections (pool size)'); }); } @@ -163,14 +163,14 @@ public function testSwooleCoroutineHighConcurrency(): void } // All requests should succeed with proper retry logic - $this->assertEquals($totalRequests, $successCount, "All {$totalRequests} requests should succeed"); - $this->assertEquals(0, $errorCount, 'No errors should occur with proper concurrency handling'); + $this->assertSame($totalRequests, $successCount, "All {$totalRequests} requests should succeed"); + $this->assertSame(0, $errorCount, 'No errors should occur with proper concurrency handling'); // Pool should be full again - $this->assertEquals(3, $pool->count(), 'Pool should have all 3 connections back'); + $this->assertSame(3, $pool->count(), 'Pool should have all 3 connections back'); // Should only create 3 connections (pool size) - $this->assertEquals(3, $connectionCounter, 'Should only create 3 connections (pool size)'); + $this->assertSame(3, $connectionCounter, 'Should only create 3 connections (pool size)'); }); } @@ -286,14 +286,14 @@ public function testSwooleCoroutineIdleConnectionReuse(): void } // Assertions inside coroutine context - $this->assertEquals(3, $connectionCounter, 'Should only create 3 connections total'); + $this->assertSame(3, $connectionCounter, 'Should only create 3 connections total'); $this->assertCount(3, $connectionIds['first'], 'First wave should have 3 connections'); $this->assertCount(3, $connectionIds['second'], 'Second wave should have 3 connections'); // Second wave should reuse connections from first wave sort($connectionIds['first']); sort($connectionIds['second']); - $this->assertEquals($connectionIds['first'], $connectionIds['second'], 'Second wave should reuse same connection IDs'); + $this->assertSame($connectionIds['first'], $connectionIds['second'], 'Second wave should reuse same connection IDs'); }); } @@ -347,10 +347,10 @@ public function testSwooleCoroutineStressTest(): void } // Assertions inside coroutine context - $this->assertEquals($totalRequests, $successCount, "All {$totalRequests} requests should succeed"); - $this->assertEquals(0, $errorCount, 'No errors should occur'); - $this->assertEquals(10, $connectionCounter, 'Should create exactly 10 connections (pool size)'); - $this->assertEquals(10, $pool->count(), 'Pool should have all connections back'); + $this->assertSame($totalRequests, $successCount, "All {$totalRequests} requests should succeed"); + $this->assertSame(0, $errorCount, 'No errors should occur'); + $this->assertSame(10, $connectionCounter, 'Should create exactly 10 connections (pool size)'); + $this->assertSame(10, $pool->count(), 'Pool should have all connections back'); }); } } diff --git a/tests/Pools/Scopes/ConnectionTestScope.php b/tests/Pools/Scopes/ConnectionTestScope.php index cd4ddfb..9cba153 100644 --- a/tests/Pools/Scopes/ConnectionTestScope.php +++ b/tests/Pools/Scopes/ConnectionTestScope.php @@ -101,23 +101,23 @@ public function testConnectionReclaim(): void $this->execute(function (): void { $pool = new Pool($this->getAdapter(), 'test', 2, fn () => 'x'); - $this->assertEquals(2, $pool->count()); + $this->assertSame(2, $pool->count()); $connection1 = $pool->pop(); - $this->assertEquals(1, $pool->count()); + $this->assertSame(1, $pool->count()); $connection2 = $pool->pop(); - $this->assertEquals(0, $pool->count()); + $this->assertSame(0, $pool->count()); $this->assertInstanceOf(Pool::class, $connection1->reclaim()); - $this->assertEquals(1, $pool->count()); + $this->assertSame(1, $pool->count()); $this->assertInstanceOf(Pool::class, $connection2->reclaim()); - $this->assertEquals(2, $pool->count()); + $this->assertSame(2, $pool->count()); }); } @@ -139,28 +139,28 @@ public function testConnectionDestroy(): void return $i <= 2 ? 'x' : 'y'; }); - $this->assertEquals(2, $object->count()); + $this->assertSame(2, $object->count()); $connection1 = $object->pop(); $connection2 = $object->pop(); - $this->assertEquals(0, $object->count()); + $this->assertSame(0, $object->count()); - $this->assertEquals('x', $connection1->getResource()); - $this->assertEquals('x', $connection2->getResource()); + $this->assertSame('x', $connection1->getResource()); + $this->assertSame('x', $connection2->getResource()); $connection1->destroy(); $connection2->destroy(); - $this->assertEquals(2, $object->count()); + $this->assertSame(2, $object->count()); $connection1 = $object->pop(); $connection2 = $object->pop(); - $this->assertEquals(0, $object->count()); + $this->assertSame(0, $object->count()); - $this->assertEquals('y', $connection1->getResource()); - $this->assertEquals('y', $connection2->getResource()); + $this->assertSame('y', $connection1->getResource()); + $this->assertSame('y', $connection2->getResource()); }); } } From 14e78b030252e48c07bd4f29dfdcbcc675d884f3 Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Thu, 15 Jan 2026 17:34:10 +0530 Subject: [PATCH 3/3] fix failing tests --- tests/Pools/Scopes/ConnectionTestScope.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Pools/Scopes/ConnectionTestScope.php b/tests/Pools/Scopes/ConnectionTestScope.php index 9cba153..cffa3d1 100644 --- a/tests/Pools/Scopes/ConnectionTestScope.php +++ b/tests/Pools/Scopes/ConnectionTestScope.php @@ -25,7 +25,7 @@ public function testConnectionGetID(): void { $this->execute(function (): void { $this->setUpConnection(); - $this->assertSame(null, $this->connectionObject->getID()); + $this->assertSame('', $this->connectionObject->getID()); $this->connectionObject->setID('test'); @@ -37,7 +37,7 @@ public function testConnectionSetID(): void { $this->execute(function (): void { $this->setUpConnection(); - $this->assertSame(null, $this->connectionObject->getID()); + $this->assertSame('', $this->connectionObject->getID()); $this->assertInstanceOf(Connection::class, $this->connectionObject->setID('test'));