Skip to content

Commit 5a706de

Browse files
authored
Merge pull request #4 from MacPaw/feat/rewriteAsBundle
feat: rewrite as bundle
2 parents 961ff04 + 9145db9 commit 5a706de

File tree

15 files changed

+231
-38
lines changed

15 files changed

+231
-38
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- '8.1'
1717
coverage: ['none']
1818
symfony-versions:
19+
- '4.4.*'
1920
- '5.1.*'
2021
- '5.2.*'
2122
- '5.3.*'
@@ -60,8 +61,10 @@ jobs:
6061
- name: Update Symfony version
6162
if: matrix.symfony-versions != ''
6263
run: |
63-
composer require symfony/messenger:${{ matrix.symfony-versions }} --no-update --no-scripts
64-
composer require symfony/serializer:${{ matrix.symfony-versions }} --no-update --no-scripts
64+
composer require symfony/http-client:${{ matrix.symfony-versions }} --no-update --no-scripts
65+
composer require symfony/cache:${{ matrix.symfony-versions }} --no-update --no-scripts
66+
composer require symfony/dependency-injection:${{ matrix.symfony-versions }} --no-update --no-scripts
67+
composer require symfony/http-kernel:${{ matrix.symfony-versions }} --no-update --no-scripts
6568
6669
- name: Install dependencies
6770
run: composer install

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
/composer.lock
33
/build/
44
/.phpunit.result.cache
5-
5+
/.idea/
66
/node_modules/
77
/package-lock.json

README.md

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,51 @@ Behat HTTP Mock Context
88
Installation
99
============
1010

11-
Step 1: Install Context
11+
Step 1: Download the Bundle
1212
----------------------------------
1313
Open a command console, enter your project directory and execute:
1414

15+
### Applications that use Symfony Flex [in progress]
1516
```console
1617
$ composer require --dev macpaw/behat-http-mock-context
1718
```
1819

19-
Step 2: Update Container config to load Context
20-
----------------------------------
21-
In the `config/services_test.yaml` file of your project:
20+
### Applications that don't use Symfony Flex
2221

23-
```yaml
24-
BehatHttpMockContext\:
25-
resource: '../vendor/macpaw/behat-http-mock-context/src/*'
22+
Open a command console, enter your project directory and execute the
23+
following command to download the latest stable version of this bundle:
24+
25+
```console
26+
$ composer require --dev macpaw/behat-http-mock-context
27+
```
28+
29+
This command requires you to have Composer installed globally, as explained
30+
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
31+
of the Composer documentation.
32+
33+
34+
Then, enable the bundle by adding it to the list of registered bundles
35+
in the `app/AppKernel.php` file of your project:
36+
37+
```php
38+
<?php
39+
// app/AppKernel.php
40+
41+
// ...
42+
class AppKernel extends Kernel
43+
{
44+
public function registerBundles()
45+
{
46+
$bundles = array(
47+
// ...
48+
BehatHttpMockContext\BehatHttpMockContextBundle::class => ['test' => true],
49+
);
50+
51+
// ...
52+
}
53+
54+
// ...
55+
}
2656
```
2757

2858
Step 2: Mock http client
@@ -55,7 +85,7 @@ Now we ready add build mock collection
5585
...
5686
```
5787

