From 2b7c76a66bf9ff68ea8e792a0eb4e67e321b90c3 Mon Sep 17 00:00:00 2001 From: Yozhef Hisem Date: Thu, 10 Oct 2024 23:43:18 +0300 Subject: [PATCH] feat: update documentation --- README.md | 98 +++------------------ docs/RedisContext/check-any-value-by-key.md | 10 +++ docs/RedisContext/check-array.md | 16 ++++ docs/RedisContext/check-key-exist.md | 10 +++ docs/RedisContext/check-serialized-value.md | 10 +++ docs/RedisContext/check-value-in-redis.md | 10 +++ docs/RedisContext/clean-db.md | 17 ++++ docs/RedisContext/store-seralized-value.md | 10 +++ docs/RedisContext/store-string-value.md | 10 +++ docs/install.md | 91 +++++++++++++++++++ src/Context/RedisContext.php | 4 +- 11 files changed, 198 insertions(+), 88 deletions(-) create mode 100644 docs/RedisContext/check-any-value-by-key.md create mode 100644 docs/RedisContext/check-array.md create mode 100644 docs/RedisContext/check-key-exist.md create mode 100644 docs/RedisContext/check-serialized-value.md create mode 100644 docs/RedisContext/check-value-in-redis.md create mode 100644 docs/RedisContext/clean-db.md create mode 100644 docs/RedisContext/store-seralized-value.md create mode 100644 docs/RedisContext/store-string-value.md create mode 100644 docs/install.md diff --git a/README.md b/README.md index 486e738..bbf432f 100644 --- a/README.md +++ b/README.md @@ -8,95 +8,21 @@ Symfony Behat Redis Context Installation ============ +[Installation Steps](docs/install.md) -Step 1: Download the Bundle ----------------------------------- -Open a command console, enter your project directory and execute: - -### Applications that use Symfony Flex [in progress](https://github.com/MacPaw/BehatRedisContext/issues/2) - -```console -$ composer require --dev macpaw/behat-redis-context -``` - -### Applications that don't use Symfony Flex - -Open a command console, enter your project directory and execute the -following command to download the latest stable version of this bundle: - -```console -$ composer require --dev macpaw/behat-redis-context -``` - -This command requires you to have Composer installed globally, as explained -in the [installation chapter](https://getcomposer.org/doc/00-intro.md) -of the Composer documentation. - - -Then, enable the bundle by adding it to the list of registered bundles -in the `app/AppKernel.php` file of your project: - -```php - ['test' => true], - ); - - // ... - } - - // ... -} -``` - -Create configuration for behat redis context: - -`config/packages/test/behat_redis_context.yaml ` -```yaml -behat_redis_context: - dataFixturesPath: "" -``` - - -Step 2: Change path to directory with your fixtures ----------------------------------- -`config/packages/test/behat_redis_context.yaml ` -```yaml -behat_redis_context: - dataFixturesPath: "your path" -``` - -Step 3: Change path to directory with your fixtures ----------------------------------- -`config/services_test.yaml` -```yaml -Predis\ClientInterface: 'Your Redis Client' -``` - -Example if you use [Symfony Redis Bundle](https://github.com/symfony-bundles/redis-bundle): -```yaml -Predis\ClientInterface: '@SymfonyBundles\RedisBundle\Redis\ClientInterface' -``` +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) -Step 4: Configure Behat -============= -Go to `behat.yml` -```yaml -... - contexts: - - BehatRedisContext\Context\RedisContext - - BehatRedisContext\Context\RedisFixturesContext -... -``` [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/RedisContext/check-any-value-by-key.md b/docs/RedisContext/check-any-value-by-key.md new file mode 100644 index 0000000..f257606 --- /dev/null +++ b/docs/RedisContext/check-any-value-by-key.md @@ -0,0 +1,10 @@ +### Check Any Value in Redis + +#### Step Definition: + +This step checks if any value exists in Redis under a specified key. + +#### Gherkin Example: + +```gherkin +When I see in redis any value by key "testKey" \ No newline at end of file diff --git a/docs/RedisContext/check-array.md b/docs/RedisContext/check-array.md new file mode 100644 index 0000000..3b089bb --- /dev/null +++ b/docs/RedisContext/check-array.md @@ -0,0 +1,16 @@ +### Check an Array in Redis + +#### Step Definition: + +This step checks if the data stored in Redis as a hash matches the expected JSON structure. + +#### Gherkin Example: + +```gherkin +Then I see in redis array by key "arrayKey": + """ + { + "key1": "value1", + "key2": "value2" + } + """ \ No newline at end of file diff --git a/docs/RedisContext/check-key-exist.md b/docs/RedisContext/check-key-exist.md new file mode 100644 index 0000000..2bc6210 --- /dev/null +++ b/docs/RedisContext/check-key-exist.md @@ -0,0 +1,10 @@ +### Check the Absence of a Value in Redis + +#### Step Definition: + +This step checks that no exists under a specific key in Redis. + +#### Gherkin Example: + +```gherkin +When I don't see in redis key "testKey" \ No newline at end of file diff --git a/docs/RedisContext/check-serialized-value.md b/docs/RedisContext/check-serialized-value.md new file mode 100644 index 0000000..d28d9eb --- /dev/null +++ b/docs/RedisContext/check-serialized-value.md @@ -0,0 +1,10 @@ +### Check a Serialized Value in Redis + +#### Step Definition: + +This step checks if a serialized value in Redis matches the expected value. It unserializes the value before comparing. + +#### Gherkin Example: + +```gherkin +When I see in redis serialized value "testSerializedValue" by key "serializedKey" \ No newline at end of file diff --git a/docs/RedisContext/check-value-in-redis.md b/docs/RedisContext/check-value-in-redis.md new file mode 100644 index 0000000..3a795ca --- /dev/null +++ b/docs/RedisContext/check-value-in-redis.md @@ -0,0 +1,10 @@ +### Check a Value in Redis + +#### Step Definition: + +This step checks if a specific value exists in Redis under the specified key. If the value is missing or does not match, the step will throw an error. + +#### Gherkin Example: + +```gherkin +When I see in redis value "testValue" by key "testKey" \ No newline at end of file diff --git a/docs/RedisContext/clean-db.md b/docs/RedisContext/clean-db.md new file mode 100644 index 0000000..28ebe0d --- /dev/null +++ b/docs/RedisContext/clean-db.md @@ -0,0 +1,17 @@ +## Redis Database Cleanup + +### Before Each Scenario + +The Redis database is automatically flushed before each scenario using the `@BeforeScenario` hook. This ensures that each scenario starts with a clean database, preventing test pollution from previous scenarios. + +#### Example Usage: + +There is no specific Gherkin step required; this happens automatically before each test scenario. + +### After Each Feature + +After all scenarios in a feature are completed, the system performs garbage collection to free up memory. + +#### Example Usage: + +There is no specific Gherkin step required; this happens automatically after the last test in a feature. \ No newline at end of file diff --git a/docs/RedisContext/store-seralized-value.md b/docs/RedisContext/store-seralized-value.md new file mode 100644 index 0000000..48cf20d --- /dev/null +++ b/docs/RedisContext/store-seralized-value.md @@ -0,0 +1,10 @@ +### Save a Serialized Value to Redis + +#### Step Definition: + +This step serializes a value and saves it in Redis under the given key. + +#### Gherkin Example: + +```gherkin +When I save serialized value "testSerializedValue" to redis by "serializedKey" diff --git a/docs/RedisContext/store-string-value.md b/docs/RedisContext/store-string-value.md new file mode 100644 index 0000000..272181b --- /dev/null +++ b/docs/RedisContext/store-string-value.md @@ -0,0 +1,10 @@ +### Save a String Value to Redis + +#### Step Definition: + +This step saves a string value in Redis with a specified key. + +#### Gherkin Example: + +```gherkin +When I save string value "testValue" to redis by "testKey" diff --git a/docs/install.md b/docs/install.md new file mode 100644 index 0000000..1c2b92e --- /dev/null +++ b/docs/install.md @@ -0,0 +1,91 @@ +Installation +============ + +Step 1: Download the Bundle +---------------------------------- +Open a command console, enter your project directory and execute: + +### Applications that use Symfony Flex [in progress](https://github.com/MacPaw/BehatRedisContext/issues/2) + +```console +$ composer require --dev macpaw/behat-redis-context +``` + +### Applications that don't use Symfony Flex + +Open a command console, enter your project directory and execute the +following command to download the latest stable version of this bundle: + +```console +$ composer require --dev macpaw/behat-redis-context +``` + +This command requires you to have Composer installed globally, as explained +in the [installation chapter](https://getcomposer.org/doc/00-intro.md) +of the Composer documentation. + + +Then, enable the bundle by adding it to the list of registered bundles +in the `app/AppKernel.php` file of your project: + +```php + ['test' => true], + ); + + // ... + } + + // ... +} +``` + +Create configuration for behat redis context: + +`config/packages/test/behat_redis_context.yaml ` +```yaml +behat_redis_context: + dataFixturesPath: "" +``` + + +Step 2: Change path to directory with your fixtures +---------------------------------- +`config/packages/test/behat_redis_context.yaml ` +```yaml +behat_redis_context: + dataFixturesPath: "your path" +``` + +Step 3: Change path to directory with your fixtures +---------------------------------- +`config/services_test.yaml` +```yaml +Predis\ClientInterface: 'Your Redis Client' +``` + +Example if you use [Symfony Redis Bundle](https://github.com/symfony-bundles/redis-bundle): +```yaml +Predis\ClientInterface: '@SymfonyBundles\RedisBundle\Redis\ClientInterface' +``` + +Step 4: Configure Behat +============= +Go to `behat.yml` + +```yaml +... + contexts: + - BehatRedisContext\Context\RedisContext + - BehatRedisContext\Context\RedisFixturesContext +... +``` \ No newline at end of file diff --git a/src/Context/RedisContext.php b/src/Context/RedisContext.php index debee4b..0aa986d 100644 --- a/src/Context/RedisContext.php +++ b/src/Context/RedisContext.php @@ -82,9 +82,9 @@ public function iSeeInRedisValueByKey(string $value, string $key): void } /** - * @When /^I don't see in redis value by key "([^"]*)"$/ + * @When /^I don't see in redis key "([^"]*)"$/ */ - public function iDontSeeInRedisValueByKey(string $key): void + public function iDontSeeInRedisKey(string $key): void { $found = $this->redis->get($key);