diff --git a/src/Factory.php b/src/Factory.php index 9ff091c..20af3c3 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -4,9 +4,6 @@ namespace Pest\Stressless; -use Pest\TestSuite; -use PHPUnit\Framework\TestCase; - /** * @internal * @@ -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. */ @@ -102,6 +94,10 @@ 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, @@ -109,9 +105,7 @@ public function run(): Result $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, @@ -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(); - } } diff --git a/src/Printers/Detail.php b/src/Printers/Detail.php index 9055fd4..257ee77 100644 --- a/src/Printers/Detail.php +++ b/src/Printers/Detail.php @@ -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); @@ -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); @@ -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);