Skip to content

Commit 5c5ee53

Browse files
committed
feat: rewrite as bundle
1 parent 961ff04 commit 5c5ee53

File tree

10 files changed

+91
-23
lines changed

10 files changed

+91
-23
lines changed

.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

composer.json

Lines changed: 4 additions & 2 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",
@@ -25,7 +25,9 @@
2525
"behat/behat": "^3.0",
2626
"symfony/http-client": "^5.0 || ^6.0",
2727
"symfony/cache": "^5.0 || ^6.0",
28-
"macpaw/extended_mock_http_client": "^1.0 || ^2.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/BehatMockHttpContextBundle.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 BehatMockHttpContextBundle 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: 3 additions & 3 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 $extendedMockHttpClientCollection
2222
) {
2323
}
2424

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\MockContext" class="BehatHttpMockContext\Context\MockContext">
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 type="tagged_iterator" tag="mock.http_client"/>
13+
</service>
14+
</services>
15+
</container>

tests/Collection/ExtendedMockHttpClientCollectionTest.php

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

55
namespace BehatHttpMockContext\Tests\Collection;
66

7-
use BehatHttpMockContext\Collection\ExtendedMockHttpClientCollection;
7+
use BehatHttpMockContext\Collection\ExtendedHttpMockClientCollection;
88
use PHPUnit\Framework\TestCase;
99
use TypeError;
1010

1111
class ExtendedMockHttpClientCollectionTest extends TestCase
1212
{
1313
public function testSuccess(): void
1414
{
15-
$clientCollection = new ExtendedMockHttpClientCollection([]);
15+
$clientCollection = new ExtendedHttpMockClientCollection([]);
1616

1717
$this->assertCount(0, $clientCollection->getHandlers());
1818
}
1919

2020
public function testInitFailed(): void
2121
{
2222
$this->expectException(TypeError::class);
23-
new ExtendedMockHttpClientCollection('string');
23+
new ExtendedHttpMockClientCollection('string');
2424
}
2525

2626
public function testSetHandlersSuccess(): void
2727
{
28-
$clientCollection = new ExtendedMockHttpClientCollection([]);
28+
$clientCollection = new ExtendedHttpMockClientCollection([]);
2929

3030
$this->assertCount(0, $clientCollection->getHandlers());
3131

@@ -37,15 +37,15 @@ public function testSetHandlersSuccess(): void
3737
public function testSetHandlersFailed(): void
3838
{
3939
$this->expectException(TypeError::class);
40-
$clientCollection = new ExtendedMockHttpClientCollection([]);
40+
$clientCollection = new ExtendedHttpMockClientCollection([]);
4141

4242
$this->assertCount(0, $clientCollection->getHandlers());
4343
$clientCollection->setHandlers('string');
4444
}
4545

4646
public function testResetSuccess(): void
4747
{
48-
$clientCollection = new ExtendedMockHttpClientCollection([[]]);
48+
$clientCollection = new ExtendedHttpMockClientCollection([[]]);
4949

5050
$this->assertCount(1, $clientCollection->getHandlers());
5151

tests/Context/MockContextTest.php

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

55
namespace BehatHttpMockContext\Tests\Context;
66

7-
use BehatHttpMockContext\Collection\ExtendedMockHttpClientCollection;
8-
use BehatHttpMockContext\Context\MockContext;
7+
use BehatHttpMockContext\Collection\ExtendedHttpMockClientCollection;
8+
use BehatHttpMockContext\Context\HttpMockContext;
99
use ExtendedMockHttpClient\Builder\RequestMockBuilder;
1010
use ExtendedMockHttpClient\ExtendedMockHttpClient;
1111
use ExtendedMockHttpClient\Model\HttpFixture;
@@ -21,11 +21,11 @@ public function testFailingObjectInCollection(): void
2121
{
2222
$this->expectException(RuntimeException::class);
2323

24-
$mockCollection = new ExtendedMockHttpClientCollection(
24+
$mockCollection = new ExtendedHttpMockClientCollection(
2525
['string']
2626
);
2727

28-
$mockContext = new MockContext(
28+
$mockContext = new HttpMockContext(
2929
new Container(),
3030
$mockCollection
3131
);
@@ -45,11 +45,11 @@ public function testSuccess(): void
4545
])
4646
));
4747

48-
$mockCollection = new ExtendedMockHttpClientCollection([
48+
$mockCollection = new ExtendedHttpMockClientCollection([
4949
new ExtendedMockHttpClient('macpaw.com')
5050
]);
5151

52-
$mockContext = new MockContext(
52+
$mockContext = new HttpMockContext(
5353
new Container(),
5454
$mockCollection
5555
);
@@ -73,11 +73,11 @@ public function testServiceNotFound(): void
7373
])
7474
));
7575

76-
$mockCollection = new ExtendedMockHttpClientCollection([
76+
$mockCollection = new ExtendedHttpMockClientCollection([
7777
new ExtendedMockHttpClient('macpaw.com')
7878
]);
7979

80-
$mockContext = new MockContext(
80+
$mockContext = new HttpMockContext(
8181
new Container(),
8282
$mockCollection
8383
);
@@ -100,14 +100,14 @@ public function testFailedClientService(): void
100100
])
101101
));
102102

103-
$mockCollection = new ExtendedMockHttpClientCollection([
103+
$mockCollection = new ExtendedHttpMockClientCollection([
104104
new ExtendedMockHttpClient('macpaw.com')
105105
]);
106106

107107
$container = new Container();
108108
$container->set('test', new stdClass());
109109

110-
$mockContext = new MockContext($container, $mockCollection);
110+
$mockContext = new HttpMockContext($container, $mockCollection);
111111

112112
$mockContext->iMockHttpClientNextResponse('test', 204);
113113
}

0 commit comments

Comments
 (0)