fittinq / symfony-behat
Requires
- doctrine/doctrine-bundle: ^2.5
- doctrine/orm: ^2.1
- fittinq/logger-elasticsearch: ^6.0
- symfony/framework-bundle: ^6.0
- symfony/http-client: ^6.1
- symfony/process: ^6.1
Requires (Dev)
- behat/behat: ^3.10
- friends-of-behat/mink: ^1.10
- friends-of-behat/mink-extension: ^2.6
- friends-of-behat/symfony-extension: ^2.3
- phpunit/phpunit: ^9.5
- symfony/yaml: ^6.1
- dev-main
- 7.0.0
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.1.3
- 5.1.2
- 5.1.1
- 5.0.2
- 5.0.1
- 5.0.0
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-development
This package is auto-updated.
Last update: 2024-10-29 10:40:06 UTC
README
Introduction
Welcome to the Symfony Behat Bundle! This powerful tool simplifies the testing of authentication, services, and service mocks in Symfony applications using Behat. This README will guide you through the installation, configuration, and usage of this bundle.
Table of Contents
Installation
To add this bundle to your Symfony project, simply run the following Composer command:
composer require fittinq/symfony-behat
Authenticator Contexts
Authenticator Configuration
To configure your project for authenticator testing, add the Authenticator bundle to your Behat setup. Update your behat.yml
or behat.yaml
as follows:
default:
default:
paths:
- behat/features
contexts:
- Fittinq\Symfony\Behat\Authenticator\Context\AuthenticatorApiContext
- Fittinq\Symfony\Behat\Authenticator\Context\AuthenticatorDatabaseContext
- Fittinq\Symfony\Behat\Authenticator\Context\AuthenticatorUserContext
- Fittinq\Symfony\Behat\Authenticator\Context\AuthenticatorRoleContext
- Fittinq\Symfony\Behat\Authenticator\Context\AuthenticatorFrontendContext
Authenticator Use Cases
AuthenticatorRoleContext
The AuthenticatorRoleContext focuses on managing roles and provides steps for adding roles and verifying their existence. Here's an example usage:
Given there are roles
| name |
| ROLE_USER |
| ROLE_ADMIN |
| ROLE_EDITOR|
AuthenticatorUserContext
This context is designed for managing user-related Behat steps. It includes steps for adding users and authenticating them via an API. Example usage:
Given there are users
| username | password | roles |
| user1 | secret | ROLE_USER |
| admin | password | ROLE_ADMIN |
| editor | 123456 | ROLE_EDITOR |
AuthenticatorFrontendContext
The AuthenticatorFrontendContext is used for testing frontend interactions, such as user logins and checking HTTP status codes and page content. Example usage:
Given user user1 logs in to the frontend app
Then the current page should contain text "Welcome, user1!"
Services Contexts
Service Configuration
To configure your project for services testing, update your Behat setup as follows:
default:
default:
paths:
- behat/features
contexts:
- Fittinq\Symfony\Behat\Service\Context\ServiceContext
Service Use Cases
Adding Services
You can add services using a Gherkin scenario like this:
Given there are services
| name | url |
| service1 | http://service1.com |
| service2 | http://service2.com |
Marking Services as Unavailable
Simulate service unavailability with a Gherkin scenario like this:
Given service1 is unavailable
Service Mock Contexts
Service Mock Configuration
To configure your project for service mocking, update your Behat setup as follows:
default:
default:
paths:
- behat/features
contexts:
- Fittinq\Symfony\Behat\ServiceMock\Context\ServiceMockContext
Service Mock Use Cases
Setting up a Service Response
You can make a service respond with specific data when it is called. Example:
When service1 service responds
"""
{
"method": "POST",
"host": "http://service-mock",
"uri": "/api/testing",
"headers": [],
"httpStatusCode": 200,
"body": {
"content": "The request was successful"
}
}
"""
Checking If a Request Was Made to a Service
You can verify if a request has been made to a service with specific data. Example:
Then a request should have been made to service2
"""
{
"method": "POST",
"host": "http://service-mock",
"uri": "/api/create",
"invocationType": "once",
"headers": [],
"requests": [
{
"headers": {},
"body": {
"name": "test"
}
}
]
}
"""