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\Config\Config;
use Behat\Config\Profile;
use Behat\Config\Suite;
use DrevOps\BehatPhpServer\ApiServerContext;
use DrevOps\BehatPhpServer\PhpServerContext;
$suite = (new Suite('default'))
->addContext(PhpServerContext::class, [
'webroot' => '%paths.base%/tests/behat/fixtures',
'protocol' => 'http',
'host' => '0.0.0.0',
'port' => 8888,
'debug' => FALSE,
])
->addContext(ApiServerContext::class, [
'protocol' => 'http',
'host' => '0.0.0.0',
'port' => 8889,
'debug' => FALSE,
'paths' => [
'%paths.base%/tests/behat/fixtures',
'%paths.base%/tests/behat/fixtures2',
],
]);
$profile = (new Profile('default'))->withSuite($suite);
return (new Config())->withProfile($profile);
declare(strict_types=1);
use Behat\Behat\Context\Context;
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Hook\BeforeScenario;
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();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.