Skip to content

Commit

Permalink
Methods for total sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
A5hleyRich committed Apr 6, 2024
1 parent abdb320 commit 430b0cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Har.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ public function smallestUncompressedRequest(): Request
})->first();
}

public function totalSize(): int
{
return $this->requests()->sum(function (Request $request) {
return $request->size();
});
}

public function totalUncompressedSize(): int
{
return $this->requests()->sum(function (Request $request) {
return $request->uncompressedSize();
});
}

public function onContentLoadTiming(int $precision = 2): ?float
{
return empty($this->har['log']['pages'][0]['pageTimings']['onContentLoad'])
Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/HarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
->and($this->har->smallestUncompressedRequest()->uncompressedSize())->toEqual(0);
});

test('total size', function () {
expect($this->har->totalSize())->toEqual(1600544);
});

test('total uncompressed size', function () {
expect($this->har->totalUncompressedSize())->toEqual(4896355);
});

test('get onContentLoad timing', function () {
expect($this->har->onContentLoadTiming())->toEqual(580.40)
->and($this->har->onContentLoadTiming(0))->toEqual(580)
Expand Down

0 comments on commit 430b0cb

Please sign in to comment.