Skip to content

Commit 3250999

Browse files
authored
Merge pull request #47 from MacPaw/develop
Merge pull request #45 from MacPaw/feat/orc-8134-add-depracation-for-orm-context
2 parents 8ec579e + 60cf4a0 commit 3250999

File tree

4 files changed

+108
-74
lines changed

4 files changed

+108
-74
lines changed

README.md

Lines changed: 53 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,90 @@
11
# Behat Api Context Bundle
22

3-
| Version | Build Status | Code Coverage |
4-
|:---------:|:-------------:|:-----:|
5-
| `master` | [![CI][master Build Status Image]][master Build Status] | [![Coverage Status][master Code Coverage Image]][master Code Coverage] |
6-
| `develop` | [![CI][develop Build Status Image]][develop Build Status] | [![Coverage Status][develop Code Coverage Image]][develop Code Coverage] |
3+
| Version | Build Status | Code Coverage | Latest Release |
4+
|:---------:|:---------------------------------------------------------:|:------------------------------------------------------------------------:|:-----------------:|
5+
| `master` | [![CI][master Build Status Image]][master Build Status] | [![Coverage Status][master Code Coverage Image]][master Code Coverage] | ![Latest Release] |
6+
| `develop` | [![CI][develop Build Status Image]][develop Build Status] | [![Coverage Status][develop Code Coverage Image]][develop Code Coverage] | - |
77

8-
## Installation
9-
10-
### Step 1: Download the Bundle
8+
## ⚠️ Deprecation Notice
119

