Skip to content

Commit 27756fe

Browse files
authored
Merge pull request #2 from volt-test/Feat/Remove-url-from-target
Remove set url on target which is unused in engine
2 parents 5a08dff + 715f6d4 commit 27756fe

File tree

4 files changed

+20
-37
lines changed

4 files changed

+20
-37
lines changed

src/Configuration.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(string $name, string $description = '')
2828
$this->duration = '';
2929
$this->rampUp = '';
3030
$this->target = [
31-
'url' => '',
31+
'url' => 'https://example.com',
3232
'idle_timeout' => '30s',
3333
];
3434
}
@@ -82,22 +82,12 @@ public function setRampUp(string $rampUp): self
8282
return $this;
8383
}
8484

85-
public function setTarget(string $url, string $idleTimeout = '30s'): self
85+
public function setTarget(string $idleTimeout = '30s'): self
8686
{
87-
if (! preg_match('/^https?:\/\//', $url)) {
88-
throw new VoltTestException('URL should start with http:// or https://');
89-
}
90-
if (! filter_var($url, FILTER_VALIDATE_URL)) {
91-
throw new VoltTestException('Invalid URL');
92-
}
9387
if (! preg_match('/^\d+[smh]$/', $idleTimeout)) {
9488
throw new VoltTestException('Invalid idle timeout format. Use <number>[s|m|h]');
9589
}
96-
$this->target = [
97-
'url' => $url,
98-
'idle_timeout' => $idleTimeout,
99-
];
100-
90+
$this->target['idle_timeout'] = $idleTimeout;
10191
return $this;
10292
}
10393

src/VoltTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,15 @@ public function setHttpDebug(bool $httpDebug): self
7777

7878
/**
7979
* Set the target URL and idle timeout
80-
* @param string $url The target URL to test
8180
* @param string $idleTimeout Default is 30s (30 seconds) example: 1s (1 second), 1m (1 minute), 1h (1 hour)
8281
* @throws VoltTestException
8382
*/
84-
public function setTarget(string $url, string $idleTimeout = '30s'): self
83+
public function setTarget(string $idleTimeout): self
8584
{
86-
if (! preg_match('/^https?:\/\//', $url)) {
87-
throw new VoltTestException('URL should start with http:// or https://');
88-
}
89-
if (! filter_var($url, FILTER_VALIDATE_URL)) {
90-
throw new VoltTestException('Invalid URL');
91-
}
9285
if (! preg_match('/^\d+[smh]$/', $idleTimeout)) {
9386
throw new VoltTestException('Invalid idle timeout format. Use <number>[s|m|h]');
9487
}
95-
$this->config->setTarget($url, $idleTimeout);
88+
$this->config->setTarget($idleTimeout);
9689

9790
return $this;
9891
}

tests/Units/ConfigurationTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testConstructorAndDefaults(): void
2525
$this->assertEquals(1, $configArray['virtual_users']);
2626
$this->assertFalse($configArray['http_debug']);
2727
$this->assertEquals([
28-
'url' => '',
28+
'url' => 'https://example.com',
2929
'idle_timeout' => '30s',
3030
], $configArray['target']);
3131
}
@@ -153,13 +153,13 @@ public static function invalidRampUpProvider(): array
153153
}
154154

155155
#[DataProvider('validTargetProvider')]
156-
public function testSetValidTarget(string $url, string $timeout): void
156+
public function testSetValidTarget(string $timeout): void
157157
{
158-
$this->config->setTarget($url, $timeout);
158+
$this->config->setTarget($timeout);
159159

160160
$configArray = $this->config->toArray();
161161
$expectedTarget = [
162-
'url' => $url,
162+
'url' => 'https://example.com',
163163
'idle_timeout' => $timeout,
164164
];
165165

@@ -169,12 +169,12 @@ public function testSetValidTarget(string $url, string $timeout): void
169169
public static function validTargetProvider(): array
170170
{
171171
return [
172-
['http://example.com', '30s'],
173-
['https://example.com', '1s'],
174-
['http://localhost:8080', '1m'],
175-
['https://api.example.com/v1', '60s'],
176-
['http://example.com', '1m'],
177-
['https://example.com', '2h'],
172+
['30s'],
173+
['1s'],
174+
['1m'],
175+
['60s'],
176+
['1m'],
177+
['2h'],
178178
];
179179
}
180180

@@ -201,7 +201,7 @@ public static function invalidTargetUrlProvider(): array
201201
public function testSetInvalidTargetTimeout(string $timeout): void
202202
{
203203
$this->expectException(VoltTestException::class);
204-
$this->config->setTarget('http://example.com', $timeout);
204+
$this->config->setTarget($timeout);
205205
}
206206

207207
public static function invalidTargetTimeoutProvider(): array
@@ -224,7 +224,7 @@ public function testFluentInterface(): void
224224
->setVirtualUsers(10)
225225
->setDuration('5m')
226226
->setRampUp('30s')
227-
->setTarget('http://example.com', '1m');
227+
->setTarget('1m');
228228

229229
$this->assertInstanceOf(Configuration::class, $result);
230230

@@ -233,7 +233,7 @@ public function testFluentInterface(): void
233233
$this->assertEquals('5m', $configArray['duration']);
234234
$this->assertEquals('30s', $configArray['ramp_up']);
235235
$this->assertEquals([
236-
'url' => 'http://example.com',
236+
'url' => 'https://example.com',
237237
'idle_timeout' => '1m',
238238
], $configArray['target']);
239239
}

tests/Units/VoltTestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testBasicConfiguration(): void
3030
->setVirtualUsers(10)
3131
->setDuration('1m')
3232
->setRampUp('10s')
33-
->setTarget('http://example.com');
33+
->setTarget('30s');
3434

3535
$this->assertInstanceOf(VoltTest::class, $result);
3636
}
@@ -91,7 +91,7 @@ public function testScenarioExecution(): void
9191
$this->voltTest
9292
->setVirtualUsers(1)
9393
->setDuration('1s')
94-
->setTarget('http://example.com');
94+
->setTarget('40s');
9595

9696
// Add a scenario
9797
$this->voltTest->scenario('Simple Test')

0 commit comments

Comments
 (0)