Skip to content

Commit 74ba7dc

Browse files
authored
Merge pull request #25 from utopia-php/chore-assertSame
use `assertSame` in tests
2 parents 0bddaf4 + 14e78b0 commit 74ba7dc

File tree

4 files changed

+106
-106
lines changed

4 files changed

+106
-106
lines changed

tests/Pools/Adapter/SwooleTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ public function testSwooleCoroutineRaceCondition(): void
103103

104104
// Assertions inside coroutine context
105105
$this->assertEmpty($errors, 'Errors occurred: ' . implode(', ', $errors));
106-
$this->assertEquals(10, $successCount, 'All 10 coroutines should successfully complete');
106+
$this->assertSame(10, $successCount, 'All 10 coroutines should successfully complete');
107107

108108
// Pool should be full again after all connections are reclaimed
109-
$this->assertEquals(5, $pool->count(), 'Pool should have all 5 connections back');
109+
$this->assertSame(5, $pool->count(), 'Pool should have all 5 connections back');
110110

111111
// Should only create exactly pool size connections (no race conditions with new implementation)
112-
$this->assertEquals(5, $connectionCounter, 'Should create exactly 5 connections (pool size)');
112+
$this->assertSame(5, $connectionCounter, 'Should create exactly 5 connections (pool size)');
113113
});
114114
}
115115

@@ -163,14 +163,14 @@ public function testSwooleCoroutineHighConcurrency(): void
163163
}
164164

165165
// All requests should succeed with proper retry logic
166-
$this->assertEquals($totalRequests, $successCount, "All {$totalRequests} requests should succeed");
167-
$this->assertEquals(0, $errorCount, 'No errors should occur with proper concurrency handling');
166+
$this->assertSame($totalRequests, $successCount, "All {$totalRequests} requests should succeed");
167+
$this->assertSame(0, $errorCount, 'No errors should occur with proper concurrency handling');
168168

169169
// Pool should be full again
170-
$this->assertEquals(3, $pool->count(), 'Pool should have all 3 connections back');
170+
$this->assertSame(3, $pool->count(), 'Pool should have all 3 connections back');
171171

172172
// Should only create 3 connections (pool size)
173-
$this->assertEquals(3, $connectionCounter, 'Should only create 3 connections (pool size)');
173+
$this->assertSame(3, $connectionCounter, 'Should only create 3 connections (pool size)');
174174
});
175175
}
176176

@@ -286,14 +286,14 @@ public function testSwooleCoroutineIdleConnectionReuse(): void
286286
}
287287

288288
// Assertions inside coroutine context
289-
$this->assertEquals(3, $connectionCounter, 'Should only create 3 connections total');
289+
$this->assertSame(3, $connectionCounter, 'Should only create 3 connections total');
290290
$this->assertCount(3, $connectionIds['first'], 'First wave should have 3 connections');
291291
$this->assertCount(3, $connectionIds['second'], 'Second wave should have 3 connections');
292292

293293
// Second wave should reuse connections from first wave
294294
sort($connectionIds['first']);
295295
sort($connectionIds['second']);
296-
$this->assertEquals($connectionIds['first'], $connectionIds['second'], 'Second wave should reuse same connection IDs');
296+
$this->assertSame($connectionIds['first'], $connectionIds['second'], 'Second wave should reuse same connection IDs');
297297
});
298298
}
299299

@@ -347,10 +347,10 @@ public function testSwooleCoroutineStressTest(): void
347347
}
348348

349349
// Assertions inside coroutine context
350-
$this->assertEquals($totalRequests, $successCount, "All {$totalRequests} requests should succeed");
351-
$this->assertEquals(0, $errorCount, 'No errors should occur');
352-
$this->assertEquals(10, $connectionCounter, 'Should create exactly 10 connections (pool size)');
353-
$this->assertEquals(10, $pool->count(), 'Pool should have all connections back');
350+
$this->assertSame($totalRequests, $successCount, "All {$totalRequests} requests should succeed");
351+
$this->assertSame(0, $errorCount, 'No errors should occur');
352+
$this->assertSame(10, $connectionCounter, 'Should create exactly 10 connections (pool size)');
353+
$this->assertSame(10, $pool->count(), 'Pool should have all connections back');
354354
});
355355
}
356356
}

