Skip to content

Commit 2ceb18f

Browse files
github-actionsgithub-actions[bot]
authored andcommitted
style(php-cs-fixer): fix coding standards
1 parent cdc11cb commit 2ceb18f

File tree

6 files changed

+183
-189
lines changed

6 files changed

+183
-189
lines changed

tests/Unit/Session/ArraySessionHandlerTest.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Mcp\Server\Tests\Unit\Session;
66

77
use Mcp\Server\Session\ArraySessionHandler;
8-
use Mockery;
98
use PHPUnit\Framework\TestCase;
109
use Psr\Clock\ClockInterface;
1110

@@ -14,17 +13,6 @@ final class ArraySessionHandlerTest extends TestCase
1413
private ClockInterface $clock;
1514
private ArraySessionHandler $handler;
1615

17-
protected function setUp(): void
18-
{
19-
$this->clock = Mockery::mock(ClockInterface::class);
20-
$this->handler = new ArraySessionHandler(ttl: 3600, clock: $this->clock);
21-
}
22-
23-
protected function tearDown(): void
24-
{
25-
Mockery::close();
26-
}
27-
2816
public function test_read_returns_false_when_session_not_exists(): void
2917
{
3018
$result = $this->handler->read('non-existent-id');
@@ -178,4 +166,15 @@ public function test_constructor_with_custom_ttl(): void
178166

179167
$this->assertEquals(7200, $handler->ttl);
180168
}
169+
170+
protected function setUp(): void
171+
{
172+
$this->clock = \Mockery::mock(ClockInterface::class);
173+
$this->handler = new ArraySessionHandler(ttl: 3600, clock: $this->clock);
174+
}
175+
176+
protected function tearDown(): void
177+
{
178+
\Mockery::close();
179+
}
181180
}

tests/Unit/Session/CacheSessionHandlerTest.php

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Mcp\Server\Tests\Unit\Session;
66

77
use Mcp\Server\Session\CacheSessionHandler;
8-
use Mockery;
98
use PHPUnit\Framework\TestCase;
109
use Psr\Clock\ClockInterface;
1110
use Psr\SimpleCache\CacheInterface;
@@ -16,25 +15,6 @@ final class CacheSessionHandlerTest extends TestCase
1615
private ClockInterface $clock;
1716
private CacheSessionHandler $handler;
1817