58-
Step 4: Configure Behat
88+
Step 3: Configure Behat
5989
=============
6090
Go to `behat.yml`
6191

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "macpaw/behat-http-mock-context",
3-
"type": "library",
3+
"type": "symfony-bundle",
44
"description": "Behat Context in testing mock HTTP Response other service",
55
"keywords": [
66
"MacPaw",
@@ -23,9 +23,11 @@
2323
"require": {
2424
"php": "^8.0",
2525
"behat/behat": "^3.0",
26-
"symfony/http-client": "^5.0 || ^6.0",
27-
"symfony/cache": "^5.0 || ^6.0",
28-
"macpaw/extended_mock_http_client": "^1.0 || ^2.0"
26+
"symfony/http-client": "^4.4 || ^5.0 || ^6.0",
27+
"symfony/cache": "^4.4 || ^5.0 || ^6.0",
28+
"macpaw/extended_mock_http_client": "^1.0 || ^2.0",
29+
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0",
30+
"symfony/http-kernel": "^4.4 || ^5.4 || ^6.0"
2931
},
3032
"require-dev": {
3133
"phpstan/phpstan": "^1.2",

src/BehatHttpMockContextBundle.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BehatHttpMockContext;
6+
7+
use Symfony\Component\HttpKernel\Bundle\Bundle;
8+
9+
class BehatHttpMockContextBundle extends Bundle
10+
{
11+
}

src/Collection/ExtendedMockHttpClientCollection.php renamed to src/Collection/ExtendedHttpMockClientCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Symfony\Component\Cache\ResettableInterface;
88

9-
class ExtendedMockHttpClientCollection implements ResettableInterface
9+
class ExtendedHttpMockClientCollection implements ResettableInterface
1010
{
1111
/*** @param iterable $handlers */
1212
public function __construct(private iterable $handlers)

src/Context/MockContext.php renamed to src/Context/HttpMockContext.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace BehatHttpMockContext\Context;
66

7-
use BehatHttpMockContext\Collection\ExtendedMockHttpClientCollection;
7+
use BehatHttpMockContext\Collection\ExtendedHttpMockClientCollection;
88
use Behat\Behat\Context\Context;
99
use Behat\Gherkin\Node\PyStringNode;
1010
use ExtendedMockHttpClient\Builder\RequestMockBuilder;
@@ -14,11 +14,11 @@
1414
use Symfony\Component\DependencyInjection\ContainerInterface;
1515
use Symfony\Component\HttpClient\Response\MockResponse;
1616

17-
class MockContext implements Context
17+
class HttpMockContext implements Context
1818
{
1919
public function __construct(
2020
private ContainerInterface $container,
21-
private ExtendedMockHttpClientCollection $extendedMockHttpClientCollection
21+
private ExtendedHttpMockClientCollection $extendedHttpMockClientCollection
2222
) {
2323
}
2424

@@ -29,7 +29,7 @@ public function __construct(
2929
*/
3030
public function afterScenario(): void
3131
{
32-
foreach ($this->extendedMockHttpClientCollection->getHandlers() as $extendedMockHttpClient) {
32+
foreach ($this->extendedHttpMockClientCollection->getHandlers() as $extendedMockHttpClient) {
3333
if (!($extendedMockHttpClient instanceof ExtendedMockHttpClient)) {
3434
throw new RuntimeException('You should replace HTTP client service using ExtendedMockHttpClient');
3535
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BehatHttpMockContext\DependencyInjection;
6+
7+
use Symfony\Component\Config\FileLocator;
8+
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
use Symfony\Component\DependencyInjection\Extension\Extension;
10+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
11+
12+
class BehatHttpMockContextExtension extends Extension
13+
{
14+
/**
15+
* @param array<array> $configs
16+
*
17+
* {@inheritdoc}
18+
*/
19+
public function load(array $configs, ContainerBuilder $container): void
20+
{
21+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
22+
$loader->load('http_mock_context.xml');
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BehatHttpMockContext\DependencyInjection;
6+
7+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8+
use Symfony\Component\Config\Definition\ConfigurationInterface;
9+
10+
class Configuration implements ConfigurationInterface
11+
{
12+
public function getConfigTreeBuilder(): TreeBuilder
13+
{
14+
return new TreeBuilder('behat_http_mock_context');
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
4+
xsd:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<services>
7+
<service public="true" autowire="true" id="BehatHttpMockContext\Context\HttpMockContext" class="BehatHttpMockContext\Context\HttpMockContext">
8+
<argument key="$container" type="service" id="test.service_container"/>
9+
<argument key="$extendedHttpMockClientCollection" type="service" id="BehatHttpMockContext\Collection\ExtendedHttpMockClientCollection"/>
10+
</service>
11+
<service public="true" autowire="true" id="BehatHttpMockContext\Collection\ExtendedHttpMockClientCollection" class="BehatHttpMockContext\Collection\ExtendedHttpMockClientCollection">
12+
<argument key="$handlers" type="tagged_iterator" tag="mock.http_client"/>
13+
</service>
14+
</services>
15+
</container>

0 commit comments

Comments
 (0)