Skip to content

Commit 583bb53

Browse files
committed
fix: add integration tests
1 parent e219038 commit 583bb53

File tree

6 files changed

+95
-3
lines changed

6 files changed

+95
-3
lines changed

src/Resources/config/http_mock_context.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<argument key="$extendedHttpMockClientCollection" type="service" id="BehatHttpMockContext\Collection\ExtendedHttpMockClientCollection"/>
1010
</service>
1111
<service public="true" autowire="true" id="BehatHttpMockContext\Collection\ExtendedHttpMockClientCollection" class="BehatHttpMockContext\Collection\ExtendedHttpMockClientCollection">
12-
<argument type="tagged_iterator" tag="mock.http_client"/>
12+
<argument key="$handlers" type="tagged_iterator" tag="mock.http_client"/>
1313
</service>
1414
</services>
1515
</container>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BehatHttpMockContext\Tests\Integration\DependencyInjection;
6+
7+
use BehatHttpMockContext\Collection\ExtendedHttpMockClientCollection;
8+
use BehatHttpMockContext\Context\HttpMockContext;
9+
use BehatHttpMockContext\DependencyInjection\BehatHttpMockContextExtension;
10+
use PHPUnit\Framework\TestCase;
11+
use Symfony\Component\Config\FileLocator;
12+
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
13+
use Symfony\Component\DependencyInjection\ContainerBuilder;
14+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
15+
16+
class BehatHttpMockContextExtensionTest extends TestCase
17+
{
18+
public function testWithDefaultConfig(): void
19+
{
20+
$container = $this->createContainerFromFixture('bundle_config');
21+
22+
$collectionDefinition = $container->getDefinition(ExtendedHttpMockClientCollection::class);
23+
self::assertSame(ExtendedHttpMockClientCollection::class, $collectionDefinition->getClass());
24+
25+
$handlersArgument = $collectionDefinition->getArgument('$handlers');
26+
self::assertInstanceOf(TaggedIteratorArgument::class, $handlersArgument);
27+
self::assertSame(
28+
'mock.http_client',
29+
$handlersArgument->getTag()
30+
);
31+
32+
$httpMockContextDefinition = $container->getDefinition(HttpMockContext::class);
33+
self::assertSame(HttpMockContext::class, $httpMockContextDefinition->getClass());
34+
self::assertSame(
35+
'test.service_container',
36+
(string) $httpMockContextDefinition->getArgument('$container')
37+
);
38+
self::assertSame(
39+
ExtendedHttpMockClientCollection::class,
40+
(string) $httpMockContextDefinition->getArgument('$extendedHttpMockClientCollection')
41+
);
42+
}
43+
44+
private function createContainerFromFixture(string $fixtureFile): ContainerBuilder
45+
{
46+
$container = new ContainerBuilder();
47+
48+
$container->registerExtension(new BehatHttpMockContextExtension());
49+
$container->getCompilerPassConfig()->setOptimizationPasses([]);
50+
$container->getCompilerPassConfig()->setRemovingPasses([]);
51+
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
52+
53+
$this->loadFixture($container, $fixtureFile);
54+
55+
$container->compile();
56+
57+
return $container;
58+
}
59+
60+
protected function loadFixture(ContainerBuilder $container, string $fixtureFile): void
61+
{
62+
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Fixtures'));
63+
$loader->load($fixtureFile . '.yaml');
64+
}
65+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BehatHttpMockContext\Tests\Integration\DependencyInjection;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use BehatHttpMockContext\DependencyInjection\Configuration;
9+
use Symfony\Component\Config\Definition\Processor;
10+
11+
final class ConfigurationTest extends TestCase
12+
{
13+
public function testProcessConfigurationWithDefaultConfiguration(): void
14+
{
15+
$expectedBundleDefaultConfig = [];
16+
17+
$this->assertSame($expectedBundleDefaultConfig, $this->processConfiguration([]));
18+
}
19+
20+
private function processConfiguration(array $values): array
21+
{
22+
$processor = new Processor();
23+
24+
return $processor->processConfiguration(new Configuration(), ['behat_http_mock_context' => $values]);
25+
}
26+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
behat_http_mock_context:

tests/Collection/ExtendedMockHttpClientCollectionTest.php renamed to tests/Unit/Collection/ExtendedMockHttpClientCollectionTest.php

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

33
declare(strict_types=1);
44

5-
namespace BehatHttpMockContext\Tests\Collection;
5+
namespace BehatHttpMockContext\Tests\Unit\Collection;
66

77
use BehatHttpMockContext\Collection\ExtendedHttpMockClientCollection;
88
use PHPUnit\Framework\TestCase;

tests/Context/MockContextTest.php renamed to tests/Unit/Context/MockContextTest.php

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

33
declare(strict_types=1);
44

5-
namespace BehatHttpMockContext\Tests\Context;
5+
namespace BehatHttpMockContext\Tests\Unit\Context;
66

77
use BehatHttpMockContext\Collection\ExtendedHttpMockClientCollection;
88
use BehatHttpMockContext\Context\HttpMockContext;

0 commit comments

Comments
 (0)