From f771101d4f96921062154210c2fadb87ba907a55 Mon Sep 17 00:00:00 2001 From: elwafa Date: Sun, 19 Jan 2025 21:03:35 +0200 Subject: [PATCH 1/3] Remove set url on target which is unused in engine --- src/Configuration.php | 16 +++------------- src/VoltTest.php | 10 ++-------- tests/Units/ConfigurationTest.php | 24 ++++++++++++------------ tests/Units/VoltTestTest.php | 4 ++-- 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/src/Configuration.php b/src/Configuration.php index 698ad58..cd1681c 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -28,7 +28,7 @@ public function __construct(string $name, string $description = '') $this->duration = ''; $this->rampUp = ''; $this->target = [ - 'url' => '', + 'url' => 'https://example.com', 'idle_timeout' => '30s', ]; } @@ -82,22 +82,12 @@ public function setRampUp(string $rampUp): self return $this; } - public function setTarget(string $url, string $idleTimeout = '30s'): self + public function setTarget(string $idleTimeout = '30s'): self { - if (! preg_match('/^https?:\/\//', $url)) { - throw new VoltTestException('URL should start with http:// or https://'); - } - if (! filter_var($url, FILTER_VALIDATE_URL)) { - throw new VoltTestException('Invalid URL'); - } if (! preg_match('/^\d+[smh]$/', $idleTimeout)) { throw new VoltTestException('Invalid idle timeout format. Use [s|m|h]'); } - $this->target = [ - 'url' => $url, - 'idle_timeout' => $idleTimeout, - ]; - + $this->target['idle_timeout'] = $idleTimeout; return $this; } diff --git a/src/VoltTest.php b/src/VoltTest.php index f3fbf7a..c2b04f7 100644 --- a/src/VoltTest.php +++ b/src/VoltTest.php @@ -81,18 +81,12 @@ public function setHttpDebug(bool $httpDebug): self * @param string $idleTimeout Default is 30s (30 seconds) example: 1s (1 second), 1m (1 minute), 1h (1 hour) * @throws VoltTestException */ - public function setTarget(string $url, string $idleTimeout = '30s'): self + public function setTarget(string $idleTimeout): self { - if (! preg_match('/^https?:\/\//', $url)) { - throw new VoltTestException('URL should start with http:// or https://'); - } - if (! filter_var($url, FILTER_VALIDATE_URL)) { - throw new VoltTestException('Invalid URL'); - } if (! preg_match('/^\d+[smh]$/', $idleTimeout)) { throw new VoltTestException('Invalid idle timeout format. Use [s|m|h]'); } - $this->config->setTarget($url, $idleTimeout); + $this->config->setTarget($idleTimeout); return $this; } diff --git a/tests/Units/ConfigurationTest.php b/tests/Units/ConfigurationTest.php index 8fedceb..7ca9549 100644 --- a/tests/Units/ConfigurationTest.php +++ b/tests/Units/ConfigurationTest.php @@ -25,7 +25,7 @@ public function testConstructorAndDefaults(): void $this->assertEquals(1, $configArray['virtual_users']); $this->assertFalse($configArray['http_debug']); $this->assertEquals([ - 'url' => '', + 'url' => 'https://example.com', 'idle_timeout' => '30s', ], $configArray['target']); } @@ -153,13 +153,13 @@ public static function invalidRampUpProvider(): array } #[DataProvider('validTargetProvider')] - public function testSetValidTarget(string $url, string $timeout): void + public function testSetValidTarget(string $timeout): void { - $this->config->setTarget($url, $timeout); + $this->config->setTarget($timeout); $configArray = $this->config->toArray(); $expectedTarget = [ - 'url' => $url, + 'url' => 'https://example.com', 'idle_timeout' => $timeout, ]; @@ -169,12 +169,12 @@ public function testSetValidTarget(string $url, string $timeout): void public static function validTargetProvider(): array { return [ - ['http://example.com', '30s'], - ['https://example.com', '1s'], - ['http://localhost:8080', '1m'], - ['https://api.example.com/v1', '60s'], - ['http://example.com', '1m'], - ['https://example.com', '2h'], + ['30s'], + ['1s'], + ['1m'], + ['60s'], + ['1m'], + ['2h'], ]; } @@ -224,7 +224,7 @@ public function testFluentInterface(): void ->setVirtualUsers(10) ->setDuration('5m') ->setRampUp('30s') - ->setTarget('http://example.com', '1m'); + ->setTarget('1m'); $this->assertInstanceOf(Configuration::class, $result); @@ -233,7 +233,7 @@ public function testFluentInterface(): void $this->assertEquals('5m', $configArray['duration']); $this->assertEquals('30s', $configArray['ramp_up']); $this->assertEquals([ - 'url' => 'http://example.com', + 'url' => 'https://example.com', 'idle_timeout' => '1m', ], $configArray['target']); } diff --git a/tests/Units/VoltTestTest.php b/tests/Units/VoltTestTest.php index cab9c18..1fefb73 100644 --- a/tests/Units/VoltTestTest.php +++ b/tests/Units/VoltTestTest.php @@ -30,7 +30,7 @@ public function testBasicConfiguration(): void ->setVirtualUsers(10) ->setDuration('1m') ->setRampUp('10s') - ->setTarget('http://example.com'); + ->setTarget('30s'); $this->assertInstanceOf(VoltTest::class, $result); } @@ -91,7 +91,7 @@ public function testScenarioExecution(): void $this->voltTest ->setVirtualUsers(1) ->setDuration('1s') - ->setTarget('http://example.com'); + ->setTarget('40s'); // Add a scenario $this->voltTest->scenario('Simple Test') From 289a597dbe259813ff62c4dba32692ccdfa2c914 Mon Sep 17 00:00:00 2001 From: elwafa Date: Sun, 19 Jan 2025 21:06:43 +0200 Subject: [PATCH 2/3] CI --- src/VoltTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/VoltTest.php b/src/VoltTest.php index c2b04f7..51e0711 100644 --- a/src/VoltTest.php +++ b/src/VoltTest.php @@ -77,7 +77,6 @@ public function setHttpDebug(bool $httpDebug): self /** * Set the target URL and idle timeout - * @param string $url The target URL to test * @param string $idleTimeout Default is 30s (30 seconds) example: 1s (1 second), 1m (1 minute), 1h (1 hour) * @throws VoltTestException */ From 715f6d442386ef41e3da584aa29a3db73e745ea1 Mon Sep 17 00:00:00 2001 From: elwafa Date: Sun, 19 Jan 2025 21:15:11 +0200 Subject: [PATCH 3/3] Removeing unused paramater --- tests/Units/ConfigurationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Units/ConfigurationTest.php b/tests/Units/ConfigurationTest.php index 7ca9549..9d9723b 100644 --- a/tests/Units/ConfigurationTest.php +++ b/tests/Units/ConfigurationTest.php @@ -201,7 +201,7 @@ public static function invalidTargetUrlProvider(): array public function testSetInvalidTargetTimeout(string $timeout): void { $this->expectException(VoltTestException::class); - $this->config->setTarget('http://example.com', $timeout); + $this->config->setTarget($timeout); } public static function invalidTargetTimeoutProvider(): array