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
87 changes: 0 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]:volt-test/php-sdk.git
cd php-sdk
composer install
```

### Basic Usage
```bash
touch test.php
```
```php
// test.php
<?php
require 'vendor/autoload.php';

use VoltTest\DataSourceConfiguration;
use VoltTest\VoltTest;

// Create a new test
$test = new VoltTest(
'User Login Flow',
'Tests user authentication process'
);
// Configure test parameters
$test
->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)
Expand Down
7 changes: 5 additions & 2 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Loading