Skip to content

Commit

Permalink
feat: update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yozhef committed Oct 10, 2024
1 parent 2b7c76a commit b78eb23
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 17 deletions.
71 changes: 54 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,65 @@
Symfony Behat Redis Context
=================================

# Symfony Behat Redis Context
| Version | Build Status | Code Coverage |
|:---------:|:-------------:|:-----:|
| `main`| [![CI][main Build Status Image]][main Build Status] | [![Coverage Status][main Code Coverage Image]][main Code Coverage] |
| `develop`| [![CI][develop Build Status Image]][develop Build Status] | [![Coverage Status][develop Code Coverage Image]][develop Code Coverage] |

Installation
============
[Installation Steps](docs/install.md)
Symfony Behat Redis Context is a package that integrates Redis operations with Behat for behavior-driven development (BDD). This context allows you to store, retrieve, and validate data in Redis as part of your Behat testing scenarios. It's useful when testing applications that depend on Redis for caching, session storage, or data management.

This documentation provides step-by-step guides for installing the package and utilizing each Redis-related step within Behat scenarios.

## How to Install Symfony Behat Redis Context

To install Symfony Behat Redis Context, follow these steps:

1. Add the package to your project using composer:
```bash
composer require --dev macpaw/behat-redis-context

For detailed steps and configuration, refer to the [Installation Steps](docs/install.md)

## RedisContext Documentation

Below are the available Redis operations that you can use in your Behat tests. Each step integrates seamlessly with Redis to ensure data is stored, retrieved, or validated as expected.

### Redis Step Definitions:

* [Check Any Value by Redis Key](docs/RedisContext/check-any-value-by-key.md)
Verifies if any value is stored in Redis under a specific key.

* [Check Array Value Stored in Redis](docs/RedisContext/check-array.md)
Ensures that the stored array or hash in Redis matches the expected structure.

* [Check if Key Exists in Redis](docs/RedisContext/check-key-exist.md)
Checks whether a specific key exists in Redis.

* [Check Serialized Value in Redis](docs/RedisContext/check-serialized-value.md)
Verifies that a serialized value stored in Redis matches the expected serialized value.

* [Check String Value in Redis](docs/RedisContext/check-value-in-redis.md)
Validates if a string value in Redis matches the expected value.

* [Clean Redis Database in Test](docs/RedisContext/clean-db.md)
Automatically flushes the Redis database before running a scenario to ensure a clean state.

* [Store Serialized Value in Redis](docs/RedisContext/store-seralized-value.md)
Serializes and stores a value in Redis with a given key.

* [Store String Value in Redis](docs/RedisContext/store-string-value.md)
Stores a simple string value in Redis under the specified key.

## RedisFixtureContext Documentation

Here you can find detailed documentation about using Redis fixtures in Behat:

Documentation how use:
============
RedisContext:
* [How Check Any Value By Redis Key](docs/RedisContext/check-any-value-by-key.md)
* [How Check Array Value Store in Redis](docs/RedisContext/check-array.md)
* [How Check Key Exist in Redis](docs/RedisContext/check-key-exist.md)
* [How Check Serialized Value in Redis](docs/RedisContext/check-serialized-value.md)
* [How Check String Value in Redis](docs/RedisContext/check-value-in-redis.md)
* [How Clean Redis in Test](docs/RedisContext/clean-db.md)
* [How Store Serialized Value in Redis](docs/RedisContext/store-seralized-value.md)
* [How Store String Value in Redis](docs/RedisContext/store-string-value.md)
1. **[How It Works](docs/RedisFixtures/how-works.md)**
Learn about the inner workings of the RedisFixtureContext and how it integrates with your Behat tests.

2. **[How to Load Fixture Data into Redis](docs/RedisFixtures/how-load-fixture-in-redis.md)**
A step-by-step guide on how to load predefined data fixtures into Redis using YAML files in Behat.

3. **[Handling Missing Fixture Files](docs/RedisFixtures/handling-missing-fixtures.md)**
What to do when a specified fixture file is missing and how to handle such errors in your tests.

[main Build Status]: https://github.com/macpaw/BehatRedisContext/actions?query=workflow%3ACI+branch%3Amain
[main Build Status Image]: https://github.com/macpaw/BehatRedisContext/workflows/CI/badge.svg?branch=main
Expand Down
7 changes: 7 additions & 0 deletions docs/RedisFixtures/handling-missing-fixtures.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Handling Missing Fixtures
If the specified fixture file is not found, an exception is thrown, indicating that the fixture is missing. Make sure the fixtures exist in the correct directory specified by data_fixtures_path.

Example Error Message:
```gherkin
The "orders" redis fixture not found.
```
109 changes: 109 additions & 0 deletions docs/RedisFixtures/how-load-fixture-in-radis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# How loading fixture date in Redis

## 1. Example Directory Structure
Here's how you can organize your project with fixture files for Redis:
```
project-root/
├── tests/
│ └── Fixtures/
│ └── Redis/
│ ├── Users.yml
│ └── Orders.yml
├── behat.yml
└── composer.json
```

## 2. Create Your Fixture Files
Example of `users.yml`:
```yaml
users:
1: "John Doe"
2: "Jane Smith"
3: "Alice Cooper"
```
In this example:
The users hash contains keys for user IDs (1, 2, 3) and their corresponding names.
When this fixture is loaded, these values will be stored in Redis under the hash key users.
Example of `orders.yml`:
```yaml
orders:
order_123:
id: 123
status: "pending"
total: 250.50
order_456:
id: 456
status: "completed"
total: 99.99
```
In this example:

The orders hash contains keys representing specific orders with associated data such as id, status, and total.
When this fixture is loaded, Redis will store each order with the given values.

## 3. Using Redis Fixture Context
Once you have created your fixture files, you can reference them in your Behat feature files using the step definition Given I load redis fixtures.

Example Behat Scenario:
```gherkin
Feature: Test Redis Data in Behat
Scenario: Check if Redis contains predefined users
Given I load redis fixtures "users"
When I see in redis any value by key "users"
Then I should see in redis array by key "users":
"""
{
"1": "John Doe",
"2": "Jane Smith",
"3": "Alice Cooper"
}
"""
```
In this scenario:

The fixture users.yml is loaded into Redis.
The test checks that the users key exists in Redis and contains the expected data.

## 4. Load Multiple Fixtures in One Scenario
You can load multiple fixtures in a single step by providing a comma-separated list of fixture names.

Example Behat Scenario:
```gherkin
Scenario: Load users and orders fixtures
Given I load redis fixtures "users, orders"
When I see in redis any value by key "users"
Then I should see in redis array by key "users":
"""
{
"1": "John Doe",
"2": "Jane Smith"
}
"""
When I see in redis any value by key "orders"
Then I should see in redis array by key "orders":
"""
{
"order_123": {
"id": 123,
"status": "pending",
"total": 250.50
},
"order_456": {
"id": 456,
"status": "completed",
"total": 99.99
}
}
"""
```
In this scenario:

Both users.yml and orders.yml fixtures are loaded into Redis.
The test checks that both users and orders contain the correct data.

4. Handling Missing Fixtures
6 changes: 6 additions & 0 deletions docs/RedisFixtures/how-works.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# How Redis Fixtures Work
When the Given I load redis fixtures step is called:

* The system looks for the specified YAML files in the directory defined by data_fixtures_path.
* Redis is populated with the key-value pairs or hash structures defined in these files.
* Simple key-value pairs are stored using the SET command, and hash sets are stored using the HMSET command.

0 comments on commit b78eb23

Please sign in to comment.