Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/libresign/behat-builtin-extension
Extension to use built-in PHP server on Behat tests
https://github.com/libresign/behat-builtin-extension
api bdd behat behat-extension php php-builtin-server test-automation tests
Last synced: 6 days ago
JSON representation
Extension to use built-in PHP server on Behat tests
- Host: GitHub
- URL: https://github.com/libresign/behat-builtin-extension
- Owner: LibreSign
- License: agpl-3.0
- Created: 2022-02-21T16:31:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-14T20:25:19.000Z (8 months ago)
- Last Synced: 2024-05-17T00:23:42.901Z (6 months ago)
- Topics: api, bdd, behat, behat-extension, php, php-builtin-server, test-automation, tests
- Language: PHP
- Homepage:
- Size: 338 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![Behat](https://github.com/LibreSign/behat-builtin-extension/actions/workflows/behat.yml/badge.svg)](https://github.com/LibreSign/behat-builtin-extension/actions/workflows/behat.yml)
# Extension to use built-in PHP server on Behat tests
## Instalation
```bash
composer require libresign/behat-builtin-extension
vendor/bin/behat --init
```## Configuration
Add the extension to your `behat.yml`:
```yaml
default:
extensions:
PhpBuiltin\Server:
verbose: false
rootDir: /var/www/html
host: localhost
```### Config values
| config | default | Environment | Description |
| ------- | ------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| verbose | false | BEHAT_VERBOSE | Enables/disables verbose mode |
| rootDir | /var/www/html | BEHAT_ROOT_DIR | Specifies http root dir |
| host | localhost | BEHAT_HOST | Host domain or IP |
| runAs | | BEHAT_RUN_AS | The username to be used to run the built-in server |
| workers | 0 | BEHAT_WORKERS | The quantity of workers to use. More informations [here](https://www.php.net/manual/en/features.commandline.webserver.php) searching by `PHP_CLI_SERVER_WORKERS` |You can also use `-v` option to enable verbose mode. Example
```bash
vendor/bin/behat -v
```
The verbose mode will show:
* The rootDir used
* The output of PHP Built-in server## Usage example
```php
baseUrl = RunServerListener::getServerRoot();
}public function sendRequest(string $verb, string $url, ?array $body = null, array $headers = []): void
{
$client = new Client();$fullUrl = $this->baseUrl . ltrim($url, '/');
$options['headers'] = $headers;
if (is_array($body)) {
$options['form_params'] = $body;
}try {
$this->response = $client->{$verb}($fullUrl, $options);
} catch (ClientException $e) {
$this->response = $e->getResponse();
} catch (ServerException $e) {
$this->response = $e->getResponse();
}
}
}
```