### Complete Configuration Example Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/VoltTest.md An example demonstrating a full test configuration with multiple parameters set. ```php $test = new VoltTest('Complete Test Configuration', 'Full configuration Example') ->setVirtualUsers(100) ->setDuration('5m') ->setRampUp('10s') ->setHttpDebug(true); ``` -------------------------------- ### Install Dependencies Source: https://github.com/volt-test/php-sdk-docs/blob/main/README.md Run this command to install project dependencies. ```bash yarn ``` -------------------------------- ### HTTP Methods Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Step.md Examples of configuring different HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS) for scenario steps. ```APIDOC ## HTTP Methods ### GET Request #### Endpoint https://api.example.com/users ### Description Configures a GET request to retrieve users. ### Method GET ### Parameters #### Headers - **Accept** (string) - Optional - Specifies the desired response format, e.g., 'application/json'. ### Request Example ```php $scenario->get('https://api.example.com/users') ->header('Accept', 'application/json'); ``` ### POST Request (JSON Body) #### Endpoint https://api.example.com/users ### Description Configures a POST request to create a user with a JSON body. ### Method POST ### Parameters #### Request Body - **(string)** - Required - JSON payload containing user data. #### Headers - **Content-Type** (string) - Required - Must be 'application/json'. ### Request Example ```php $scenario->post('https://api.example.com/users', '{"name": "John"}') ->header('Content-Type', 'application/json'); ``` ### POST Request (Form Data) #### Endpoint https://api.example.com/users ### Description Configures a POST request to create a user using form-urlencoded data. ### Method POST ### Parameters #### Request Body - **(string)** - Required - Form data string, e.g., 'email=${email}&password=${password}'. #### Headers - **Content-Type** (string) - Required - Must be 'application/x-www-form-urlencoded'. ### Request Example ```php $scenario->post('https://api.example.com/users', 'email=${email}&password=${password}') ->header('Content-Type', 'application/x-www-form-urlencoded'); ``` ### PUT Request #### Endpoint https://api.example.com/users/{id} ### Description Configures a PUT request to update a specific user. ### Method PUT ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the user to update. #### Request Body - **(string)** - Required - JSON payload with updated user data. ### Request Example ```php $scenario->put('https://api.example.com/users/1', '{"name": "Updated"}'); ``` ### PATCH Request #### Endpoint https://api.example.com/users/{id} ### Description Configures a PATCH request to partially update a specific user. ### Method PATCH ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the user to update. #### Request Body - **(string)** - Required - JSON payload with fields to update. ### Request Example ```php $scenario->patch('https://api.example.com/users/1', '{"status": "active"}'); ``` ### DELETE Request #### Endpoint https://api.example.com/users/{id} ### Description Configures a DELETE request to remove a specific user. ### Method DELETE ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the user to delete. ### Request Example ```php $scenario->delete('https://api.example.com/users/1'); ``` ### HEAD Request #### Endpoint https://api.example.com/status ### Description Configures a HEAD request to retrieve only the headers of the status endpoint. ### Method HEAD ### Request Example ```php $scenario->head('https://api.example.com/status'); ``` ### OPTIONS Request #### Endpoint https://api.example.com/users ### Description Configures an OPTIONS request to determine the communication options for the users endpoint. ### Method OPTIONS ### Request Example ```php $scenario->options('https://api.example.com/users'); ``` ``` -------------------------------- ### Start Local Development Server Source: https://github.com/volt-test/php-sdk-docs/blob/main/README.md Starts a local development server for live preview. Changes are reflected without restarting. ```bash yarn start ``` -------------------------------- ### Install Laravel Performance Testing Package Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-08-09-effortless-laravel-performace-testing-with-volt-test-php-sdk/index.mdx Install the package using Composer. After installation, publish the configuration file to customize settings. ```bash composer require volt-test/laravel-performance-testing ``` ```bash php artisan vendor:publish --tag=volttest-config ``` -------------------------------- ### Configuration Validation Examples Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/VoltTest.md Examples demonstrating invalid configurations that will throw VoltTestException. Includes invalid user counts and duration/target formats. ```php $test->setVirtualUsers(0); ``` ```php $test->setDuration('invalid'); ``` ```php $test->setTarget('not-valid'); ``` -------------------------------- ### Install PHP in WSL Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/installation.md Install PHP and required extensions within the Windows Subsystem for Linux environment. ```bash sudo apt update sudo apt install php-cli php-curl php-json ``` -------------------------------- ### Install SDK using Composer Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/installation.md Use this command to add the Volt-Test SDK as a dependency to your PHP project via Composer. ```bash composer require volt-test/php-sdk ``` -------------------------------- ### Complete Test Result Summary Example Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Result.md A comprehensive example demonstrating how to print various test summary and response time metrics using printf for formatted output. This snippet assumes a test has already been executed and its result stored in the $result variable. ```php $result = $test->run(); printf("Test Summary:\n"); printf("Duration: %s\n", $result->getDuration()); printf("Total Requests: %d\n", $result->getTotalRequests()); printf("Success Rate: %.2f%%\n", $result->getSuccessRate()); printf("Requests/sec: %.2f\n", $result->getRequestsPerSecond()); printf("Success Requests: %d\n", $result->getSuccessRequests()); printf("Failed Requests: %d\n", $result->getFailedRequests()); printf("\nResponse Times:\n"); printf("Min: %s\n", $result->getMinResponseTime()); printf("Max: %s\n", $result->getMaxResponseTime()); printf("Avg: %s\n", $result->getAvgResponseTime()); printf("Median: %s\n", $result->getMedianResponseTime()); printf("P95: %s\n", $result->getP95ResponseTime()); printf("P99: %s\n", $result->getP99ResponseTime()); ``` -------------------------------- ### Initialize VoltTest Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/VoltTest.md Start a new test by initializing the VoltTest class with a name and an optional description. ```php scenario('Basic Scenario'); // Add a step to the scenario $scenario->step('Register') ->get('https://google.com') ->header('Content-Type', 'text/html'); // Run the test $result = $voltTest->run(true); // Echo the result echo $result->getRawOutput(); ``` -------------------------------- ### Complete Multi-Step Scenario Example Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Step.md Demonstrates a scenario with two steps: fetching a form, extracting a CSRF token, validating the status, and then submitting the form using the extracted token. Includes setting think time. ```php $scenario->step('Get Form') ->get('https://example.com/form') ->header('Content-Type', 'application/x-www-form-urlencoded') ->extractFromRegex('csrf', 'name="_token" value="(.+?)"') ->validateStatus('success', 200) ->setThinkTime('1s'); $scenario->step('Process Result') ->post('https://example.com/form', 'name=John') ->header('X-CSRF-TOKEN', '${csrf}') ->validateStatus('success', 200); ``` -------------------------------- ### TestResult Class - Complete Example Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Result.md A full code example demonstrating how to run a test and print all available metrics in a formatted manner. ```APIDOC ## TestResult Class - Complete Example ### Description This section provides a complete, runnable example that illustrates the typical workflow of executing a test and then systematically retrieving and displaying all performance metrics and response time statistics. ### Method ```php $result = $test->run(); printf("Test Summary:\n"); printf("Duration: %s\n", $result->getDuration()); printf("Total Requests: %d\n", $result->getTotalRequests()); printf("Success Rate: %.2f%%\n", $result->getSuccessRate()); printf("Requests/sec: %.2f\n", $result->getRequestsPerSecond()); printf("Success Requests: %d\n", $result->getSuccessRequests()); printf("Failed Requests: %d\n", $result->getFailedRequests()); printf("\nResponse Times:\n"); printf("Min: %s\n", $result->getMinResponseTime()); printf("Max: %s\n", $result->getMaxResponseTime()); printf("Avg: %s\n", $result->getAvgResponseTime()); printf("Median: %s\n", $result->getMedianResponseTime()); printf("P95: %s\n", $result->getP95ResponseTime()); printf("P99: %s\n", $result->getP99ResponseTime()); ``` ### Response Example ```plaintext Test Summary: Duration: 24.000873057s Total Requests: 5000 Success Rate: 82.96% Requests/sec: 208.33 Success Requests: 4148 Failed Requests: 852 Response Times: Min: 7.388011ms Max: 18.179649581s Avg: 3.848391356s Median: 8.997304894s P95: 16.74641748s P99: 17.552319263s ``` ``` -------------------------------- ### Clone SDK Repository Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/installation.md Clone the Volt-Test SDK repository from GitHub to install it manually. ```bash git clone git@github.com:volt-test/php-sdk.git ``` ```bash cd php-sdk ``` ```bash composer install ``` -------------------------------- ### CRUD Operations Test Example Source: https://context7.com/volt-test/php-sdk-docs/llms.txt Illustrates performing Create, Read, Update, and Delete operations against an API. It shows how to pass variables, such as a user ID, between steps. ```php setVirtualUsers(100); $test->setDuration('1m'); $scenario = $test->scenario('CRUD Operations'); // Create $scenario->step('Create User') ->post('https://api.example.com/users', json_encode([ 'name' => 'John Doe', 'email' => 'john@example.com', 'role' => 'user', ])) ->header('Content-Type', 'application/json') ->validateStatus('creation_success', 201) ->extractFromJson('user_id', 'data.id'); // Read $scenario->step('Get User') ->get('https://api.example.com/users/${user_id}') ->validateStatus('read_success', 200); // Update $scenario->step('Update User') ->put('https://api.example.com/users/${user_id}', json_encode([ 'name' => 'Jane Doe', 'email' => 'jane@example.com', ])) ->header('Content-Type', 'application/json') ->validateStatus('update_success', 200); // Delete $scenario->step('Delete User') ->delete('https://api.example.com/users/${user_id}') ->validateStatus('delete_success', 204); $result = $test->run(); echo $result->getRawOutput(); ``` -------------------------------- ### Configure Gradual User Ramp-Up Source: https://context7.com/volt-test/php-sdk-docs/llms.txt Specify a ramp-up delay to gradually introduce virtual users over time, rather than starting them all at once. Users are distributed evenly across the specified duration. ```php setVirtualUsers(100); $test->setRampUp('10s'); // Gradually start 100 users over 10 seconds (100ms delay per user) ``` -------------------------------- ### Run Test and Get Basic Metrics Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Result.md Execute a test and retrieve fundamental performance metrics like success rate and total requests. ```php $result = $test->run(); // Get key metrics echo "Success Rate: " . $result->getSuccessRate() . "%\n"; echo "Total Requests: " . $result->getTotalRequests() . "\n"; ``` -------------------------------- ### Perform a GET Request Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Step.md Executes a GET request to retrieve data from a URL and sets an 'Accept' header for the response. ```php $scenario->get('https://api.example.com/users') ->header('Accept', 'application/json'); ``` -------------------------------- ### Run Volt-Test using Docker (Alpine) Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/installation.md Execute Volt-Test scripts using a Docker container based on Alpine Linux, installing necessary PHP extensions. ```bash docker run --rm -v $(pwd):/app -w /app php:8-alpine sh -c "apk add php-cli php-curl php-json && php your-script.php" ``` -------------------------------- ### Clone VoltTest PHP SDK Repository Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-02-28-stress-testing-laravel-with-volt-test-web-ui/index.mdx Alternatively, clone the VoltTest PHP SDK repository and install dependencies. This method is useful for development or if direct Composer installation is not preferred. ```bash git clone https://github.com/volt-test/php-sdk.git cd php-sdk composer install ``` -------------------------------- ### Install Volt-test Laravel Package Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-11-29-laravel-load-testing-with-phpunit/index.mdx Use Composer to update or install the Volt-test package for Laravel performance testing. ```bash composer update ``` ```bash composer require volt-test/laravel-performance-testing ``` -------------------------------- ### Example PHPUnit Output with Volt-Test Report Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-11-29-laravel-load-testing-with-phpunit/index.mdx This is an example of the output you can expect when running performance tests. It shows interleaved Volt-Test metrics alongside standard PHPUnit assertions. ```text $ vendor/bin/phpunit --testsuite Performance PHPUnit 11.5.44 by Sebastian Bergmann and contributors. Runtime: PHP 8.4.15 Configuration: /path/to/app/phpunit.xml Performance Report: testHomePageUnderLoad Total Requests: 50 Success Rate: 100.00% Requests/Sec (RPS): 346.19 Avg Latency: 74.2426ms ---------------------------------------------------------------------- 1 / 1 (100%) Time: 00:01.524, Memory: 30.00 MB ``` -------------------------------- ### Define Test Step: Visit Home Page Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-02-28-stress-testing-laravel-with-volt-test-web-ui/index.mdx Defines a step to visit the home page using an HTTP GET request. Includes setting the Accept header, validating the response status code, and setting a think time. ```php $userFlowScenario->step('Visit Home Page') ->get('http://localhost:8000') ->header('Accept', 'text/html') ->validateStatus('home_page_loaded', 200) ->setThinkTime('2s'); ``` -------------------------------- ### API Authentication Test Example Source: https://context7.com/volt-test/php-sdk-docs/llms.txt Demonstrates an API authentication flow where an access token is extracted from a login response and then used in subsequent authenticated requests. ```php setVirtualUsers(10); $test->setDuration('1m'); $scenario = $test->scenario('API Authentication'); // Login Request - extract access token $scenario->step('Login') ->post('https://api.example.com/auth/login', json_encode([ 'email' => 'user@example.com', 'password' => 'secret' ])) ->header('Content-Type', 'application/json') ->validateStatus('login_success', 200) ->extractFromJson('access_token', 'data.token'); // Use token in authenticated requests $scenario->step('Get Profile') ->get('https://api.example.com/profile') ->header('Authorization', 'Bearer ${access_token}') ->validateStatus('profile_success', 200); $result = $test->run(); echo $result->getRawOutput(); ``` -------------------------------- ### Set Ramp-Up Delay Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/VoltTest.md Define the time over which virtual users are gradually introduced. If not set, all users start immediately. This helps simulate real-world traffic. ```php $test->setRampUp('10s'); ``` -------------------------------- ### setRampUp() - Configure Gradual User Ramp-Up Source: https://context7.com/volt-test/php-sdk-docs/llms.txt The ramp-up delay determines how virtual users are introduced over time instead of starting all at once. Users are distributed evenly over the specified time. ```APIDOC ## setRampUp() ### Description The ramp-up delay determines how virtual users are introduced over time instead of starting all at once. Users are distributed evenly over the specified time. ### Method `setRampUp(string $rampUp)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php setVirtualUsers(100); $test->setRampUp('10s'); // Gradually start 100 users over 10 seconds (100ms delay per user) ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Define Test Step: Visit Dashboard Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-02-28-stress-testing-laravel-with-volt-test-web-ui/index.mdx Defines a step to visit the dashboard page via an HTTP GET request. This step validates that the dashboard loads successfully (HTTP 200) and includes a think time. ```php $userFlowScenario->step('Visit Dashboard') ->get('http://localhost:8000/dashboard') ->header('Accept', 'text/html') ->validateStatus('dashboard_loaded', 200) ->setThinkTime('3s'); ``` -------------------------------- ### Perform HTTP Requests with Various Methods Source: https://context7.com/volt-test/php-sdk-docs/llms.txt VoltTest supports all standard HTTP methods including GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS for API and web testing. ```php scenario('CRUD Operations'); // GET Request $scenario->step('Get Users') ->get('https://api.example.com/users') ->header('Accept', 'application/json'); // POST Request with JSON body $scenario->step('Create User') ->post('https://api.example.com/users', '{"name": "John", "email": "john@example.com"}') ->header('Content-Type', 'application/json'); // POST Request with form data $scenario->step('Form Submit') ->post('https://api.example.com/users', 'email=${email}&password=${password}') ->header('Content-Type', 'application/x-www-form-urlencoded'); // PUT Request $scenario->step('Update User') ->put('https://api.example.com/users/1', '{"name": "Updated Name"}'); // PATCH Request $scenario->step('Patch User') ->patch('https://api.example.com/users/1', '{"status": "active"}'); // DELETE Request $scenario->step('Delete User') ->delete('https://api.example.com/users/1'); // HEAD Request $scenario->step('Check Status') ->head('https://api.example.com/status'); // OPTIONS Request $scenario->step('Get Options') ->options('https://api.example.com/users'); ``` -------------------------------- ### PHPUnit Performance Test Example Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-11-29-laravel-load-testing-with-phpunit/index.mdx This PHPUnit test class extends PerformanceTestCase and defines a test method to run a Volt-Test class with specified virtual users. It includes assertions to validate performance metrics. This approach allows leveraging existing Volt-Test classes within a PHPUnit suite. ```php executeTest( RegistrationTest::class, 10 ); // Assertions to validate performance metrics. $this->assertResponseOk(); $this->assertRps(100); $this->assertLatency(500); $this->assertP95(1000); $this->assertP99(1500); } } ``` -------------------------------- ### Test CRUD Operations on a JSON API Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Examples/json_api_examples.md Test a JSON API that supports CRUD (Create, Read, Update, Delete) operations for managing users. This example demonstrates making POST, GET, PUT, and DELETE requests sequentially, using extracted IDs to reference resources. ```php $test = new VoltTest('CRUD Operations Test'); $test->setVirtualUsers(100); $test->setDuration('1m'); $scenario = $test->scenario('CRUD Operations'); // Create $scenario->step('Create User') ->post('https://api.example.com/users', json_encode([ 'name' => 'John Doe', 'email' => 'some@mail.com', 'role' => 'user', ])) ->header('Content-Type', 'application/json') ->validateStatus('creation_success', 201) ->extractFromJson('user_id', 'data.id'); // Read $scenario->step('Get User') ->get('https://api.example.com/users/${user_id}') ->validateStatus('read_success', 200); // Update $scenario->step('Update User') ->put('https://api.example.com/users/${user_id}', json_encode([ 'name' => 'Jane Doe', 'email' => 'update@mail.com', ])) ->header('Content-Type', 'application/json') ->validateStatus('update_success', 200); // Delete $scenario->step('Delete User') ->delete('https://api.example.com/users/${user_id}') ->validateStatus('delete_success', 204); // Run the test and get the result $result = $test->run(); echo $result->getRawOutput(); ``` -------------------------------- ### Configure Data Source from CSV Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-02-28-stress-testing-laravel-with-volt-test-web-ui/index.mdx Sets up a data source for the scenario, loading unique user data from a specified CSV file. Ensure the CSV file exists and is correctly formatted for unique user simulation. ```php $userFlowScenario->setDataSourceConfiguration( new DataSourceConfiguration(__Dir__ . '/users.csv', 'unique', true) ); ``` -------------------------------- ### Deploy Website (SSH) Source: https://github.com/volt-test/php-sdk-docs/blob/main/README.md Deploys the website using SSH. Assumes SSH is configured for deployment. ```bash USE_SSH=true yarn deploy ``` -------------------------------- ### Create a Scenario in VoltTest Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Scenarios.md Instantiate VoltTest and create a new scenario with a name and optional description. ```php use VoltTest\VoltTest; $test = new VoltTest('API Test'); $scenario = $test->scenario( 'Login Flow', // Scenario name 'User authentication' // Optional description ); ``` -------------------------------- ### Creating a Step with POST Request Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Step.md Demonstrates how to create a new step in a scenario and define it as a POST request to a specified URL. ```APIDOC ## POST /api/example.com/login ### Description Creates a new step named 'Login' and configures it as a POST request to the login endpoint. ### Method POST ### Endpoint https://api.example.com/login ### Parameters #### Request Body - **(string)** - Required - JSON payload for login. ### Request Example ```php use VoltTest\VoltTest; $test = new VoltTest('API Test'); $scenario = $test->scenario('Login Flow'); $scenario->step('Login') ->post('https://api.example.com/login', '{"name": "John"}'); ``` ### Response #### Success Response (200) - **(object)** - Details of the response from the login endpoint. #### Response Example ```json { "message": "Login successful", "token": "your_auth_token" } ``` ``` -------------------------------- ### Run Quick Performance Test via Artisan Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-08-09-effortless-laravel-performace-testing-with-volt-test-php-sdk/index.mdx Execute a quick performance test directly from the command line, specifying the URL, HTTP method, and request body. ```bash php artisan volttest:run https://example.com/api/login --users=100 --method=POST --body='{"email":"test@example.com","password":"secret"}' ``` -------------------------------- ### Use Extracted Data in Subsequent Request Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Step.md Demonstrates using an extracted 'token' variable in the 'Authorization' header of a subsequent GET request. ```php $scenario->get('https://api.example.com/profile') ->header('Authorization', 'Bearer ${token}'); ``` -------------------------------- ### Create a VoltTest Instance Source: https://context7.com/volt-test/php-sdk-docs/llms.txt Initialize the VoltTest class with a test name and an optional description. This is the main entry point for creating performance tests. ```php post('https://api.example.com/users', '{"name": "John"}') ->header('Authorization', 'Bearer token') ->header('Accept', 'application/json') ->header('X-Custom-Header', 'value'); ``` ``` -------------------------------- ### run() - Execute the Test Source: https://context7.com/volt-test/php-sdk-docs/llms.txt Execute the configured test and return results. Pass `true` for real-time progress tracking and HTTP debugging output. ```APIDOC ## run() - Execute the Test ### Description Execute the configured test and return results. Pass `true` for real-time progress tracking and HTTP debugging output. ### Method POST (Implicitly used within a scenario step) ### Endpoint N/A (This is a method call on the VoltTest object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php // Run without progress tracking $result = $test->run(); // Run with real-time progress and debugging output $result = $test->run(true); ``` ### Response #### Success Response (200) None (This method returns the test results, not a standard HTTP response) #### Response Example None ``` -------------------------------- ### Create HTTP Request Steps Source: https://context7.com/volt-test/php-sdk-docs/llms.txt Define individual HTTP requests within a scenario. Each step requires a name and HTTP method configuration. ```php scenario('User Flow'); $scenario->step('Login') // Step name is required ->post('https://api.example.com/login'); ``` -------------------------------- ### PHP HTML Form Test with CSRF Extraction Source: https://context7.com/volt-test/php-sdk-docs/llms.txt Use this snippet to simulate user interactions with an HTML form, including extracting dynamic tokens like CSRF for security. Ensure the Volt-Test SDK is installed via Composer. ```php setVirtualUsers(50); $test->setDuration('30s'); $test->setRampUp('5s'); $scenario = $test->scenario('Login Form Test'); $scenario->autoHandleCookies(); // Get login page and extract CSRF token $scenario->step('Get Login Page') ->get('https://example.com/login') ->extractFromHtml('csrf_token', 'input[name="_token"]', 'value') ->validateStatus('page_load', 200) ->setThinkTime('1s'); // Submit login form with extracted CSRF token $scenario->step('Submit Login') ->post('https://example.com/login', '_token=${csrf_token}&email=user@example.com&password=secret') ->header('Content-Type', 'application/x-www-form-urlencoded') ->validateStatus('login_success', 302); $result = $test->run(true); // Enable real-time progress printf("Test Summary:\n"); printf("Duration: %s\n", $result->getDuration()); printf("Total Requests: %d\n", $result->getTotalRequests()); printf("Success Rate: %.2f%%\n", $result->getSuccessRate()); printf("Requests/sec: %.2f\n", $result->getRequestsPerSecond()); printf("\nResponse Times:\n"); printf("Min: %s\n", $result->getMinResponseTime()); printf("Max: %s\n", $result->getMaxResponseTime()); printf("Avg: %s\n", $result->getAvgResponseTime()); printf("P95: %s\n", $result->getP95ResponseTime()); printf("P99: %s\n", $result->getP99ResponseTime()); ``` -------------------------------- ### Basic API Performance Test with VoltTest Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-02-26-introducing-volt-test-php-load-testing/index.md This snippet demonstrates setting up a basic performance test for an API. It configures virtual users, duration, ramp-up time, and defines a two-step scenario involving authentication and data retrieval, including variable extraction and status validation. ```php setVirtualUsers(50) // Number of concurrent users ->setDuration('30s') // Test duration ->setRampUp('5s') // Gradually ramp up to full load ->setHttpDebug(false); // Disable HTTP debug output // Create a test scenario $apiScenario = $test->scenario('API Flow') ->setWeight(100); // Full weight (100%) to this scenario // Define the first step - Get auth token $apiScenario->step('Get Token') ->post('https://api.example.com/auth', '{"username":"test","password":"test123"}') ->header('Content-Type', 'application/json') ->extractFromJson('token', 'data.token') // Extract token from response ->validateStatus('success', 200); // Define the second step - Use the token $apiScenario->step('Get User Data') ->get('https://api.example.com/users/me') ->header('Authorization', 'Bearer ${token}') // Use extracted token ->validateStatus('success', 200); // Run the test $result = $test->run(true); // true enables real-time progress output // Display results echo "Success Rate: " . $result->getSuccessRate() . "%\n"; echo "Requests/sec: " . $result->getRequestsPerSecond() . "\n"; echo "Avg Response: " . $result->getAvgResponseTime() . "\n"; echo "P95 Response: " . $result->getP95ResponseTime() . "\n"; ``` -------------------------------- ### Run Volt-Test in WSL Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/installation.md Execute your Volt-Test scripts using the PHP CLI within WSL. ```bash php your-script.php ``` -------------------------------- ### Create a Test Scenario Source: https://context7.com/volt-test/php-sdk-docs/llms.txt Define a user flow or scenario for the performance test. Each scenario has a name and an optional description. ```php scenario( 'Login Flow', // Scenario name (required) 'User authentication' // Optional description ); ``` -------------------------------- ### Configure Data Source for Scenario Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Scenarios.md Set up data-driven testing for a scenario by providing a DataSourceConfiguration object. This specifies the data file path, iteration mode (sequential, random, unique), and whether the file includes a header row. ```php use VoltTest\DataSourceConfiguration; $dataConfig = new DataSourceConfiguration( __DIR__ . '/test-data.csv', // Full file path 'random', // Mode: sequential/random/unique true // Has header row ); $scenario->setDataSourceConfiguration($dataConfig); ``` -------------------------------- ### TestResult Class - Basic Usage Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Result.md Demonstrates how to instantiate and run a test, then retrieve key performance metrics. ```APIDOC ## TestResult Class - Basic Usage ### Description This section shows the basic steps to obtain test results and access fundamental metrics like success rate and total requests. ### Method ```php $result = $test->run(); // Get key metrics echo "Success Rate: " . $result->getSuccessRate() . "%\n"; echo "Total Requests: " . $result->getTotalRequests() . "\n"; ``` ### Response Example ```plaintext Success Rate: 82.96% Total Requests: 5000 ``` ``` -------------------------------- ### Run VoltTest Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/VoltTest.md Execute the configured test. Pass `true` to enable real-time progress tracking and HTTP debugging. ```php $result = $test->run(); ``` ```php $result = $test->run(true); ``` -------------------------------- ### Execute the Test Source: https://context7.com/volt-test/php-sdk-docs/llms.txt Execute the configured test and return results. Pass `true` for real-time progress tracking and HTTP debugging output. ```php scenario('Basic Flow'); $scenario->step('Request') ->get('https://api.example.com/status'); // Run without progress tracking $result = $test->run(); // Run with real-time progress and debugging output $result = $test->run(true); ?> ``` -------------------------------- ### Create a Step in a Scenario Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Step.md Initiates a new step within a scenario and defines it as a POST request to a specified URL. The step name is mandatory. ```php use VoltTest\VoltTest; $test = new VoltTest('API Test'); $scenario = $test->scenario('Login Flow'); $scenario->step('Login') // Step name is required ->post('https://api.example.com/login'); ``` -------------------------------- ### VoltTest Class - Creating a Test Instance Source: https://context7.com/volt-test/php-sdk-docs/llms.txt The VoltTest class is the main entry point for creating and configuring performance tests. Initialize it with a test name and optional description. ```APIDOC ## VoltTest Class - Creating a Test Instance ### Description The VoltTest class is the main entry point for creating and configuring performance tests. Initialize it with a test name and optional description. ### Method `__construct(string $testName, ?string $description = null)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php yarn deploy ``` -------------------------------- ### Initialize VoltTest Instance Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-02-28-stress-testing-laravel-with-volt-test-web-ui/index.mdx Creates a new VoltTest instance for a specific test flow. Use this to define the test's name and a brief description of the user flow being simulated. ```php $test = new VoltTest( 'Laravel User Flow', 'Tests home page visit, user registration, and dashboard access' ); ``` -------------------------------- ### Configure Data-Driven API Test Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Examples/json_api_examples.md Set up a data-driven API test using a CSV file for user registration data. Ensure the CSV file has appropriate headers and data for each field. ```php $test = new VoltTest('Data-Driven API Test'); $test->setVirtualUsers(50); // Configure data source $dataConfig = new DataSourceConfiguration( __DIR__ . '/test_users.csv', // CSV with test data 'random', // Random selection true // Has header row ); $scenario = $test->scenario('Registration Test') ->setDataSourceConfiguration($dataConfig); // Registration process using data from CSV $scenario->step('Submit Registration') ->post('https://api.example.com/register', json_encode([ 'name' => '${name}', 'email' => '${email}', 'phone' => '${phone}', ])) ->header('Content-Type', 'application/json') ->validateStatus('registration_success', 200); // Run the test and get the result $result = $test->run(); echo $result->getRawOutput(); ``` -------------------------------- ### Configure Data-Driven Form Testing in PHP Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Examples/html_form_examples.md Set up a data source configuration to use a CSV file for sequential data retrieval in form testing. Ensure the CSV file has a header row. ```php $test = new VoltTest('Data-Driven Form Test'); $test->setVirtualUsers(10); // Configure data source $dataConfig = new DataSourceConfiguration( __DIR__ .'/test_users.csv', // CSV with test data actual file path 'sequential', // Sequential selection true // Has header row ); $scenario = $test->scenario('Registration Test') ->setDataSourceConfiguration($dataConfig); // Registration process using data from CSV $scenario->step('Submit Registration') ->post('https://example.com/register','name=${name}&email=${email}&phone=${phone}') ->header('Content-Type', 'application/x-www-form-urlencoded') ->validateStatus('registration_success', 200); // Run the test and get the result $result = $test->run(); ``` -------------------------------- ### Create Test Data CSV Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-02-28-stress-testing-laravel-with-volt-test-web-ui/index.mdx Create a CSV file named 'users.csv' to store test user data, including email and password. This file will be used as a data source for realistic testing scenarios. ```csv email,password user1@example.com,password123 user2@example.com,password123 user3@example.com,password123 user4@example.com,password123 user5@example.com,password123 ``` -------------------------------- ### Run Volt-Test using Docker Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/installation.md Execute Volt-Test scripts within a Docker container, mounting the current directory as a volume. ```bash docker run --rm -v $(pwd):/app -w /app php:8-cli php your-script.php ``` -------------------------------- ### Run Performance Tests with PHPUnit Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-11-29-laravel-load-testing-with-phpunit/index.mdx Execute performance tests using the PHPUnit command-line interface. Ensure your PHPUnit configuration is set up to include performance test suites. ```bash ./vendor/bin/phpunit --testsuite=Performance ``` -------------------------------- ### Write a Laravel Load Test with Volt-Test Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-11-29-laravel-load-testing-with-phpunit/index.mdx Create a load test class extending `PerformanceTestCase` to test a URL under load and assert performance metrics. Server management is enabled via a static property. ```php loadTestUrl('/', [ 'virtual_users' => 50, ]); // Assert that the success rate is above 99% $this->assertVTSuccessful($result, 99); // Assert that the 95th percentile response time is below 150ms $this->assertVTP95ResponseTime($result, 150); } } ``` -------------------------------- ### Perform an OPTIONS Request Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Step.md Executes an OPTIONS request to determine the communication options for a resource at a specified URL. ```php $scenario->options('https://api.example.com/users'); ``` -------------------------------- ### Retrieve Basic Performance Metrics Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/Result.md Access core performance metrics including test duration, request counts, and throughput. Ensure a test has been run to obtain these values. ```php // Test duration $result->getDuration(); // Returns: "24.000873057s" // Request counts $result->getTotalRequests(); // Returns: 5000 $result->getSuccessRequests(); // Returns: 4148 $result->getFailedRequests(); // Returns: 852 // Performance metrics $result->getSuccessRate(); // Returns: 82.96 $result->getRequestsPerSecond(); // Returns: 208.33 ``` -------------------------------- ### scenario() - Create Test Scenarios Source: https://context7.com/volt-test/php-sdk-docs/llms.txt Scenarios represent user flows that will be executed during performance tests. Each scenario contains a sequence of steps and can be configured with specific behaviors. ```APIDOC ## scenario() ### Description Scenarios represent user flows that will be executed during performance tests. Each scenario contains a sequence of steps and can be configured with specific behaviors. ### Method `scenario(string $scenarioName, ?string $description = null): Scenario` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php scenario( 'Login Flow', // Scenario name (required) 'User authentication' // Optional description ); ``` ### Response #### Success Response (200) Returns a Scenario object. #### Response Example None ``` -------------------------------- ### Configure Test Parameters Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-02-28-stress-testing-laravel-with-volt-test-web-ui/index.mdx Sets key parameters for the stress test, including the number of virtual users, test duration, ramp-up time, and HTTP debug logging. Adjust these values to control the intensity and duration of the simulation. ```php $test ->setVirtualUsers(5) ->setDuration('60s') ->setRampUp('10s') ->setHttpDebug(true); ``` -------------------------------- ### Define a Performance Test Scenario Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-08-09-effortless-laravel-performace-testing-with-volt-test-php-sdk/index.mdx Implement the `VoltTestCase` interface to define test scenarios. Use `VoltTestManager` to configure scenarios, steps, and validations. ```php namespace App\VoltTests; use VoltTest\Laravel\Contracts\VoltTestCase; use VoltTest\Laravel\VoltTestManager; class ExampleTest implements VoltTestCase { public function define(VoltTestManager $manager): void { $manager->scenario('ExampleTest') ->step('Visit Home Page') ->get('https://example.com') ->validateStatus('success', 200); } } ``` -------------------------------- ### Run PHP Script from Terminal Source: https://github.com/volt-test/php-sdk-docs/blob/main/docs/getting-started.md Execute a PHP script containing Volt-Test code using the PHP command-line interpreter. ```bash php example.php ``` -------------------------------- ### Run All Performance Tests Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-11-29-laravel-load-testing-with-phpunit/index.mdx Execute all tests in the Performance testsuite, including your load tests. Ensure your tests are located in the `tests/Performance` directory. ```bash vendor/bin/phpunit --testsuite Performance ``` -------------------------------- ### Define Test Step: Submit Registration Form Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-02-28-stress-testing-laravel-with-volt-test-web-ui/index.mdx Defines a step to submit the registration form using an HTTP POST request. It includes the extracted CSRF token, user data from the data source, and validates the response status. Ensure the Content-Type header is correctly set for form data. ```php $userFlowScenario->step('Submit Registration') ->post( 'http://localhost:8000/register', '_token=${csrf_token}&name=Test User&email=${email}&password=${password}&password_confirmation=${password}' ) ->header('Content-Type', 'application/x-www-form-urlencoded') ->validateStatus('registration_successful', 302) ->setThinkTime('1s'); ``` -------------------------------- ### Configure Data-Driven Testing with CSV Source: https://context7.com/volt-test/php-sdk-docs/llms.txt Configure data-driven testing using CSV files. Supports random, sequential, and unique iteration modes. Ensure the CSV file has a header row if specified. ```php setVirtualUsers(50); $dataConfig = new DataSourceConfiguration( __DIR__ . '/test_users.csv', // Full path to CSV file 'random', // Mode: sequential/random/unique true // Has header row ); $scenario = $test->scenario('Registration Test') ->setDataSourceConfiguration($dataConfig); // Use CSV columns as variables in steps $scenario->step('Submit Registration') ->post('https://api.example.com/register', json_encode([ 'name' => '${name}', 'email' => '${email}', 'phone' => '${phone}', ])) ->header('Content-Type', 'application/json') ->validateStatus('registration_success', 200); $result = $test->run(); echo $result->getRawOutput(); ``` -------------------------------- ### Configure Concurrent Virtual Users Source: https://context7.com/volt-test/php-sdk-docs/llms.txt Set the number of concurrent virtual users to simulate. The default value is 1. ```php setVirtualUsers(100); // Simulate 100 concurrent users ``` -------------------------------- ### Set Volt-Test Environment Variables in System Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-11-29-laravel-load-testing-with-phpunit/index.mdx Alternatively, set Volt-Test environment variables directly in your system environment or in a `.env` or `.env.testing` file. ```bash VOLTTEST_BASE_PATH=. VOLTTEST_SERVER_PORT=8009 VOLTTEST_ENABLE_SERVER_MANAGEMENT=true VOLTTEST_DEBUG_FOR_SERVER_MANAGEMENT=true ``` -------------------------------- ### Data-Driven Testing with CSV Source: https://github.com/volt-test/php-sdk-docs/blob/main/blog/2025-08-09-effortless-laravel-performace-testing-with-volt-test-php-sdk/index.mdx Configure tests to use data from CSV files for realistic simulations. Use `${variable}` syntax to inject data into requests. ```csv name,email,password John Doe,user1@example.com,password123 Jane Smith,user2@example.com,password456 ``` ```php $manager->scenario('RegisterTest') ->dataSource('users.csv') ->step('Register User') ->post('/register', [ 'name' => '${name}', 'email' => '${email}', 'password' => '${password}', ]); ```