Skip to content

Commit

Permalink
chore: removes __destruct behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Nov 6, 2023
1 parent d129563 commit e238c00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 34 deletions.
36 changes: 5 additions & 31 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace Pest\Stressless;

use Pest\TestSuite;
use PHPUnit\Framework\TestCase;

/**
* @internal
*
Expand All @@ -29,11 +26,6 @@ final class Factory
*/
private int $duration = 5;

/**
* Weather or not the factory is running.
*/
private bool $running = false;

/**
* The computed result, if any.
*/
Expand Down Expand Up @@ -102,16 +94,18 @@ public function for(int $duration): DurationOptions
*/
public function run(): Result
{
if ($this->result instanceof Result) {
return $this->result;
}

$this->options['stages'] = [[
'duration' => sprintf('%ds', $this->duration),
'target' => $this->concurrency,
]];

$this->options['throw'] = true;

$this->running = true;

return $this->result ??= ((new Run(
return $this->result = ((new Run(
new Url($this->url),
$this->options,
$this->verbose,
Expand Down Expand Up @@ -171,24 +165,4 @@ public function __get(string $name): mixed
{
return $this->{$name}(); // @phpstan-ignore-line
}

/**
* Destructs the run factory.
*/
public function __destruct()
{
if ($this->result instanceof Result) {
return;
}

if (TestSuite::getInstance()->test instanceof TestCase) {
return;
}

if ($this->running) {
return;
}

$this->dd();
}
}
6 changes: 3 additions & 3 deletions src/Printers/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function print(Result $result): void

$color = $this->color($result->requests->upload->duration->avg, 50.0, 150.0, 250.0);
$value = $result->requests->upload->duration->avg;
$percentage = $value * 100.0 / $total;
$percentage = $total === 0.0 ? 0.0 : ($value * 100.0 / $total);
$percentage = sprintf('%4.1f', $percentage);
$value = $this->ms($value);

Expand All @@ -83,7 +83,7 @@ public function print(Result $result): void

$color = $this->color($result->requests->ttfb->duration->avg, 50.0, 150.0, 400.0);
$value = $result->requests->ttfb->duration->avg;
$percentage = $value * 100.0 / $total;
$percentage = $total === 0.0 ? 0.0 : ($value * 100.0 / $total);
$percentage = sprintf('%4.1f', $percentage);
$value = $this->ms($value);

Expand All @@ -94,7 +94,7 @@ public function print(Result $result): void

$color = $this->color($result->requests->download->duration->avg, 100.0, 300.0, 1000.0);
$value = $result->requests->download->duration->avg;
$percentage = $value * 100.0 / $total;
$percentage = $total === 0.0 ? 0.0 : ($value * 100.0 / $total);
$percentage = sprintf('%4.1f', $percentage);
$value = $this->ms($value);

Expand Down

0 comments on commit e238c00

Please sign in to comment.