baywa-re-lusy/behat-contexts
最新稳定版本:2.12.0
Composer 安装命令:
composer require baywa-re-lusy/behat-contexts
包简介
BayWa r.e. Behat Contexts
README 文档
README
This repository provides you with different Behat Contexts containing common test steps that can be reused across different projects.
Installation
Install the package via Composer:
$ composer require --dev lusy/behat-contexts
In your behat.yml, add the following:
default: ... suites: api_features: contexts: ... - BayWaReLusy\BehatContext\HalContext - BayWaReLusy\BehatContext\SqsContext - BayWaReLusy\BehatContext\ConsoleContext ...
HalContext
A Context to parse & test API responses in HAL format:
- https://de.wikipedia.org/wiki/Hypertext_Application_Language
- https://stateless.group/hal_specification.html
In your FeatureContext, add the following:
use BayWaReLusy\BehatContext\HalContext\HalContextAwareTrait; use BayWaReLusy\BehatContext\HalContext\HalContextAwareInterface; class FeatureContext implements ... HalContextAwareInterface ... { use HalContextAwareTrait; ... /** * @BeforeScenario */ public function gatherContexts(\Behat\Behat\Hook\Scope\BeforeScenarioScope $scope) { ... $this->gatherHalContext($scope); $this->getHalContext() ->setJsonFilesPath(<path to directory with JSON files>) ->setBaseUrl(<API Base URL>) ->setBearerToken(<API Bearer Token>); ... } }
And when you receive a reponse from your API, pass it to the context:
/** @var Psr\Http\Message\ResponseInterface */ $apiResponse = ... $this->getHalContext()->setLastResponse($apiResponse);
You can add placeholders to your URL by writing:
When I send a "GET" request to "/resource-url/{MY_PLACEHOLDER}"
And add the corresponding value with:
$this->getHalContext()->addPlaceholder('MY_PLACEHOLDER', '<placeholder value>');
AuthContext
A Context to login to a generic Auth Server (OpenID Connect/OAuth2) with Login/Password or as a Machine-to-Machine client.
The HalContext needs to be initialized first.
In your FeatureContext, add the following:
use BayWaReLusy\BehatContext\AuthContext\AuthContextAwareTrait; use BayWaReLusy\BehatContext\AuthContext\AuthContextAwareInterface; use BayWaReLusy\BehatContext\AuthContext\MachineToMachineCredentials; use BayWaReLusy\BehatContext\AuthContext\UserCredentials; class FeatureContext implements ... AuthContextAwareInterface ... { use AuthContextAwareTrait; ... /** * @BeforeScenario */ public function gatherContexts(\Behat\Behat\Hook\Scope\BeforeScenarioScope $scope) { ... $this->gatherAuthContext($scope); $this->getAuthContext() ->setHalContext($this->getHalContext()) ->setServerAddress(<Auth Server address>) ->setTokenEndpoint(<Auth Server Token endpoint>) ->setTokenEndpoint(<Auth Server Token endpoint>) ->addMachineToMachineCredentials(new MachineToMachineCredentials( '<Client name describing the client>', '<Auth Client ID>', '<Auth Client Secret>' )) ->addUserCredentials(new UserCredentials( '<User Login>', '<User Password>', '<Auth Client ID>' )); ... } }
SqsContext
A Context to use AWS SQS compatible queues like e.g. ElasticMQ
In your FeatureContext, add the following:
use BayWaReLusy\BehatContext\SqsContext\SqsContextAwareTrait; use BayWaReLusy\BehatContext\SqsContext\SqsContextAwareInterface; use BayWaReLusy\BehatContext\SqsContext\QueueUrl; class FeatureContext implements ... SqsContextAwareInterface ... { use SqsContextAwareTrait; ... /** * @BeforeScenario */ public function gatherContexts(\Behat\Behat\Hook\Scope\BeforeScenarioScope $scope) { ... $queueService = ... // <== instance of BayWaReLusy\QueueTools\QueueService $this->gatherSqsContext($scope); $this->getSqsContext() ->setQueueService($queueService) ->setSqsEndpoint($sqsEndpoint) // <== optional Hostname of the SQS endpoint (e.g. "http://baywa_tms_elasticmq:9324") ->setAwsRegion(<AWS Region>) ->setAwsKey(<AWS Key>) ->setAwsSecret(<AWS Secret>) ->addQueue(new QueueUrl('queueName', $queueUrl)); ... } }
To clear the queues before each Scenario, use the following code:
/** * @BeforeScenario */ public function clearAllQueues(): void { // Clear all queues $this->sqsContext->clearAllQueues(); }
ConsoleContext
A Context containing steps to test console routes
In your FeatureContext, add the following:
use BayWaReLusy\BehatContext\ConsoleContext\ConsoleContextAwareTrait; use BayWaReLusy\BehatContext\ConsoleContext\ConsoleContextAwareInterface; class FeatureContext implements ... ConsoleContextAwareInterface ... { use ConsoleContextAwareTrait; ... /** * @BeforeScenario */ public function gatherContexts(\Behat\Behat\Hook\Scope\BeforeScenarioScope $scope) { ... $this->gatherConsoleContext($scope); ... } }
统计信息
- 总下载量: 993
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2022-04-12