tests/Pools/Scopes/ConnectionTestScope.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,43 @@ public function testConnectionGetID(): void
2525
{
2626
$this->execute(function (): void {
2727
$this->setUpConnection();
28-
$this->assertEquals(null, $this->connectionObject->getID());
28+
$this->assertSame('', $this->connectionObject->getID());
2929

3030
$this->connectionObject->setID('test');
3131

32-
$this->assertEquals('test', $this->connectionObject->getID());
32+
$this->assertSame('test', $this->connectionObject->getID());
3333
});
3434
}
3535

3636
public function testConnectionSetID(): void
3737
{
3838
$this->execute(function (): void {
3939
$this->setUpConnection();
40-
$this->assertEquals(null, $this->connectionObject->getID());
40+
$this->assertSame('', $this->connectionObject->getID());
4141

4242
$this->assertInstanceOf(Connection::class, $this->connectionObject->setID('test'));
4343

44-
$this->assertEquals('test', $this->connectionObject->getID());
44+
$this->assertSame('test', $this->connectionObject->getID());
4545
});
4646
}
4747

4848
public function testConnectionGetResource(): void
4949
{
5050
$this->execute(function (): void {
5151
$this->setUpConnection();
52-
$this->assertEquals('x', $this->connectionObject->getResource());
52+
$this->assertSame('x', $this->connectionObject->getResource());
5353
});
5454
}
5555

5656
public function testConnectionSetResource(): void
5757
{
5858
$this->execute(function (): void {
5959
$this->setUpConnection();
60-
$this->assertEquals('x', $this->connectionObject->getResource());
60+
$this->assertSame('x', $this->connectionObject->getResource());
6161

6262
$this->assertInstanceOf(Connection::class, $this->connectionObject->setResource('y'));
6363

64-
$this->assertEquals('y', $this->connectionObject->getResource());
64+
$this->assertSame('y', $this->connectionObject->getResource());
6565
});
6666
}
6767

@@ -92,7 +92,7 @@ public function testConnectionGetPool(): void
9292
}
9393

9494
$this->assertInstanceOf(Pool::class, $pool);
95-
$this->assertEquals('test', $pool->getName());
95+
$this->assertSame('test', $pool->getName());
9696
});
9797
}
9898

@@ -101,23 +101,23 @@ public function testConnectionReclaim(): void
101101
$this->execute(function (): void {
102102
$pool = new Pool($this->getAdapter(), 'test', 2, fn () => 'x');
103103

104-
$this->assertEquals(2, $pool->count());
104+
$this->assertSame(2, $pool->count());
105105

106106
$connection1 = $pool->pop();
107107

108-
$this->assertEquals(1, $pool->count());
108+
$this->assertSame(1, $pool->count());
109109

110110
$connection2 = $pool->pop();
111111

112-
$this->assertEquals(0, $pool->count());
112+
$this->assertSame(0, $pool->count());
113113

114114
$this->assertInstanceOf(Pool::class, $connection1->reclaim());
115115

116-
$this->assertEquals(1, $pool->count());
116+
$this->assertSame(1, $pool->count());
117117

118118
$this->assertInstanceOf(Pool::class, $connection2->reclaim());
119119

120-
$this->assertEquals(2, $pool->count());
120+
$this->assertSame(2, $pool->count());
121121
});
122122
}
123123

@@ -139,28 +139,28 @@ public function testConnectionDestroy(): void
139139
return $i <= 2 ? 'x' : 'y';
140140
});
141141

142-
$this->assertEquals(2, $object->count());
142+
$this->assertSame(2, $object->count());
143143

144144
$connection1 = $object->pop();
145145
$connection2 = $object->pop();
146146

147-
$this->assertEquals(0, $object->count());
147+
$this->assertSame(0, $object->count());
148148

149-
$this->assertEquals('x', $connection1->getResource());
150-
$this->assertEquals('x', $connection2->getResource());
149+
$this->assertSame('x', $connection1->getResource());
150+
$this->assertSame('x', $connection2->getResource());
151151

152152
$connection1->destroy();
153153
$connection2->destroy();
154154

155-
$this->assertEquals(2, $object->count());
155+
$this->assertSame(2, $object->count());
156156

157157
$connection1 = $object->pop();
158158
$connection2 = $object->pop();
159159

160-
$this->assertEquals(0, $object->count());
160+
$this->assertSame(0, $object->count());
161161

