Skip to content

Rename toolbar config to profiling #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
### Deprecated

- `auto` value in `toolbar.enabled` config
- `toolbar` config, use `profiling` instead


## 1.2.2 - 2016-07-19
Expand Down
36 changes: 28 additions & 8 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ public function getConfigTreeBuilder()
return $v;
})
->end()
->beforeNormalization()
->ifTrue(function ($v) {
return is_array($v) && array_key_exists('toolbar', $v) && is_array($v['toolbar']);
})
->then(function ($v) {
if (array_key_exists('profiling', $v)) {
throw new InvalidConfigurationException('Can\'t configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling".');
}

@trigger_error('"httplug.toolbar" config is deprecated since version 1.3 and will be removed in 2.0. Use "httplug.profiling" instead.', E_USER_DEPRECATED);

if (array_key_exists('enabled', $v['toolbar']) && 'auto' === $v['toolbar']['enabled']) {
@trigger_error('"auto" value in "httplug.toolbar" config is deprecated since version 1.3 and will be removed in 2.0. Use a boolean value instead.', E_USER_DEPRECATED);
$v['toolbar']['enabled'] = $this->debug;
}

$v['profiling'] = $v['toolbar'];

unset($v['toolbar']);

return $v;
})
->end()
->children()
->arrayNode('main_alias')
->addDefaultsIfNotSet()
Expand All @@ -90,17 +113,14 @@ public function getConfigTreeBuilder()
->scalarNode('stream_factory')->defaultNull()->end()
->end()
->end()
->arrayNode('toolbar')
->arrayNode('profiling')
->addDefaultsIfNotSet()
->treatFalseLike(['enabled' => false])
->treatTrueLike(['enabled' => true])
->treatNullLike(['enabled' => $this->debug])
->info('Extend the debug profiler with information about requests.')
->children()
->booleanNode('enabled') // @deprecated value auto in 1.3.0
->beforeNormalization()
->ifString()
->then(function ($v) {
return 'auto' === $v ? $this->debug : $v;
})
->end()
->booleanNode('enabled')
->info('Turn the toolbar on or off. Defaults to kernel debug mode.')
->defaultValue($this->debug)
->end()
Expand Down
14 changes: 7 additions & 7 deletions DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ public function load(array $configs, ContainerBuilder $container)
}

// Configure toolbar
if ($config['toolbar']['enabled']) {
if ($config['profiling']['enabled']) {
$loader->load('data-collector.xml');

if (!empty($config['toolbar']['formatter'])) {
if (!empty($config['profiling']['formatter'])) {
// Add custom formatter
$container
->getDefinition('httplug.collector.debug_collector')
->replaceArgument(0, new Reference($config['toolbar']['formatter']))
->replaceArgument(0, new Reference($config['profiling']['formatter']))
;
}

$container
->getDefinition('httplug.formatter.full_http_message')
->addArgument($config['toolbar']['captured_body_length'])
->addArgument($config['profiling']['captured_body_length'])
;
}

Expand All @@ -91,7 +91,7 @@ private function configureClients(ContainerBuilder $container, array $config)
$first = $name;
}

$this->configureClient($container, $name, $arguments, $config['toolbar']['enabled']);
$this->configureClient($container, $name, $arguments, $config['profiling']['enabled']);
}

// If we have clients configured
Expand Down Expand Up @@ -294,7 +294,7 @@ private function configureAutoDiscoveryClients(ContainerBuilder $container, arra
$container,
'auto_discovered_client',
[HttpClientDiscovery::class, 'find'],
$config['toolbar']['enabled']
$config['profiling']['enabled']
);
}

Expand All @@ -309,7 +309,7 @@ private function configureAutoDiscoveryClients(ContainerBuilder $container, arra
$container,
'auto_discovered_async',
[HttpAsyncClientDiscovery::class, 'find'],
$config['toolbar']['enabled']
$config['profiling']['enabled']
);
}

