Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 12 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
// app/AppKernel.php
This bundle provides a Behat context for testing your application's interaction with a database using Doctrine ORM.

// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
BehatOrmContext\BehatOrmContextBundle::class => ['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
Expand Down
26 changes: 26 additions & 0 deletions docs/ORMContext/see-count-in-repository.md
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions docs/ORMContext/see-entity-in-repository-with-id.md
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions docs/ORMContext/see-entity-in-repository-with-properties.md
Original file line number Diff line number Diff line change
@@ -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
71 changes: 71 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
@@ -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
<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
BehatOrmContext\BehatOrmContextBundle::class => ['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`.