Skip to content

Commit

Permalink
Merge pull request #1309 from bastnic/feature/feature-switch-SchemaVa…
Browse files Browse the repository at this point in the history
…lidator

Disable schema validation no matter the profiling configuration
  • Loading branch information
ostrolucky authored Mar 24, 2021
2 parents 155a870 + fa36d2d commit 70be9d4
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 3 deletions.
7 changes: 4 additions & 3 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder

unset($connection['logging']);

$dataCollectorDefinition = $container->getDefinition('data_collector.doctrine');
$dataCollectorDefinition->replaceArgument(1, $connection['profiling_collect_schema_errors']);

if ($connection['profiling']) {
$profilingAbstractId = $connection['profiling_collect_backtrace'] ?
'doctrine.dbal.logger.backtrace' :
Expand All @@ -164,9 +167,7 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder
$profilingLoggerId = $profilingAbstractId . '.' . $name;
$container->setDefinition($profilingLoggerId, new ChildDefinition($profilingAbstractId));
$profilingLogger = new Reference($profilingLoggerId);
$container->getDefinition('data_collector.doctrine')
->addMethodCall('addLogger', [$name, $profilingLogger])
->replaceArgument(1, $connection['profiling_collect_schema_errors']);
$dataCollectorDefinition->addMethodCall('addLogger', [$name, $profilingLogger]);

if ($logger !== null) {
$chainLogger = $container->register(
Expand Down
15 changes: 15 additions & 0 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,21 @@ public function testRepositoryFactory(): void
$this->assertDICDefinitionMethodCallOnce($definition, 'setRepositoryFactory', ['repository_factory']);
}

public function testDisableSchemaValidation(): void
{
$container = $this->loadContainer('dbal_collect_schema_errors_enable');
$collectorDefinition = $container->getDefinition('data_collector.doctrine');
$this->assertTrue($collectorDefinition->getArguments()[1]);

$container = $this->loadContainer('dbal_collect_schema_errors_disable');
$collectorDefinition = $container->getDefinition('data_collector.doctrine');
$this->assertFalse($collectorDefinition->getArguments()[1]);

$container = $this->loadContainer('dbal_collect_schema_errors_disable_no_profiling');
$collectorDefinition = $container->getDefinition('data_collector.doctrine');
$this->assertFalse($collectorDefinition->getArguments()[1]);
}

private function loadContainer(
string $fixture,
array $bundles = ['YamlBundle'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" ?>

<srv:container xmlns="http://symfony.com/schema/dic/doctrine"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">

<config>
<dbal default-connection="mysql">
<connection
name="profile_without_schema_validator"
logging="false"
profiling="true"
profiling-collect-schema-errors="false" />
</dbal>
</config>
</srv:container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" ?>

<srv:container xmlns="http://symfony.com/schema/dic/doctrine"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">

<config>
<dbal default-connection="mysql">
<connection
name="profile_without_schema_validator_no_profiling"
logging="false"
profiling="false"
profiling-collect-schema-errors="false" />
</dbal>
</config>
</srv:container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" ?>

<srv:container xmlns="http://symfony.com/schema/dic/doctrine"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">

<config>
<dbal default-connection="mysql">
<connection
name="profile_with_schema_validator"
logging="false"
profiling="true"
profiling-collect-schema-errors="true" />
</dbal>
</config>
</srv:container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
doctrine:
dbal:
default_connection: mysql
connections:
profile_without_schema_validator:
logging: false
profiling: true
profiling_collect_schema_errors: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
doctrine:
dbal:
default_connection: mysql
connections:
profile_without_schema_validator_no_profiling:
logging: false
profiling: false
profiling_collect_schema_errors: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
doctrine:
dbal:
default_connection: mysql
connections:
profile_with_schema_validator:
logging: false
profiling: true
profiling_collect_schema_errors: true

0 comments on commit 70be9d4

Please sign in to comment.