Expand Down
4 changes: 4 additions & 0 deletions Tests/Resources/Fixtures/config/bc/profiling_toolbar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
httplug:
profiling: ~
toolbar:
enabled: auto
5 changes: 5 additions & 0 deletions Tests/Resources/Fixtures/config/bc/toolbar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
httplug:
toolbar:
enabled: true
formatter: null
captured_body_length: 0
2 changes: 1 addition & 1 deletion Tests/Resources/Fixtures/config/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'uri_factory' => 'Http\Message\UriFactory\GuzzleUriFactory',
'stream_factory' => 'Http\Message\StreamFactory\GuzzleStreamFactory',
],
'toolbar' => [
'profiling' => [
'enabled' => true,
'formatter' => 'my_toolbar_formatter',
'captured_body_length' => 0,
Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources/Fixtures/config/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<uri-factory>Http\Message\UriFactory\GuzzleUriFactory</uri-factory>
<stream-factory>Http\Message\StreamFactory\GuzzleStreamFactory</stream-factory>
</classes>
<toolbar enabled="true" formatter="my_toolbar_formatter" captured_body_length="0"/>
<profiling enabled="true" formatter="my_toolbar_formatter" captured_body_length="0"/>
<plugins>
<authentication>
<my_basic type="basic" username="foo" password="bar"/>
Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources/Fixtures/config/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ httplug:
message_factory: Http\Message\MessageFactory\GuzzleMessageFactory
uri_factory: Http\Message\UriFactory\GuzzleUriFactory
stream_factory: Http\Message\StreamFactory\GuzzleStreamFactory
toolbar:
profiling:
enabled: true
formatter: my_toolbar_formatter
captured_body_length: 0
Expand Down
159 changes: 90 additions & 69 deletions Tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,69 @@
*/
class ConfigurationTest extends AbstractExtensionConfigurationTestCase
{
private $debug = true;
private $emptyConfig = [
'main_alias' => [
'client' => 'httplug.client.default',
'message_factory' => 'httplug.message_factory.default',
'uri_factory' => 'httplug.uri_factory.default',
'stream_factory' => 'httplug.stream_factory.default',
],
'classes' => [
'client' => null,
'message_factory' => null,
'uri_factory' => null,
'stream_factory' => null,
],
'clients' => [],
'profiling' => [
'enabled' => true,
'formatter' => null,
'captured_body_length' => 0,
],
'plugins' => [
'authentication' => [],
'cache' => [
'enabled' => false,
'stream_factory' => 'httplug.stream_factory',
'config' => [
'default_ttl' => null,
'respect_cache_headers' => true,
],
],
'cookie' => [
'enabled' => false,
],
'decoder' => [
'enabled' => true,
'use_content_encoding' => true,
],
'history' => [
'enabled' => false,
],
'logger' => [
'enabled' => true,
'logger' => 'logger',
'formatter' => null,
],
'redirect' => [
'enabled' => true,
'preserve_header' => true,
'use_default_for_multiple' => true,
],
'retry' => [
'enabled' => true,
'retry' => 1,
],
'stopwatch' => [
'enabled' => true,
'stopwatch' => 'debug.stopwatch',
],
],
'discovery' => [
'client' => 'auto',
'async_client' => null,
],
];

protected function getContainerExtension()
{
Expand All @@ -20,86 +82,21 @@ protected function getContainerExtension()

protected function getConfiguration()
{
return new Configuration($this->debug);
return new Configuration(true);
}

public function testEmptyConfiguration()
{
$expectedConfiguration = [
'main_alias' => [
'client' => 'httplug.client.default',
'message_factory' => 'httplug.message_factory.default',
'uri_factory' => 'httplug.uri_factory.default',
'stream_factory' => 'httplug.stream_factory.default',
],
'classes' => [
'client' => null,
'message_factory' => null,
'uri_factory' => null,
'stream_factory' => null,
],
'clients' => [],
'toolbar' => [
'enabled' => true,
'formatter' => null,
'captured_body_length' => 0,
],
'plugins' => [
'authentication' => [],
'cache' => [
'enabled' => false,
'stream_factory' => 'httplug.stream_factory',
'config' => [
'default_ttl' => null,
'respect_cache_headers' => true,
],
],
'cookie' => [
'enabled' => false,
],
'decoder' => [
'enabled' => true,
'use_content_encoding' => true,
],
'history' => [
'enabled' => false,
],
'logger' => [
'enabled' => true,
'logger' => 'logger',
'formatter' => null,
],
'redirect' => [
'enabled' => true,
'preserve_header' => true,
'use_default_for_multiple' => true,
],
'retry' => [
'enabled' => true,
'retry' => 1,
],
'stopwatch' => [
'enabled' => true,
'stopwatch' => 'debug.stopwatch',
],
],
'discovery' => [
'client' => 'auto',
'async_client' => null,
],
];

$formats = array_map(function ($path) {
return __DIR__.'/../../Resources/Fixtures/'.$path;
}, [
'config/empty.yml',
'config/empty.xml',
'config/empty.php',
'config/toolbar_auto.yml',
]);

foreach ($formats as $format) {
$this->assertProcessedConfigurationEquals($expectedConfiguration, [$format]);
$this->assertProcessedConfigurationEquals($this->emptyConfig, [$format]);
}
}

Expand All @@ -119,7 +116,7 @@ public function testSupportsAllConfigFormats()
'stream_factory' => 'Http\Message\StreamFactory\GuzzleStreamFactory',
],
'clients' => [],
'toolbar' => [
'profiling' => [
'enabled' => true,
'formatter' => 'my_toolbar_formatter',
'captured_body_length' => 0,
Expand Down Expand Up @@ -223,4 +220,28 @@ public function testInvalidAuthentication()
$file = __DIR__.'/../../Resources/Fixtures/config/invalid_auth.yml';
$this->assertProcessedConfigurationEquals([], [$file]);
}

public function testBackwardCompatibility()
{
$formats = array_map(function ($path) {
return __DIR__.'/../../Resources/Fixtures//'.$path;
}, [
'config/bc/toolbar.yml',
'config/bc/toolbar_auto.yml',
]);

foreach ($formats as $format) {
$this->assertProcessedConfigurationEquals($this->emptyConfig, [$format]);
}
}

/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Can't configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling".
*/
public function testProfilingToolbarCollision()
{
$file = __DIR__.'/../../Resources/Fixtures/config/bc/profiling_toolbar.yml';
$this->assertProcessedConfigurationEquals([], [$file]);
}
}