From b396dd218be380d8fe4407253b23bec102de50a1 Mon Sep 17 00:00:00 2001 From: Yozhef Hisem Date: Fri, 16 May 2025 15:17:20 +0300 Subject: [PATCH 1/2] feat: orc-11 create documentation method --- docs/ORMContext/see-count-in-repository.md | 26 ++++++++++++ .../see-entity-in-repository-with-id.md | 26 ++++++++++++ ...ee-entity-in-repository-with-properties.md | 40 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 docs/ORMContext/see-count-in-repository.md create mode 100644 docs/ORMContext/see-entity-in-repository-with-id.md create mode 100644 docs/ORMContext/see-entity-in-repository-with-properties.md diff --git a/docs/ORMContext/see-count-in-repository.md b/docs/ORMContext/see-count-in-repository.md new file mode 100644 index 0000000..0db7c27 --- /dev/null +++ b/docs/ORMContext/see-count-in-repository.md @@ -0,0 +1,26 @@ +### I See X Entities in Repository + +#### Step Definition: + +This step checks if the database contains exactly the specified number of entities for a given entity class. + +#### Gherkin Example: + +```gherkin +And I see 5 entities "App\Entity\User" +``` + +#### Description: + +This step allows you to verify that a specific number of entities exist in the database. It executes a count query on the database for the specified entity class and verifies that the result matches the expected count. + +#### Parameters: + +- `count`: The expected number of entities +- `entityClass`: The fully-qualified class name of the entity to check + +#### Use Cases: + +- Verifying that data setup was successful +- Checking that operations have created/deleted the expected number of records +- Validating database state after data manipulation steps \ No newline at end of file diff --git a/docs/ORMContext/see-entity-in-repository-with-id.md b/docs/ORMContext/see-entity-in-repository-with-id.md new file mode 100644 index 0000000..2b88155 --- /dev/null +++ b/docs/ORMContext/see-entity-in-repository-with-id.md @@ -0,0 +1,26 @@ +### I See Entity with Specific ID + +#### Step Definition: + +This step checks if the database contains an entity of a specific type with the given ID. + +#### Gherkin Example: + +```gherkin +And I see entity "App\Entity\Product" with id "abc123" +``` + +#### Description: + +This step allows you to verify that a specific entity exists in the database by its ID. It performs a count query with a condition on the ID field and expects exactly one matching entity. + +#### Parameters: + +- `entityClass`: The fully-qualified class name of the entity to check +- `id`: The ID value to match against the entity's ID field + +#### Use Cases: + +- Verifying that a specific record exists after creation +- Confirming entity persistence during a multi-step process +- Checking that an entity with a specific identifier is still present \ No newline at end of file diff --git a/docs/ORMContext/see-entity-in-repository-with-properties.md b/docs/ORMContext/see-entity-in-repository-with-properties.md new file mode 100644 index 0000000..1187bb2 --- /dev/null +++ b/docs/ORMContext/see-entity-in-repository-with-properties.md @@ -0,0 +1,40 @@ +### I See Entity with Specific Properties + +#### Step Definition: + +This step checks if the database contains an entity of a specific type with the given properties. + +#### Gherkin Example: + +```gherkin +Then I see entity "App\Entity\User" with properties: + """ + { + "email": "user@example.com", + "firstName": "John", + "lastName": "Doe", + "active": true + } + """ +``` + +#### Description: + +This step allows you to verify that a specific entity exists in the database by matching multiple property values. It performs a count query with conditions on each specified property and expects exactly one matching entity. + +#### Parameters: + +- `entityClass`: The fully-qualified class name of the entity to check +- `properties`: A JSON string containing key-value pairs representing entity properties to match + +#### Use Cases: + +- Verifying that an entity with specific field values exists +- Checking that entity properties match expected values after operations +- Validating complex entity state with multiple property conditions +- Testing business logic that modifies entity properties + +#### Notes: + +- Properties with `null` values are queried using `IS NULL` condition +- All other properties are matched using equality \ No newline at end of file From af0940f58496be04a954d02048684381bb2ba3bc Mon Sep 17 00:00:00 2001 From: Yozhef Hisem Date: Fri, 16 May 2025 15:22:00 +0300 Subject: [PATCH 2/2] feat: orc-11 create documentation method --- README.md | 79 ++++++++----------------------------------------- docs/install.md | 71 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 67 deletions(-) create mode 100644 docs/install.md diff --git a/README.md b/README.md index 3d61107..d47c4bc 100644 --- a/README.md +++ b/README.md @@ -5,82 +5,27 @@ | `master` | [![CI][master Build Status Image]][master Build Status] | [![Coverage Status][master Code Coverage Image]][master Code Coverage] | | `develop` | [![CI][develop Build Status Image]][develop Build Status] | [![Coverage Status][develop Code Coverage Image]][develop Code Coverage] | -## 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) - -```bash -composer require --dev macpaw/behat-orm-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: - -```bash -composer require --dev macpaw/behat-orm-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. +Behat context for testing Doctrine ORM integration. -Then, enable the bundle by adding it to the list of registered bundles -in the `app/AppKernel.php` file of your project: +## Description -```php - ['test' => true], - ); - - // ... - } - - // ... -} -``` - ---- - -### Step 2: Configure Behat - -Go to `behat.yml`: - -```yaml -# ... -contexts: - - BehatOrmContext\Context\OrmContext -# ... -``` - ---- +## Installation -## Configuration +See the [installation instructions](docs/install.md). -By default, the bundle has the following configuration: +## Features -```yaml -behat_orm_context: -``` +The bundle provides several Behat step definitions for ORM testing: -You can override it manually in your `config/packages/test/behat_orm_context.yaml`: +* [See X entities in repository](docs/ORMContext/see-count-in-repository.md) - Check if the count of entities in the repository matches expected +* [See entity with ID](docs/ORMContext/see-entity-in-repository-with-id.md) - Check if an entity with a specific ID exists +* [See entity with properties](docs/ORMContext/see-entity-in-repository-with-properties.md) - Check if an entity with specific properties exists ---- +## License +This bundle is released under the MIT license. See the included [LICENSE](LICENSE) file for more information. [master Build Status]: https://github.com/macpaw/behat-orm-context/actions?query=workflow%3ACI+branch%3Amaster [master Build Status Image]: https://github.com/macpaw/behat-orm-context/workflows/CI/badge.svg?branch=master diff --git a/docs/install.md b/docs/install.md new file mode 100644 index 0000000..3e44b62 --- /dev/null +++ b/docs/install.md @@ -0,0 +1,71 @@ +# Installation + +## Step 1: Download the Bundle + +Open a command console, enter your project directory and execute: + +### Applications that use Symfony Flex + +```bash + composer require --dev macpaw/behat-orm-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: + +```bash + composer require --dev macpaw/behat-orm-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], + ); + + // ... + } + + // ... +} +``` + +## Step 2: Configure Behat + +Go to `behat.yml`: + +```yaml +# ... +contexts: + - BehatOrmContext\Context\OrmContext: + manager: '@doctrine.orm.entity_manager' +# ... +``` + +## Configuration + +By default, the bundle has the following configuration: + +```yaml +behat_orm_context: + # Currently no specific configuration options are available +``` + +You can override it manually in your `config/packages/test/behat_orm_context.yaml`. \ No newline at end of file