19-
protected function setUp(): void
20-
{
21-
$this->cache = Mockery::mock(CacheInterface::class);
22-
$this->clock = Mockery::mock(ClockInterface::class);
23-
24-
// Mock the initial session index retrieval in constructor
25-
$this->cache->shouldReceive('get')
26-
->with('mcp_session_index', [])
27-
->andReturn([])
28-
->once();
29-
30-
$this->handler = new CacheSessionHandler($this->cache, ttl: 3600, clock: $this->clock);
31-
}
32-
33-
protected function tearDown(): void
34-
{
35-
Mockery::close();
36-
}
37-
3818
public function test_read_returns_false_when_session_not_exists(): void
3919
{
4020
$this->cache->shouldReceive('get')->with('non-existent-id', false)->andReturn(false);
@@ -47,7 +27,7 @@ public function test_read_returns_false_when_session_not_exists(): void
4727
public function test_read_removes_expired_session_from_index(): void
4828
{
4929
$sessionId = 'expired-session';
50-
30+
5131
// Session exists in cache but not in index
5232
$this->cache->shouldReceive('get')->with($sessionId, false)->andReturn(false);
5333
$this->cache->shouldReceive('set')->with('mcp_session_index', [])->andReturn(true);
@@ -209,7 +189,7 @@ public function test_gc_returns_empty_array_when_no_expired_sessions(): void
209189

210190
public function test_constructor_with_default_ttl(): void
211191
{
212-
$cache = Mockery::mock(CacheInterface::class);
192+
$cache = \Mockery::mock(CacheInterface::class);
213193
$cache->shouldReceive('get')->with('mcp_session_index', [])->andReturn([]);
214194

215195
$handler = new CacheSessionHandler($cache);
@@ -219,7 +199,7 @@ public function test_constructor_with_default_ttl(): void
219199

220200
public function test_constructor_with_custom_ttl(): void
221201
{
222-
$cache = Mockery::mock(CacheInterface::class);
202+
$cache = \Mockery::mock(CacheInterface::class);
223203
$cache->shouldReceive('get')->with('mcp_session_index', [])->andReturn([]);
224204

225205
$handler = new CacheSessionHandler($cache, ttl: 7200);
@@ -248,7 +228,7 @@ public function test_multiple_operations_maintain_index_consistency(): void
248228
$this->cache->shouldReceive('set')
249229
->with('mcp_session_index', [
250230
$sessionId1 => $currentTime->getTimestamp(),
251-
$sessionId2 => $currentTime->getTimestamp()
231+
$sessionId2 => $currentTime->getTimestamp(),
252232
])
253233
->andReturn(true);
254234
$this->cache->shouldReceive('set')->with($sessionId2, $sessionData2)->andReturn(true);
@@ -263,4 +243,23 @@ public function test_multiple_operations_maintain_index_consistency(): void
263243

264244
$this->assertTrue($result);
265245
}
246+
247+
protected function setUp(): void
248+
{
249+
$this->cache = \Mockery::mock(CacheInterface::class);
250+
$this->clock = \Mockery::mock(ClockInterface::class);
251+
252+
// Mock the initial session index retrieval in constructor
253+
$this->cache->shouldReceive('get')
254+
->with('mcp_session_index', [])
255+
->andReturn([])
256+
->once();
257+
258+
$this->handler = new CacheSessionHandler($this->cache, ttl: 3600, clock: $this->clock);
259+
}
260+
261+
protected function tearDown(): void
262+
{
263+
\Mockery::close();
264+
}
266265
}

tests/Unit/Session/SessionIdGeneratorTest.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@
66

77
use Mcp\Server\Session\SessionIdGenerator;
88
use PHPUnit\Framework\TestCase;
9-
use Random\RandomException;
109

1110
final class SessionIdGeneratorTest extends TestCase
1211
{
1312
private SessionIdGenerator $generator;
1413

15-
protected function setUp(): void
16-
{
17-
$this->generator = new SessionIdGenerator();
18-
}
19-
2014
public function test_generate_returns_string(): void
2115
{
2216
$sessionId = $this->generator->generate();
@@ -28,7 +22,7 @@ public function test_generate_returns_32_character_hex_string(): void
2822
{
2923
$sessionId = $this->generator->generate();
3024

31-
$this->assertEquals(32, strlen($sessionId));
25+
$this->assertEquals(32, \strlen($sessionId));
3226
$this->assertMatchesRegularExpression('/^[a-f0-9]{32}$/', $sessionId);
3327
}
3428

@@ -53,8 +47,8 @@ public function test_generate_uses_cryptographically_secure_randomness(): void
5347
$this->assertNotEquals($id1, $id2);
5448

5549
// Check that the IDs have good entropy (not all the same character)
56-
$this->assertNotEquals(str_repeat($id1[0], 32), $id1);
57-
$this->assertNotEquals(str_repeat($id2[0], 32), $id2);
50+
$this->assertNotEquals(\str_repeat($id1[0], 32), $id1);
51+
$this->assertNotEquals(\str_repeat($id2[0], 32), $id2);
5852
}
5953

6054
public function test_multiple_generators_produce_unique_ids(): void
@@ -83,18 +77,18 @@ public function test_generated_id_represents_16_bytes(): void
8377
$sessionId = $this->generator->generate();
8478

8579
// Convert hex string back to binary to verify it represents 16 bytes
86-
$binaryData = hex2bin($sessionId);
87-
$this->assertEquals(16, strlen($binaryData));
80+
$binaryData = \hex2bin($sessionId);
81+
$this->assertEquals(16, \strlen($binaryData));
8882
}
8983

9084
public function test_generated_ids_have_good_distribution(): void
9185
{
92-
$charCounts = array_fill_keys(str_split('0123456789abcdef'), 0);
86+
$charCounts = \array_fill_keys(\str_split('0123456789abcdef'), 0);
9387

9488
// Generate many IDs and count character frequency
9589
for ($i = 0; $i < 100; $i++) {
9690
$sessionId = $this->generator->generate();
97-
foreach (str_split($sessionId) as $char) {
91+
foreach (\str_split($sessionId) as $char) {
9892
$charCounts[$char]++;
9993
}
10094
}
@@ -105,11 +99,16 @@ public function test_generated_ids_have_good_distribution(): void
10599
}
106100

107101
// Check that no character dominates (rough distribution check)
108-
$totalChars = array_sum($charCounts);
102+
$totalChars = \array_sum($charCounts);
109103
$expectedAverage = $totalChars / 16; // 16 hex characters
110104

111105
foreach ($charCounts as $char => $count) {
112106
$this->assertLessThan($expectedAverage * 3, $count, "Character '{$char}' appears too frequently");
113107
}
114108
}
109+
110+
protected function setUp(): void
111+
{
112+
$this->generator = new SessionIdGenerator();
113+
}
115114
}

0 commit comments

Comments
 (0)