-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
176 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |