Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}
Expand Down Expand Up @@ -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 <number>[s|m|h]');
}
$this->target = [
'url' => $url,
'idle_timeout' => $idleTimeout,
];

$this->target['idle_timeout'] = $idleTimeout;
return $this;
}

Expand Down
11 changes: 2 additions & 9 deletions src/VoltTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,15 @@ 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
*/
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 <number>[s|m|h]');
}
$this->config->setTarget($url, $idleTimeout);
$this->config->setTarget($idleTimeout);

return $this;
}
Expand Down
26 changes: 13 additions & 13 deletions tests/Units/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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,
];

Expand All @@ -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'],
];
}

Expand All @@ -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
Expand All @@ -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);

Expand All @@ -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']);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Units/VoltTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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')
Expand Down
Loading