Skip to content

Commit a7cc6dc

Browse files
test: add edge case tests for LessThan mutations (#158)
Add tests for boundary conditions identified in mutation testing: 1. HarFileRepository: - Test filtering of files with exactly 4 characters - Verify files < 4 chars are filtered out - Verify .har files >= 4 chars are included 2. Timings: - Test setConnect allows connect equal to SSL time - Test setConnect throws exception when connect < SSL - Test setSend/setWait/setReceive allow zero values - Test setSend/setWait/setReceive reject negative values These tests kill the LessThan mutations identified in the report by: - Testing the boundary value where < becomes <= - Ensuring edge cases are properly handled Co-authored-by: Claude <noreply@anthropic.com>
1 parent c9680a7 commit a7cc6dc

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

tests/src/Unit/Repository/HarFileRepositoryTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,45 @@ public function testLoadJsonHandlesEmptyFile(): void
105105
throw $e;
106106
}
107107
}
108+
109+
public function testGetIdsFiltersFilesWithLessThanFourCharacters(): void
110+
{
111+
$tempDir = sys_get_temp_dir().'/har_test_'.uniqid();
112+
mkdir($tempDir);
113+
114+
// Create files with various lengths
115+
$files = [
116+
'a' => '', // 1 character - should be filtered
117+
'ab' => '', // 2 characters - should be filtered
118+
'abc' => '', // 3 characters - should be filtered
119+
'test' => '', // 4 characters but no .har extension - should be filtered
120+
'a.bc' => '', // 4 characters but no .har extension - should be filtered
121+
'a.har' => '{}', // 5 characters with .har extension - should be included
122+
'ab.har' => '{}', // 6 characters with .har extension - should be included
123+
];
124+
125+
foreach ($files as $filename => $content) {
126+
file_put_contents($tempDir.'/'.$filename, $content);
127+
}
128+
129+
$repository = new HarFileRepository($tempDir);
130+
$ids = $repository->getIds();
131+
132+
// Only files with .har extension and length >= 4 should be included
133+
$this->assertContains('a.har', $ids);
134+
$this->assertContains('ab.har', $ids);
135+
136+
// All other files should be filtered out
137+
$this->assertNotContains('a', $ids);
138+
$this->assertNotContains('ab', $ids);
139+
$this->assertNotContains('abc', $ids);
140+
$this->assertNotContains('test', $ids);
141+
$this->assertNotContains('a.bc', $ids);
142+
143+
// Clean up
144+
foreach (array_keys($files) as $filename) {
145+
unlink($tempDir.'/'.$filename);
146+
}
147+
rmdir($tempDir);
148+
}
108149
}

tests/src/Unit/TimingsTest.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,94 @@ public function testHasSsl(): void
9999
$this->assertTrue($timings->hasSsl());
100100
$this->assertEquals(25.7, $timings->getSsl());
101101
}
102+
103+
public function testSetConnectAllowsConnectEqualToSSL(): void
104+
{
105+
$timings = new Timings();
106+
$timings->setSsl(100.0);
107+
108+
// Connect time equal to SSL time should be allowed
109+
// The check is (connect < ssl), so connect >= ssl is valid
110+
$timings->setConnect(100.0);
111+
$this->assertEquals(100.0, $timings->getConnect());
112+
}
113+
114+
public function testSetConnectThrowsExceptionWhenConnectLessThanSSL(): void
115+
{
116+
$timings = new Timings();
117+
$timings->setSsl(100.0);
118+
119+
$this->expectException(\LogicException::class);
120+
$this->expectExceptionMessage('Connect time must include SSL time');
121+
122+
// Connect time less than SSL time should throw exception
123+
$timings->setConnect(50.0);
124+
}
125+
126+
public function testSetConnectAllowsConnectGreaterThanSSL(): void
127+
{
128+
$timings = new Timings();
129+
$timings->setSsl(100.0);
130+
131+
// Connect time greater than SSL time should be allowed
132+
$timings->setConnect(150.0);
133+
$this->assertEquals(150.0, $timings->getConnect());
134+
}
135+
136+
public function testSetSendAllowsZero(): void
137+
{
138+
$timings = new Timings();
139+
140+
// Send time of 0 should be allowed (not negative)
141+
$timings->setSend(0.0);
142+
$this->assertEquals(0.0, $timings->getSend());
143+
}
144+
145+
public function testSetSendThrowsExceptionForNegativeValues(): void
146+
{
147+
$timings = new Timings();
148+
149+
$this->expectException(\LogicException::class);
150+
$this->expectExceptionMessage('Send must not be negative');
151+
152+
$timings->setSend(-1.0);
153+
}
154+
155+
public function testSetWaitAllowsZero(): void
156+
{
157+
$timings = new Timings();
158+
159+
// Wait time of 0 should be allowed (not negative)
160+
$timings->setWait(0.0);
161+
$this->assertEquals(0.0, $timings->getWait());
162+
}
163+
164+
public function testSetWaitThrowsExceptionForNegativeValues(): void
165+
{
166+
$timings = new Timings();
167+
168+
$this->expectException(\LogicException::class);
169+
$this->expectExceptionMessage('Wait must not be negative');
170+
171+
$timings->setWait(-1.0);
172+
}
173+
174+
public function testSetReceiveAllowsZero(): void
175+
{
176+
$timings = new Timings();
177+
178+
// Receive time of 0 should be allowed (not negative)
179+
$timings->setReceive(0.0);
180+
$this->assertEquals(0.0, $timings->getReceive());
181+
}
182+
183+
public function testSetReceiveThrowsExceptionForNegativeValues(): void
184+
{
185+
$timings = new Timings();
186+
187+
$this->expectException(\LogicException::class);
188+
$this->expectExceptionMessage('Receive must not be negative');
189+
190+
$timings->setReceive(-1.0);
191+
}
102192
}

0 commit comments

Comments
 (0)