Skip to content

Commit

Permalink
Bit better configuration + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prgTW committed Jan 31, 2024
1 parent 77ed411 commit 8c183be
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 2 deletions.
23 changes: 21 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,24 @@ private function appendAnalyticsSection(ArrayNodeDefinition $rootNode): void
->arrayNode('analytics')
->addDefaultsIfNotSet()
->children()
->variableNode('trackers')
->arrayNode('dashboard')
->addDefaultsIfNotSet()
->children()
->scalarNode('api_key')->end()
->scalarNode('client_id')->end()
->scalarNode('table_id')->end()
->end()
->end()
->arrayNode('whitelist')
->ignoreExtraKeys(false)
->addDefaultsIfNotSet()
->end()
->scalarNode('js_source_https')->defaultValue('https://')->end()
->scalarNode('js_source_http')->defaultValue('http://')->end()
->scalarNode('js_source_endpoint')->defaultValue('stats.g.doubleclick.net/dc.js')->end()
->arrayNode('trackers')
->ignoreExtraKeys(false)
->addDefaultsIfNotSet()
->end()
->end()
->end()
Expand All @@ -67,7 +84,9 @@ private function appendMapsSection(ArrayNodeDefinition $rootNode): void
->arrayNode('maps')
->addDefaultsIfNotSet()
->children()
->variableNode('config')
->arrayNode('config')
->ignoreExtraKeys(false)
->addDefaultsIfNotSet()
->end()
->end()
->end()
Expand Down
178 changes: 178 additions & 0 deletions Tests/Configuration/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?php

declare(strict_types=1);

namespace AntiMattr\GoogleBundle\Tests\Configuration;

use AntiMattr\GoogleBundle\DependencyInjection\Configuration;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Processor;

class ConfigurationTest extends TestCase
{
/**
* @dataProvider provideConfigs
*/
public function testEmptyConfig(array $configs, array $expectedConfig): void
{
$computedConfig = (new Processor())->processConfiguration(new Configuration, $configs);
self::assertEquals($expectedConfig, $computedConfig);
}

public function provideConfigs(): iterable
{
yield 'empty' => [
[],
[
'adwords' => [
'conversions' => [],
],
'analytics' => [
'dashboard' => [],
'whitelist' => [],
'js_source_https' => 'https://',
'js_source_http' => 'http://',
'js_source_endpoint' => 'stats.g.doubleclick.net/dc.js',
'trackers' => [],
],
'maps' => [
'config' => [],
],
],
];

yield 'adwords_null' => [
[
[
'adwords' => null,
],
],
[
'adwords' => [
'conversions' => [],
],
'analytics' => [
'dashboard' => [],
'whitelist' => [],
'js_source_https' => 'https://',
'js_source_http' => 'http://',
'js_source_endpoint' => 'stats.g.doubleclick.net/dc.js',
'trackers' => [],
],
'maps' => [
'config' => [],
],
],
];

yield 'adwords_conversions_null' => [
[
[
'adwords' => [
'conversions' => null,
],
],
],
[
'adwords' => [
'conversions' => [],
],
'analytics' => [
'dashboard' => [],
'whitelist' => [],
'js_source_https' => 'https://',
'js_source_http' => 'http://',
'js_source_endpoint' => 'stats.g.doubleclick.net/dc.js',
'trackers' => [],
],
'maps' => [
'config' => [],
],
],
];

yield 'adwords' => [
[
[
'adwords' => [
'conversions' => [
'foo' => [
'id' => 'foo',
'format' => 'xml',
],
],
],
],
[
'adwords' => [
'conversions' => [
'bar' => [
'id' => 'bar',
'language' => 'pl',
],
],
],
],
],
[
'adwords' => [
'conversions' => [
'foo' => [
'id' => 'foo',
'label' => null,
'value' => null,
'format' => 'xml',
'color' => null,
'language' => null,
],
'bar' => [
'id' => 'bar',
'label' => null,
'value' => null,
'format' => null,
'color' => null,
'language' => 'pl',
],
],
],
'analytics' => [
'dashboard' => [],
'whitelist' => [],
'js_source_https' => 'https://',
'js_source_http' => 'http://',
'js_source_endpoint' => 'stats.g.doubleclick.net/dc.js',
'trackers' => [],
],
'maps' => [
'config' => [],
],
],
];

yield 'analytics_trackers_null' => [
[
[
'analytics' => [
'trackers' => null,
],
],
],
[
'adwords' => [
'conversions' => [],
],
'analytics' => [
'dashboard' => [],
'whitelist' => [],
'js_source_https' => 'https://',
'js_source_http' => 'http://',
'js_source_endpoint' => 'stats.g.doubleclick.net/dc.js',
'trackers' => [],
],
'maps' => [
'config' => [],
],
],
];
}
}

0 comments on commit 8c183be

Please sign in to comment.