12-
Open a command console, enter your project directory and execute:
10+
> The `ORMContext` has been **deprecated** and **removed** from this package.
11+
> Please use the standalone package [`macpaw/behat-orm-context`](https://github.com/macpaw/behat-orm-context) instead.
1312
14-
#### Applications that use Symfony Flex [in progress](https://github.com/MacPaw/BehatRedisContext/issues/2)
13+
---
1514

16-
```bash
17-
composer require --dev macpaw/behat-api-context
18-
```
15+
## Installation
1916

20-
#### Applications that don't use Symfony Flex
17+
### Step 1: Install the Bundle
2118

22-
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
19+
Run the following command in your project directory to install the bundle as a development dependency:
2320

2421
```bash
25-
composer require --dev macpaw/behat-api-context
22+
composer require --dev macpaw/behat-api-context
2623
```
2724

28-
This command requires you to have Composer installed globally, as explained
29-
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
30-
of the Composer documentation.
25+
> If you are using Symfony Flex, the bundle will be registered automatically.
26+
> Otherwise, follow Step 2 to register the bundle manually.
27+
### Step 2: Register the Bundle
3128

32-
33-
Then, enable the bundle by adding it to the list of registered bundles
34-
in the `app/AppKernel.php` file of your project:
29+
If your project does **not** use Symfony Flex or the bundle does not provide a recipe, manually register it in `config/bundles.php`:
3530

3631
```php
3732
<?php
38-
// app/AppKernel.php
39-
40-
// ...
41-
class AppKernel extends Kernel
42-
{
43-
public function registerBundles()
44-
{
45-
$bundles = array(
46-
// ...
47-
BehatApiContext\BehatApiContextBundle::class => ['test' => true],
48-
);
49-
50-
// ...
51-
}
33+
// config/bundles.php
5234

35+
return [
5336
// ...
54-
}
37+
BehatApiContext\BehatApiContextBundle::class => ['test' => true],
38+
];
5539
```
5640

57-
---
41+
> ℹ️ The bundle should only be enabled in the `test` environment.
5842
59-
## Step 2: Configure Behat
43+
### Step 3: Configure Behat
6044

61-
Go to `behat.yml`:
45+
Update your `behat.yml`:
6246

6347
```yaml
64-
# ...
65-
contexts:
66-
- BehatApiContext\Context\ApiContext
67-
# ...
48+
default:
49+
suites:
50+
default:
51+
contexts:
52+
- BehatApiContext\Context\ApiContext
53+
- BehatApiContext\Context\ORMContext
6854
```
6955
70-
### Optional: Enable ORMContext
56+
> If you also want to use `ORMContext`, install [macpaw/behat-orm-context](https://github.com/macpaw/behat-orm-context) and follow its setup instructions.
7157

72-
If you want to use `ORMContext`, you need to have `doctrine/orm` installed:
58+
> 📄 **Migration Notice:** `OrmContext` will be removed from `behat-api-context` in the next major release.
59+
> Please migrate to [`behat-orm-context`](https://github.com/macpaw/behat-orm-context) to avoid test failures.
60+
> See the full [ORMContext Migration Plan](./docs/ormcontext-migration.md) for step-by-step instructions.
7361

74-
```bash
75-
composer require --dev doctrine/orm
76-
```
77-
78-
Then, update your `behat.yml`:
79-
80-
```yaml
81-
# ...
82-
contexts:
83-
- BehatApiContext\Context\ORMContext
84-
# ...
85-
```
8662

8763
---
8864

8965
## Configuration
9066

91-
By default, the bundle has the following configuration:
67+
By default, the bundle provides the following configuration:
68+
> This bundle does not yet include a Symfony recipe to automatically create the configuration file.
69+
> If you need a specific configuration, you have to add it manually.
70+
> [Recipe in progress](https://github.com/MacPaw/BehatRedisContext/issues/2)
9271

9372
```yaml
9473
behat_api_context:
95-
kernel_reset_managers:
96-
- BehatApiContext\Service\ResetManager\DoctrineResetManager
74+
kernel_reset_managers: []
9775
```
9876

99-
The `use_orm_context` parameter is no longer configurable manually. Its value is determined automatically based on whether the Doctrine ORM is installed:
100-
> **Important:** This logic is applied internally and cannot be overridden via configuration.
77+
You can also add your own reset manager by overriding the configuration manually in `config/packages/test/behat_api_context.yaml`:
10178

102-
| ORM Installed | Default `use_orm_context` |
103-
|:-------------:|:-------------------------:|
104-
| Yes | `true` |
105-
| No | `false` |
79+
```yaml
80+
behat_api_context:
81+
kernel_reset_managers:
82+
- BehatApiContext\Service\ResetManager\DoctrineResetManager
83+
```
10684

10785
---
10886

109-
# Usage
87+
## Usage
11088

11189
### Runnable request parameters
11290

@@ -127,25 +105,26 @@ You can use dynamic expressions:
127105
```gherkin
128106
"""
129107
{
130-
"dateTo": "<(new DateTimeImmutable())->add(new DateInterval('P6D'))->getTimeStamp()>",
131-
"dateFrom": "<(new DateTimeImmutable())->add(new DateInterval('P2D'))->getTimeStamp()>"
108+
"dateTo": "<(new DateTimeImmutable())->add(new DateInterval('P6D'))->getTimestamp()>",
109+
"dateFrom": "<(new DateTimeImmutable())->add(new DateInterval('P2D'))->getTimestamp()>"
132110
}
133111
"""
134112
```
135113

136114
#### To achieve this, several conditions must be met:
137115
- Runnable code must be a string and placed inside `<>`.
138116
- Do not add `return` keyword at the beginning, otherwise a `RuntimeException` will be thrown.
139-
- Do not add `;` at the end of the expression, otherwise a `RuntimeException` will be thrown.
117+
- Do not add a semicolon (`;`) at the end of the expression, otherwise a `RuntimeException` will be thrown.
140118
- Avoid code that returns `null`, otherwise a `RuntimeException` will be thrown.
141119

142120
---
143121

144-
[master Build Status]: https://github.com/macpaw/behat-api-context/actions?query=workflow%3ACI+branch%3Amaster
145-
[master Build Status Image]: https://github.com/macpaw/behat-api-context/workflows/CI/badge.svg?branch=master
146-
[develop Build Status]: https://github.com/macpaw/behat-api-context/actions?query=workflow%3ACI+branch%3Adevelop
147-
[develop Build Status Image]: https://github.com/macpaw/behat-api-context/workflows/CI/badge.svg?branch=develop
122+
[master Build Status]: https://github.com/MacPaw/behat-api-context/actions/workflows/ci.yaml
123+
[master Build Status Image]: https://github.com/MacPaw/behat-api-context/actions/workflows/ci.yaml/badge.svg?branch=master
124+
[develop Build Status]: https://github.com/MacPaw/behat-api-context/actions/workflows/ci.yaml
125+
[develop Build Status Image]: https://github.com/MacPaw/behat-api-context/actions/workflows/ci.yaml/badge.svg?branch=develop
148126
[master Code Coverage]: https://codecov.io/gh/macpaw/behat-api-context/branch/master
149127
[master Code Coverage Image]: https://img.shields.io/codecov/c/github/macpaw/behat-api-context/master?logo=codecov
150128
[develop Code Coverage]: https://codecov.io/gh/macpaw/behat-api-context/branch/develop
151129
[develop Code Coverage Image]: https://img.shields.io/codecov/c/github/macpaw/behat-api-context/develop?logo=codecov
130+
[Latest Release]: https://img.shields.io/github/v/release/macpaw/behat-api-context

composer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
"BehatApiContext\\Tests\\": "tests"
5656
}
5757
},
58+
"extra": {
59+
"branch-alias": {
60+
"dev-master": "1.x-dev"
61+
},
62+
"deprecated": "The ORMContext has been removed from this package. Please use macpaw/behat-orm-context instead."
63+
},
5864
"scripts": {
5965
"composer-validate": "composer validate",
6066
"phpstan": "./vendor/bin/phpstan analyse -l max",
@@ -67,6 +73,15 @@
6773
"@phpstan",
6874
"@code-style",
6975
"@phpunit"
76+
],
77+
"post-install-cmd": [
78+
"@show-deprecation"
79+
],
80+
"post-update-cmd": [
81+
"@show-deprecation"
82+
],
83+
"show-deprecation": [
84+
"@php -r \"echo '[DEPRECATED] ORMContext has been removed from this package. Use macpaw/behat-orm-context instead.';\""
7085
]
7186
},
7287
"config": {

docs/ormcontext-migration.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Migration plan for using ORMContext
2+
3+
### Step 1: 📦 Add `behat-orm-context` to `composer.json`
4+
```bash
5+
composer require --dev macpaw/behat-orm-context
6+
```
7+
8+
### Step 2: 🧩 Register `OrmContext` in `behat.yml`
9+
```yaml
10+
default:
11+
suites:
12+
default:
13+
contexts:
14+
- BehatOrmContext\Context\OrmContext
15+
16+
```
17+
> If you previously used `BehatApiContext\Context\OrmContext`, replace it with `BehatOrmContext\Context\OrmContext`
18+
19+
### Step 3: 🧪 Verify Scenarios
20+
1. Run Behat tests:
21+
```bash
22+
vendor/bin/behat
23+
```
24+
25+
2. Ensure that all steps previously relying on OrmContext still work correctly after the migration.
26+
27+
### 🚨 Backward Compatibility Notice
28+
> `OrmContext` will be removed from `behat-api-context` in a future major release. If you don't migrate, your tests will break after updating dependencies.
29+
30+
### 🔔 Recommendation
31+
Perform the migration before the next major release of `behat-api-context` to avoid CI/CD disruptions and unexpected test failures in your production pipeline.

src/Context/ORMContext.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@
1111
use Doctrine\ORM\NoResultException;
1212
use RuntimeException;
1313

14+
/**
15+
* @deprecated since 1.4.0, use macpaw/behat-orm-context instead: https://github.com/MacPaw/behat-orm-context
16+
*/
1417
final class ORMContext implements Context
1518
{
1619
private EntityManagerInterface $manager;
1720

1821
public function __construct(EntityManagerInterface $manager)
1922
{
23+
trigger_error(
24+
'BehatApiContext\ORMContext is deprecated since version 1.4.0 and will be removed in 2.0. '
25+
. 'Please use macpaw/behat-orm-context instead: https://github.com/MacPaw/behat-orm-context',
26+
E_USER_DEPRECATED
27+
);
28+
2029
$this->manager = $manager;
2130
}
2231

0 commit comments

Comments
 (0)