PHP code example of libresign / behat-builtin-extension
1. Go to this page and download the library: Download libresign/behat-builtin-extension library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
libresign / behat-builtin-extension example snippets
use Behat\Behat\Context\Context;
use PhpBuiltin\RunServerListener;
/**
* Defines application features from the specific context.
*/
class FeatureContext implements Context
{
private string $baseUrl;
public function __construct()
{
$this->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();
}
}
}