diff --git a/README.md b/README.md index 16de321..f28b8db 100644 --- a/README.md +++ b/README.md @@ -25,93 +25,6 @@ Accurate timing and metrics collection For detailed documentation, visit [https://php.volt-test.com](https://php.volt-test.com) -## Quick Start - -### Installation - -```bash -git clone git@github.com:volt-test/php-sdk.git -cd php-sdk -composer install -``` - -### Basic Usage -```bash -touch test.php -``` -```php -// test.php -setVirtualUsers(1) // number of VUs (Virtual Users) -// ->setDuration('1s') // to run the test for 1 second - ->setHttpDebug(true); // to enable http debug mode remove it if you don't want to see the http debug - -// Create login scenario -$loginScenario = $test->scenario('User Login') - ->autoHandleCookies(); // this will save cookies with all requests in this scenario - - -$loginScenario->step('Register') - ->get('http://localhost:8001/register') - ->extractFromRegex('csrf_token_register', 'name="_token" value="(.+?)"') // Extract the csrf token to submit a form - ->header('Accept', 'text/html'); - -$loginScenario->step('Submit Register') - ->post( - 'http://localhost:8001/register', - '_token=${csrf_token_register}&name=Test-v&email=${email}&password=${password}&password_confirmation=${password}') // send data with extracted data and source file - ->header('Content-Type', 'application/x-www-form-urlencoded') - ->validateStatus('status validator from php',302); - - -// Add first step - Get login page -$loginScenario->step('get_login_page') - ->get('http://localhost:8001/login') - ->header('Accept', 'text/html') - ->extractFromRegex('csrf_token', 'name="_token" value="(.+?)"') - ->validateStatus('status validator from php',200); - -// Add second step - Submit login -$loginScenario->step('submit_login') - ->post( - 'http://localhost:8001/login', - '_token=${csrf_token}&email=${email}&password=${password}') - ->header('Content-Type', 'application/x-www-form-urlencoded') -->validateStatus('status validator from php',302); - - -// Add third step - Visit dashboard -$loginScenario->step('visit_dashboard') - ->get('http://localhost:8001/dashboard') - ->header('Accept', 'text/html') - ->validateStatus('status_code', 200); -// Run the test -// This will start the test and block until it completes -// pass true to run() to run the test with progress and real time results -$result = $test->run(true); -// OR $test->run(true); to run the test with progress and real time results - -// Access test results -echo "Success Rate: " . $result->getSuccessRate() . "%\n"; -echo "Average Response Time: " . $result->getAvgResponseTime() . "\n"; -``` - -```bash -php test.php -``` - ## Features - Cross-platform support (Windows, Linux, MacOS) diff --git a/src/Request.php b/src/Request.php index 7635442..816fafd 100644 --- a/src/Request.php +++ b/src/Request.php @@ -101,12 +101,15 @@ public function addHeader(string $name, string $value): self * */ public function toArray(): array { - return [ + $array = [ 'method' => $this->method, 'url' => $this->url, - 'header' => $this->headers, 'body' => $this->body, ]; + if (count($this->headers) > 0) { + $array['header'] = $this->headers; + } + return $array; } /**