PHP code example of drevops / behat-phpserver
1. Go to this page and download the library: Download drevops/behat-phpserver 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/ */
drevops / behat-phpserver example snippets
declare(strict_types=1);
use Behat\Behat\Context\Context;
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use DrevOps\BehatPhpServer\ApiServerContext;
use DrevOps\BehatPhpServer\PhpServerContext;
class FeatureContext implements Context {
/**
* The PHP server URL.
*/
protected string $phpServerUrl;
/**
* The API server URL.
*/
protected string $apiServerUrl;
/**
* Initialize the context.
*
* @beforeScenario
*/
public function beforeScenarioInit(BeforeScenarioScope $scope): void {
$environment = $scope->getEnvironment();
if (!$environment instanceof InitializedContextEnvironment) {
throw new \Exception('Environment is not initialized');
}
$context = $environment->getContext(PhpServerContext::class);
$this->phpServerUrl = $context->getServerUrl();
$context = $environment->getContext(ApiServerContext::class);
$this->apiServerUrl = $context->getServerUrl();
}
}