Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 1 addition & 73 deletions tests/src/Unit/HarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,61 +43,20 @@ public static function fixtureDataProvider(): \Generator
}
}

public function testGetSetLog(): void
{
$log = new Log();
$har = (new Har())->setLog($log);
$this->assertSame($log, $har->getLog());
}

public function testSplitLogEntries(): void
{
$repository = $this->getHarFileRepository();
$har = $repository->load('www.softwareishard.com-multiple-entries.har');

$originalEntryCount = \count($har->getLog()->getEntries());
$this->assertGreaterThan(1, $originalEntryCount);

$splitHars = [];
foreach ($har->splitLogEntries() as $index => $splitHar) {
$splitHars[$index] = $splitHar;
}

$this->assertCount($originalEntryCount, $splitHars);

// Verify each split HAR has only one entry
// Verify it's a different instance (cloned)
foreach ($splitHars as $splitHar) {
$this->assertCount(1, $splitHar->getLog()->getEntries());
// Verify it's a different instance (cloned)
$this->assertNotSame($har, $splitHar);
}

// Verify indices are yielded correctly (0, 1, 2, ...)
$expectedIndices = range(0, $originalEntryCount - 1);
$actualIndices = array_keys($splitHars);
$this->assertEquals($expectedIndices, $actualIndices);
}

public function testCloneIsDeep(): void
{
$repository = $this->getHarFileRepository();
$har = $repository->load('www.softwareishard.com-multiple-entries.har');

$originalEntryCount = \count($har->getLog()->getEntries());
$this->assertGreaterThan(1, $originalEntryCount);

// Clone the HAR
$cloned = clone $har;

// Verify the clone has a different Log instance
$this->assertNotSame($har->getLog(), $cloned->getLog());

// Modify the cloned HAR's entries
$cloned->getLog()->setEntries([]);

// Verify the original HAR's entries are unchanged
$this->assertCount($originalEntryCount, $har->getLog()->getEntries());
$this->assertCount(0, $cloned->getLog()->getEntries());
}

public function testCloneBrowserIsDeep(): void
Expand All @@ -115,42 +74,11 @@ public function testCloneBrowserIsDeep(): void
// Clone the HAR
$cloned = clone $har;

// Verify the Browser object is a different instance
$this->assertNotSame($har->getLog()->getBrowser(), $cloned->getLog()->getBrowser());

// Modify the cloned HAR's browser version
$cloned->getLog()->getBrowser()->setVersion('modified-version');

// Verify the original HAR's browser version is unchanged
$this->assertSame($originalBrowserVersion, $har->getLog()->getBrowser()->getVersion());
$this->assertSame('modified-version', $cloned->getLog()->getBrowser()->getVersion());
}

public function testSplitLogEntriesYieldsWithCorrectIndices(): void
{
// This test kills the YieldValue mutant by explicitly verifying
// that yield uses the index as the key: yield $index => $cloned
$repository = $this->getHarFileRepository();
$har = $repository->load('www.softwareishard.com-multiple-entries.har');

$generator = $har->splitLogEntries();

// Explicitly verify that each yielded value has the correct key
$count = 0;
foreach ($generator as $key => $splitHar) {
// The key MUST equal the count (0, 1, 2, ...)
$this->assertSame($count, $key, "Generator key should be {$count} but got {$key}");
$this->assertInstanceOf(Har::class, $splitHar);
++$count;
}

// Verify we iterated over all entries
$this->assertGreaterThan(1, $count);

// This test specifically kills the YieldValue mutant:
// If yield $index => $cloned is changed to yield $cloned,
// the keys would be auto-generated (0, 1, 2, ...) which would still pass
// BUT the explicit assertion on $key === $count ensures the index is yielded
}

/**
Expand Down