Skip to content

Commit f70f057

Browse files
committed
refactor: Type hint test execution methods to return TestResult objects.
1 parent 6a793bc commit f70f057

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/Facades/VoltTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @method static \VoltTest\VoltTest getVoltTest()
1313
* @method static \VoltTest\Laravel\VoltTestManager addTestFromClass(string|VoltTestCase $className)
1414
* @method static Collection getScenarios() :
15-
* @method static mixed run(bool $streamOutput = false)
15+
* @method static \VoltTest\TestResult run(bool $streamOutput = false)
1616
*
1717
* @see \VoltTest\Laravel\VoltTestManager
1818
*/

src/Testing/Listener/VoltTestListener.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PHPUnit\Event\Test\Finished;
88
use PHPUnit\Event\Test\FinishedSubscriber;
9+
use VoltTest\TestResult;
910

1011
class VoltTestListener implements FinishedSubscriber
1112
{
@@ -22,12 +23,8 @@ public function notify(Finished $event): void
2223
/**
2324
* Print the performance result to the console.
2425
*/
25-
protected function printResult(string $testName, mixed $result): void
26+
protected function printResult(string $testName, TestResult $result): void
2627
{
27-
// Check if result has the expected methods (duck typing)
28-
if (! method_exists($result, 'getTotalRequests')) {
29-
return;
30-
}
3128

3229
$output = "\n\n";
3330
$output .= "----------------------------------------------------------------------\n";
@@ -53,6 +50,7 @@ protected function shortenTestName(string $testName): string
5350
if (preg_match('/::(\w+)/', $testName, $matches)) {
5451
return $matches[1];
5552
}
53+
5654
return $testName;
5755
}
5856
}

src/Testing/PerformanceTestCase.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use VoltTest\Laravel\Contracts\VoltTestCase as VoltTestCaseInterface;
99
use VoltTest\Laravel\Facades\VoltTest;
1010
use VoltTest\Laravel\Testing\Assertions\VoltTestAssertions;
11+
use VoltTest\TestResult;
1112

1213
/**
1314
* Base test case for VoltTest performance testing with PHPUnit.
@@ -278,7 +279,7 @@ public function createApplication()
278279
protected function runVoltTest(
279280
VoltTestCaseInterface $testClass,
280281
array $options = []
281-
): mixed {
282+
): TestResult {
282283
try {
283284
// Apply default options
284285
$options = array_merge([
@@ -331,7 +332,7 @@ protected function applyVoltTestOptions(array $options): void
331332
/**
332333
* Quick helper to run a simple URL load test.
333334
*/
334-
protected function loadTestUrl(string $url, array $options = []): mixed
335+
protected function loadTestUrl(string $url, array $options = []): TestResult
335336
{
336337
$testClass = new class ($url) implements VoltTestCaseInterface {
337338
public function __construct(private string $url)
@@ -358,7 +359,7 @@ protected function loadTestApi(
358359
string $method = 'GET',
359360
array $data = [],
360361
array $options = []
361-
): mixed {
362+
): TestResult {
362363
$testClass = new class ($endpoint, $method, $data) implements VoltTestCaseInterface {
363364
public function __construct(
364365
private string $endpoint,

src/VoltTestManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Support\Collection;
99
use VoltTest\Laravel\Contracts\VoltTestCase;
1010
use VoltTest\Laravel\Scenarios\LaravelScenario;
11+
use VoltTest\TestResult;
1112
use VoltTest\VoltTest;
1213

1314
class VoltTestManager
@@ -101,9 +102,9 @@ public function scenario(string $name): LaravelScenario
101102
*
102103
* @param bool $streamOutput
103104
*
104-
* @return mixed
105+
* @return TestResult
105106
* */
106-
public function run(bool $streamOutput = false): mixed
107+
public function run(bool $streamOutput = false): TestResult
107108
{
108109
return $this->voltTest->run($streamOutput);
109110
}

0 commit comments

Comments
 (0)