From b78eb232bbb86bc0eb2a341e3242e7b0d11fb4e1 Mon Sep 17 00:00:00 2001 From: Yozhef Hisem Date: Fri, 11 Oct 2024 00:00:08 +0300 Subject: [PATCH] feat: update documentation --- README.md | 71 +++++++++--- .../handling-missing-fixtures.md | 7 ++ .../how-load-fixture-in-radis.md | 109 ++++++++++++++++++ docs/RedisFixtures/how-works.md | 6 + 4 files changed, 176 insertions(+), 17 deletions(-) create mode 100644 docs/RedisFixtures/handling-missing-fixtures.md create mode 100644 docs/RedisFixtures/how-load-fixture-in-radis.md create mode 100644 docs/RedisFixtures/how-works.md diff --git a/README.md b/README.md index bbf432f..19a4043 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/RedisFixtures/handling-missing-fixtures.md b/docs/RedisFixtures/handling-missing-fixtures.md new file mode 100644 index 0000000..c3ccab9 --- /dev/null +++ b/docs/RedisFixtures/handling-missing-fixtures.md @@ -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. +``` \ No newline at end of file diff --git a/docs/RedisFixtures/how-load-fixture-in-radis.md b/docs/RedisFixtures/how-load-fixture-in-radis.md new file mode 100644 index 0000000..73b7e4f --- /dev/null +++ b/docs/RedisFixtures/how-load-fixture-in-radis.md @@ -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 \ No newline at end of file diff --git a/docs/RedisFixtures/how-works.md b/docs/RedisFixtures/how-works.md new file mode 100644 index 0000000..79114b4 --- /dev/null +++ b/docs/RedisFixtures/how-works.md @@ -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. \ No newline at end of file