Skip to content

Commit

Permalink
[UPDATE] Make http_client required (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neirda24 authored Jun 21, 2024
1 parent 5aa9ceb commit df54744
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Then

sensiolabs_gotenberg:
assets_directory: '%kernel.project_dir%/assets'
http_client: 'gotenberg.client'
http_client: 'gotenberg.client' # Required and must have a `base_uri`.
# Override the request Gotenberg will make to call one of your routes.
request_context:
# Used only when using `->route()`. Overrides the guessed `base_url` from the request. May be useful in CLI.
Expand Down
5 changes: 3 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public function getConfigTreeBuilder(): TreeBuilder
->defaultValue('%kernel.project_dir%/assets')
->end()
->scalarNode('http_client')
->info('HTTP Client reference to use.')
->defaultValue('http_client')
->info('HTTP Client reference to use. (Must have a base_uri)')
->isRequired()
->cannotBeEmpty()
->end()
->arrayNode('request_context')
->info('Override the request Gotenberg will make to call one of your routes.')
Expand Down
17 changes: 16 additions & 1 deletion tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@ public function testDefaultConfigIsCorrect(): void
$processor = new Processor();
$config = $processor->processConfiguration(
new Configuration(),
[],
[[
'http_client' => 'http_client',
]],
);

self::assertEquals(self::getBundleDefaultConfig(), $config);
}

public function testHttpClientIsRequired(): void
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The child config "http_client" under "sensiolabs_gotenberg" must be configured: HTTP Client reference to use. (Must have a base_uri)');

$processor = new Processor();
$processor->processConfiguration(
new Configuration(),
[],
);
}

/**
* @return array<string, list<mixed>>
*/
Expand Down Expand Up @@ -52,6 +66,7 @@ public function testWithExtraHeadersConfiguration(): void
/** @var array{'default_options': array<string, mixed>} $config */
$config = $processor->processConfiguration(new Configuration(), [
[
'http_client' => 'http_client',
'default_options' => [
'pdf' => [
'html' => ['extra_http_headers' => [['name' => 'MyHeader', 'value' => 'MyValue'], ['name' => 'User-Agent', 'value' => 'MyValue']]],
Expand Down
11 changes: 9 additions & 2 deletions tests/DependencyInjection/SensiolabsGotenbergExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public function testUrlBuildersCanChangeTheirRequestContext(string $serviceName)
self::assertNotContains('.sensiolabs_gotenberg.request_context', $containerBuilder->getServiceIds());

$extension->load([[
'http_client' => 'http_client',
'request_context' => [
'base_uri' => 'https://sensiolabs.com',
],
Expand Down Expand Up @@ -270,7 +271,9 @@ public function testDataCollectorIsNotEnabledWhenKernelDebugIsFalse(): void
$extension = new SensiolabsGotenbergExtension();

$containerBuilder = $this->getContainerBuilder(kernelDebug: false);
$extension->load([], $containerBuilder);
$extension->load([[
'http_client' => 'http_client',
]], $containerBuilder);

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

$containerBuilder = $this->getContainerBuilder(kernelDebug: true);
$extension->load([], $containerBuilder);
$extension->load([[
'http_client' => 'http_client',
]], $containerBuilder);

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

$containerBuilder = $this->getContainerBuilder(kernelDebug: true);
$extension->load([[
'http_client' => 'http_client',
'default_options' => [
'pdf' => [
'html' => [
Expand Down Expand Up @@ -384,6 +390,7 @@ private static function getValidConfig(): array
{
return [
[
'http_client' => 'http_client',
'default_options' => [
'pdf' => [
'html' => [
Expand Down
3 changes: 3 additions & 0 deletions tests/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ private function configureContainer(ContainerConfigurator $container, LoaderInte
$builder->loadFromExtension('framework', [
'test' => true,
]);
$builder->loadFromExtension('sensiolabs_gotenberg', [
'http_client' => 'http_client',
]);
$builder->addCompilerPass($this);
}

Expand Down

0 comments on commit df54744

Please sign in to comment.