Skip to content

Commit

Permalink
Remove data-collector when no twig is present (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed May 4, 2023
2 parents cb420d8 + 6d2cfd0 commit d17ccbe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/DependencyInjection/WouterJEloquentExtension.php
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Reference;
use Illuminate\Database\Events\QueryExecuted;
use Twig\Extension\AbstractExtension;

/**
* @final
Expand Down Expand Up @@ -45,6 +46,10 @@ public function load(array $configs, ContainerBuilder $container): void

protected function loadDataCollector(ContainerBuilder $container, Loader\XmlFileLoader $loader): void
{
if (!class_exists(\Twig_Environment::class) && !class_exists(AbstractExtension::class)) {
return;
}

$loader->load('data_collector.xml');

$container->getDefinition('wouterj_eloquent.events')
Expand Down
25 changes: 25 additions & 0 deletions tests/Functional/DataCollectorTest.php
@@ -0,0 +1,25 @@
<?php

namespace WouterJ\EloquentBundle\Functional;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class DataCollectorTest extends KernelTestCase
{
protected static function getKernelClass(): string
{
return 'TestKernel';
}

public function testDataCollectorRegistered()
{
if (method_exists(__CLASS__, 'getContainer')) {
$container = self::getContainer();
} else {
static::bootKernel();
$container = self::$kernel->getContainer();
}

$this->assertArrayHasKey('wouterj_eloquent.data_collector', array_merge($container->getServiceIds(), $container->getRemovedIds()));
}
}

0 comments on commit d17ccbe

Please sign in to comment.