Skip to content

Commit df54744

Browse files
authored
[UPDATE] Make http_client required (#81)
1 parent 5aa9ceb commit df54744

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Then
2626

2727
sensiolabs_gotenberg:
2828
assets_directory: '%kernel.project_dir%/assets'
29-
http_client: 'gotenberg.client'
29+
http_client: 'gotenberg.client' # Required and must have a `base_uri`.
3030
# Override the request Gotenberg will make to call one of your routes.
3131
request_context:
3232
# Used only when using `->route()`. Overrides the guessed `base_url` from the request. May be useful in CLI.

src/DependencyInjection/Configuration.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ public function getConfigTreeBuilder(): TreeBuilder
2424
->defaultValue('%kernel.project_dir%/assets')
2525
->end()
2626
->scalarNode('http_client')
27-
->info('HTTP Client reference to use.')
28-
->defaultValue('http_client')
27+
->info('HTTP Client reference to use. (Must have a base_uri)')
28+
->isRequired()
29+
->cannotBeEmpty()
2930
->end()
3031
->arrayNode('request_context')
3132
->info('Override the request Gotenberg will make to call one of your routes.')

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,26 @@ public function testDefaultConfigIsCorrect(): void
1717
$processor = new Processor();
1818
$config = $processor->processConfiguration(
1919
new Configuration(),
20-
[],
20+
[[
21+
'http_client' => 'http_client',
22+
]],
2123
);
2224

2325
self::assertEquals(self::getBundleDefaultConfig(), $config);
2426
}
2527

28+
public function testHttpClientIsRequired(): void
29+
{
30+
$this->expectException(InvalidConfigurationException::class);
31+
$this->expectExceptionMessage('The child config "http_client" under "sensiolabs_gotenberg" must be configured: HTTP Client reference to use. (Must have a base_uri)');
32+
33+
$processor = new Processor();
34+
$processor->processConfiguration(
35+
new Configuration(),
36+
[],
37+
);
38+
}
39+
2640
/**
2741
* @return array<string, list<mixed>>
2842
*/
@@ -52,6 +66,7 @@ public function testWithExtraHeadersConfiguration(): void
5266
/** @var array{'default_options': array<string, mixed>} $config */
5367
$config = $processor->processConfiguration(new Configuration(), [
5468
[
69+
'http_client' => 'http_client',
5570
'default_options' => [
5671
'pdf' => [
5772
'html' => ['extra_http_headers' => [['name' => 'MyHeader', 'value' => 'MyValue'], ['name' => 'User-Agent', 'value' => 'MyValue']]],

tests/DependencyInjection/SensiolabsGotenbergExtensionTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ public function testUrlBuildersCanChangeTheirRequestContext(string $serviceName)
241241
self::assertNotContains('.sensiolabs_gotenberg.request_context', $containerBuilder->getServiceIds());
242242

243243
$extension->load([[
244+
'http_client' => 'http_client',
244245
'request_context' => [
245246
'base_uri' => 'https://sensiolabs.com',
246247
],
@@ -270,7 +271,9 @@ public function testDataCollectorIsNotEnabledWhenKernelDebugIsFalse(): void
270271
$extension = new SensiolabsGotenbergExtension();
271272

272273
$containerBuilder = $this->getContainerBuilder(kernelDebug: false);
273-
$extension->load([], $containerBuilder);
274+
$extension->load([[
275+
'http_client' => 'http_client',
276+
]], $containerBuilder);
274277

275278
self::assertNotContains('sensiolabs_gotenberg.data_collector', $containerBuilder->getServiceIds());
276279
}
@@ -280,7 +283,9 @@ public function testDataCollectorIsEnabledWhenKernelDebugIsTrue(): void
280283
$extension = new SensiolabsGotenbergExtension();
281284

282285
$containerBuilder = $this->getContainerBuilder(kernelDebug: true);
283-
$extension->load([], $containerBuilder);
286+
$extension->load([[
287+
'http_client' => 'http_client',
288+
]], $containerBuilder);
284289

285290
self::assertContains('sensiolabs_gotenberg.data_collector', $containerBuilder->getServiceIds());
286291
}
@@ -291,6 +296,7 @@ public function testDataCollectorIsProperlyConfiguredIfEnabled(): void
291296

292297
$containerBuilder = $this->getContainerBuilder(kernelDebug: true);
293298
$extension->load([[
299+
'http_client' => 'http_client',
294300
'default_options' => [
295301
'pdf' => [
296302
'html' => [
@@ -384,6 +390,7 @@ private static function getValidConfig(): array
384390
{
385391
return [
386392
[
393+
'http_client' => 'http_client',
387394
'default_options' => [
388395
'pdf' => [
389396
'html' => [

tests/Kernel.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ private function configureContainer(ContainerConfigurator $container, LoaderInte
3333
$builder->loadFromExtension('framework', [
3434
'test' => true,
3535
]);
36+
$builder->loadFromExtension('sensiolabs_gotenberg', [
37+
'http_client' => 'http_client',
38+
]);
3639
$builder->addCompilerPass($this);
3740
}
3841

0 commit comments

Comments
 (0)