Skip to content

Commit

Permalink
Merge pull request #414 from php-http/allow-null-ttl
Browse files Browse the repository at this point in the history
allow to configure default_ttl to null
  • Loading branch information
dbu authored Mar 17, 2022
2 parents b924cf6 + 8529a02 commit 0e5533d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.

# 1.26.0 - 2022-03-17

- Fixed you can now configure the cache plugin default_ttl with `null`.

# 1.25.0 - 2021-11-26
- Added PHP 8.1 support
- Added Symfony 6 support
Expand Down
8 changes: 7 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,14 @@ private function createCachePluginNode()
->integerNode('cache_lifetime')
->info('The minimum time we should store a cache item')
->end()
->integerNode('default_ttl')
->scalarNode('default_ttl')
->info('The default max age of a Response')
->validate()
->ifTrue(function ($v) {
return null !== $v && !is_int($v);
})
->thenInvalid('default_ttl must be an integer or null, got %s')
->end()
->end()
->arrayNode('blacklisted_paths')
->info('An array of regular expression patterns for paths not to be cached. Defaults to an empty array.')
Expand Down
9 changes: 9 additions & 0 deletions tests/Resources/Fixtures/config/ttl_null.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
httplug:
clients:
test:
plugins:
-
cache:
cache_pool: my_custom_cache_pull
config:
default_ttl: null
33 changes: 33 additions & 0 deletions tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,37 @@ public function testInvalidCapturedBodyLengthString(): void
$this->expectExceptionMessage('The child node "captured_body_length" at path "httplug.profiling" must be an integer or null');
$this->assertProcessedConfigurationEquals([], [$file]);
}

public function testNullDefaultTtl(): void
{
$file = __DIR__.'/../../Resources/Fixtures/config/ttl_null.yml';
$config = $this->emptyConfig;
$config['clients'] = [
'test' => [
'factory' => 'httplug.factory.auto',
'service' => null,
'public' => null,
'flexible_client' => false,
'http_methods_client' => false,
'batch_client' => false,
'config' => [],
'plugins' => [
[
'cache' => [
'config' => [
'default_ttl' => null,
'blacklisted_paths' => [],
'methods' => ['GET', 'HEAD'],
'cache_listeners' => [],
],
'cache_pool' => 'my_custom_cache_pull',
'enabled' => true,
'stream_factory' => 'httplug.stream_factory',
],
],
],
],
];
$this->assertProcessedConfigurationEquals($config, [$file]);
}
}

0 comments on commit 0e5533d

Please sign in to comment.