162-
$this->assertEquals('y', $connection1->getResource());
163-
$this->assertEquals('y', $connection2->getResource());
162+
$this->assertSame('y', $connection1->getResource());
163+
$this->assertSame('y', $connection2->getResource());
164164
});
165165
}
166166
}

tests/Pools/Scopes/GroupTestScope.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ public function testGroupReset(): void
6464
$this->setUpGroup();
6565
$this->groupObject->add(new Pool($this->getAdapter(), 'test', 5, fn () => 'x'));
6666

67-
$this->assertEquals(5, $this->groupObject->get('test')->count());
67+
$this->assertSame(5, $this->groupObject->get('test')->count());
6868

6969
$this->groupObject->get('test')->pop();
7070
$this->groupObject->get('test')->pop();
7171
$this->groupObject->get('test')->pop();
7272

73-
$this->assertEquals(2, $this->groupObject->get('test')->count());
73+
$this->assertSame(2, $this->groupObject->get('test')->count());
7474

7575
$this->groupObject->reclaim();
7676

77-
$this->assertEquals(5, $this->groupObject->get('test')->count());
77+
$this->assertSame(5, $this->groupObject->get('test')->count());
7878
});
7979
}
8080

@@ -84,11 +84,11 @@ public function testGroupReconnectAttempts(): void
8484
$this->setUpGroup();
8585
$this->groupObject->add(new Pool($this->getAdapter(), 'test', 5, fn () => 'x'));
8686

87-
$this->assertEquals(3, $this->groupObject->get('test')->getReconnectAttempts());
87+
$this->assertSame(3, $this->groupObject->get('test')->getReconnectAttempts());
8888

8989
$this->groupObject->setReconnectAttempts(5);
9090

91-
$this->assertEquals(5, $this->groupObject->get('test')->getReconnectAttempts());
91+
$this->assertSame(5, $this->groupObject->get('test')->getReconnectAttempts());
9292
});
9393
}
9494

@@ -98,11 +98,11 @@ public function testGroupReconnectSleep(): void
9898
$this->setUpGroup();
9999
$this->groupObject->add(new Pool($this->getAdapter(), 'test', 5, fn () => 'x'));
100100

101-
$this->assertEquals(1, $this->groupObject->get('test')->getReconnectSleep());
101+
$this->assertSame(1, $this->groupObject->get('test')->getReconnectSleep());
102102

103103
$this->groupObject->setReconnectSleep(2);
104104

105-
$this->assertEquals(2, $this->groupObject->get('test')->getReconnectSleep());
105+
$this->assertSame(2, $this->groupObject->get('test')->getReconnectSleep());
106106
});
107107
}
108108

@@ -118,23 +118,23 @@ public function testGroupUse(): void
118118
$this->groupObject->add($pool2);
119119
$this->groupObject->add($pool3);
120120

121-
$this->assertEquals(1, $pool1->count());
122-
$this->assertEquals(1, $pool2->count());
123-
$this->assertEquals(1, $pool3->count());
121+
$this->assertSame(1, $pool1->count());
122+
$this->assertSame(1, $pool2->count());
123+
$this->assertSame(1, $pool3->count());
124124

125125
// @phpstan-ignore argument.type
126126
$this->groupObject->use(['pool1', 'pool3'], function ($one, $three) use ($pool1, $pool2, $pool3): void {
127-
$this->assertEquals('1', $one);
128-
$this->assertEquals('3', $three);
127+
$this->assertSame('1', $one);
128+
$this->assertSame('3', $three);
129129

130-
$this->assertEquals(0, $pool1->count());
131-
$this->assertEquals(1, $pool2->count());
132-
$this->assertEquals(0, $pool3->count());
130+
$this->assertSame(0, $pool1->count());
131+
$this->assertSame(1, $pool2->count());
132+
$this->assertSame(0, $pool3->count());
133133
});
134134

135-
$this->assertEquals(1, $pool1->count());
136-
$this->assertEquals(1, $pool2->count());
137-
$this->assertEquals(1, $pool3->count());
135+
$this->assertSame(1, $pool1->count());
136+
$this->assertSame(1, $pool2->count());
137+
$this->assertSame(1, $pool3->count());
138138
});
139139
}
140140
}

0 commit comments

Comments
 (0)