Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Testing, documenting and completing integration with zendframework/ze…

…nd-developer-tools - waiting for zendframework/ZendDeveloperTools#24
  • Loading branch information...
commit 161df3e4e3ba89907ce61b938c0230772949e0ad 1 parent 8a4c279
@Ocramius Ocramius authored
View
12 config/module.config.php
@@ -49,8 +49,14 @@
'eventmanager' => array(
'orm_default' => array()
),
+
+ 'sql_logger_collector' => array(
+ 'orm_default' => array(),
+ ),
),
+ // zendframework/zend-developer-tools specific settings
+
'view_manager' => array(
'template_map' => array(
'zend-developer-tools/toolbar/doctrine-orm' => __DIR__ . '/../view/zend-developer-tools/toolbar/doctrine-orm.phtml',
@@ -58,8 +64,10 @@
),
'zdt' => array(
- 'collectors' => array(
- 'orm_default' => 'doctrine.collector.orm_default',
+ 'profiler' => array(
+ 'collectors' => array(
+ 'orm_default' => 'doctrine.sql_logger_collector.orm_default',
+ ),
),
'toolbar' => array(
'entries' => array(
View
107 docs/developer-tools.md
@@ -0,0 +1,107 @@
+# Zend Developer Tools in DoctrineORMModule
+
+If you ever tried [Zend Developer Tools](https://github.com/zendframework/ZendDeveloperTools) you will surely understand
+the importance of being able to track performance pitfalls or excessive amount of queries in your applications when
+developing.
+
+## Setup
+
+To setup [Zend Developer Tools](https://github.com/zendframework/ZendDeveloperTools), run
+
+```sh
+php composer.phar require zendframework/zend-developer-tools dev-master
+```
+
+Then enable `ZendDeveloperTools` in your modules and enable profiling and the toolbar (see docs of Zend Developer Tools
+for that).
+
+Once `ZendDeveloperTools` is enabled, having `doctrine.entity_manager.orm_default` as your default `EntityManager`, you
+will notice that the queries performed by the ORM get logged and displayed in the toolbar.
+
+![](http://github.com/doctrine/DoctrineModule/raw/master/docs/images/zf2-zend-developer-tools-doctrine-module.png)
+
+## Customization
+
+If you want to customize this behavior (or track multiple `EntityManager` instances) you can do it in different ways.
+Please note that if you have set an `SQLLogger` in your configuration, this functionality won't override it, so you can
+use these features in total safety.
+
+### Multiple EntityManager/Connection instances and logging
+
+*WARNING! These are advanced features! Even if the code is fully tested, this is usually not required for most users!*
+
+To setup logging for an additional DBAL Connection or EntityManager, put something like following in your module:
+
+```php
+<?php
+
+namespace MyNamespace;
+
+class Module
+{
+ public function getConfig()
+ {
+ return array(
+ 'doctrine' => array(
+ 'sql_logger_collector' => array(
+ 'other_orm' => array(
+ // name of the sql logger collector (used by ZDT)
+ 'name' => 'other_orm',
+
+ // name of the configuration service at which to attach the logger
+ 'configuration' => 'doctrine.configuration.other_orm',
+
+ // uncomment following if you want to use a particular SQL logger instead of relying on
+ // the attached one
+ //'sql_logger' => 'service_name_of_my_dbal_sql_logger',
+ ),
+ ),
+ ),
+
+ 'zdt' => array(
+
+ // registering the profiler with ZDT
+ 'profiler' => array(
+ 'collectors' => array(
+ // reference to the service we have defined
+ 'other_orm' => 'doctrine.sql_logger_collector.other_orm',
+ ),
+ ),
+
+ // registering a new toolbar item with ZDT (name must be the same of the collector name)
+ 'toolbar' => array(
+ 'entries' => array(
+ // this is actually a name of a view script to use - you can use your custom one
+ 'other_orm' => 'zend-developer-tools/toolbar/doctrine-orm',
+ ),
+ ),
+ ),
+ );
+ }
+
+ public function getServiceConfiguration()
+ {
+ return array(
+ 'factories' => array(
+ // defining a service (any name is valid as long as you use it consistently across this example)
+ 'doctrine.sql_logger_collector.other_orm' => new \DoctrineORMModule\Service\SQLLoggerCollectorFactory('other_orm'),
+ ),
+ );
+ }
+
+ public function onBootstrap(\Zend\EventManager\EventInterface $e)
+ {
+ $config = $e->getTarget()->getServiceManager()->get('Config');
+
+ if (isset($config['zdt']['profiler']['enabled']) && $config['zdt']['profiler']['enabled']) {
+ // when ZDT is enabled, initialize the sql collector
+ $app->getServiceManager()->get('doctrine.sql_logger_collector.other_orm');
+ }
+ }
+}
+```
+
+This example will simply generate a new icon in the toolbar, with the log results of your `other_orm` connection:
+
+
+![](http://github.com/doctrine/DoctrineModule/raw/master/docs/images/zend-developer-tools-multiple-entity-managers.png)
View
BIN  docs/images/zend-developer-tools-multiple-entity-managers.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  docs/images/zf2-zend-developer-tools-doctrine-module.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
43 src/DoctrineORMModule/Module.php
@@ -28,13 +28,9 @@
use DoctrineORMModule\Service\ConfigurationFactory as ORMConfigurationFactory;
use DoctrineORMModule\Service\EntityManagerFactory;
use DoctrineORMModule\Service\DBALConnectionFactory;
+use DoctrineORMModule\Service\SQLLoggerCollectorFactory;
use DoctrineORMModule\Form\Annotation\AnnotationBuilder;
-// @todo move to own factory to allow wrapping of controllers
-use DoctrineORMModule\Collector\SQLLoggerCollector;
-use Doctrine\DBAL\Logging\DebugStack;
-use Doctrine\DBAL\Logging\LoggerChain;
-
use Zend\ModuleManager\ModuleManagerInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
@@ -104,6 +100,12 @@ public function onBootstrap(EventInterface $e)
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($em), 'em');
});
+
+ $config = $app->getServiceManager()->get('Config');
+
+ if (isset($config['zdt']['profiler']['enabled']) && $config['zdt']['profiler']['enabled']) {
+ $app->getServiceManager()->get('doctrine.sql_logger_collector.orm_default');
+ }
}
/**
@@ -124,32 +126,17 @@ public function getServiceConfig()
'Doctrine\ORM\EntityManager' => 'doctrine.entitymanager.orm_default',
),
'factories' => array(
+ 'doctrine.connection.orm_default' => new DBALConnectionFactory('orm_default'),
+ 'doctrine.configuration.orm_default' => new ORMConfigurationFactory('orm_default'),
+ 'doctrine.entitymanager.orm_default' => new EntityManagerFactory('orm_default'),
+
+ 'doctrine.driver.orm_default' => new DriverFactory('orm_default'),
+ 'doctrine.eventmanager.orm_default' => new EventManagerFactory('orm_default'),
+ 'doctrine.sql_logger_collector.orm_default' => new SQLLoggerCollectorFactory('orm_default'),
+
'DoctrineORMModule\Form\Annotation\AnnotationBuilder' => function(ServiceLocatorInterface $sl) {
return new AnnotationBuilder($sl->get('doctrine.entitymanager.orm_default'));
},
-
- 'doctrine.connection.orm_default' => new DBALConnectionFactory('orm_default'),
- 'doctrine.configuration.orm_default' => new ORMConfigurationFactory('orm_default'),
- 'doctrine.entitymanager.orm_default' => new EntityManagerFactory('orm_default'),
-
- 'doctrine.driver.orm_default' => new DriverFactory('orm_default'),
- 'doctrine.eventmanager.orm_default' => new EventManagerFactory('orm_default'),
- 'doctrine.collector.orm_default' => function(ServiceLocatorInterface $sl) {
- $debugStackLogger = new DebugStack();
- /* @var $configuration \Doctrine\ORM\Configuration */
- $configuration = $sl->get('doctrine.configuration.orm_default');
-
- if (null !== $configuration->getSQLLogger()) {
- $logger = new LoggerChain();
- $logger->addLogger($debugStackLogger);
- $logger->addLogger($configuration->getSQLLogger());
- $configuration->setSQLLogger($logger);
- } else {
- $configuration->setSQLLogger($debugStackLogger);
- }
-
- return new SQLLoggerCollector($debugStackLogger, 'orm_default');
- },
),
);
}
View
101 src/DoctrineORMModule/Options/SQLLoggerCollectorOptions.php
@@ -0,0 +1,101 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace DoctrineORMModule\Options;
+
+use Zend\Stdlib\AbstractOptions;
+
+/**
+ * Configuration options for an collector
+ *
+ * @license MIT
+ * @link http://www.doctrine-project.org/
+ * @author Marco Pivetta <ocramius@gmail.com>
+ */
+class SQLLoggerCollectorOptions extends AbstractOptions
+{
+ /**
+ * @var string name to be assigned to the collector
+ */
+ protected $name = 'orm_default';
+
+ /**
+ * @var string|null service name of the configuration where the logger has to be put
+ */
+ protected $configuration;
+
+ /**
+ * @var string|null service name of the SQLLogger to be used
+ */
+ protected $sqlLogger;
+
+ /**
+ * @param string $configuration
+ */
+ public function setName($name)
+ {
+ $this->name = (string) $name;
+ }
+
+ /**
+ * Name of the collector
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * @param string|null $configuration
+ */
+ public function setConfiguration($configuration)
+ {
+ $this->configuration = $configuration ? (string) $configuration : null;
+ }
+
+ /**
+ * Configuration service name (where to set the logger)
+ *
+ * @return string
+ */
+ public function getConfiguration()
+ {
+ return $this->configuration ? $this->configuration : 'doctrine.configuration.orm_default';
+ }
+
+ /**
+ * @param string|null $logger
+ */
+ public function setSqlLogger($sqlLogger)
+ {
+ $this->sqlLogger = $sqlLogger ? (string) $sqlLogger : null;
+ }
+
+ /**
+ * SQLLogger service name
+ *
+ * @return string|null
+ */
+ public function getSqlLogger()
+ {
+ return $this->sqlLogger;
+ }
+}
View
116 src/DoctrineORMModule/Service/SQLLoggerCollectorFactory.php
@@ -0,0 +1,116 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace DoctrineORMModule\Service;
+
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+
+use RuntimeException;
+
+use DoctrineORMModule\Collector\SQLLoggerCollector;
+
+use Doctrine\DBAL\Logging\DebugStack;
+use Doctrine\DBAL\Logging\LoggerChain;
+
+/**
+ * DBAL Configuration ServiceManager factory
+ *
+ * @license MIT
+ * @link http://www.doctrine-project.org/
+ * @author Marco Pivetta <ocramius@gmail.com>
+ */
+class SQLLoggerCollectorFactory implements FactoryInterface
+{
+ /**
+ * @var string
+ */
+ protected $name;
+
+ /**
+ * @param $name
+ */
+ public function __construct($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ /** @var $options \DoctrineORMModule\Options\SQLLoggerCollectorOptions */
+ $options = $this->getOptions($serviceLocator);
+
+ // @todo always ask the serviceLocator instead? (add a factory?)
+ if ($options->getSqlLogger()) {
+ $debugStackLogger = $serviceLocator->get($options->getSqlLogger());
+ } else {
+ $debugStackLogger = new DebugStack();
+ }
+
+ /* @var $configuration \Doctrine\ORM\Configuration */
+ $configuration = $serviceLocator->get($options->getConfiguration());
+
+ if (null !== $configuration->getSQLLogger()) {
+ $logger = new LoggerChain();
+ $logger->addLogger($debugStackLogger);
+ $logger->addLogger($configuration->getSQLLogger());
+ $configuration->setSQLLogger($logger);
+ } else {
+ $configuration->setSQLLogger($debugStackLogger);
+ }
+
+ return new SQLLoggerCollector($debugStackLogger, $options->getName());
+ }
+
+ /**
+ * @param ServiceLocatorInterface $serviceLocator
+ * @return mixed
+ * @throws RuntimeException
+ */
+ protected function getOptions(ServiceLocatorInterface $serviceLocator)
+ {
+ $options = $serviceLocator->get('Config');
+ $options = $options['doctrine'];
+ $options = isset($options['sql_logger_collector'][$this->name])
+ ? $options['sql_logger_collector'][$this->name]
+ : null;
+
+ if (null === $options) {
+ throw new RuntimeException(sprintf(
+ 'Configuration with name "%s" could not be found in "doctrine.sql_logger_collector".',
+ $this->name
+ ));
+ }
+
+ $optionsClass = $this->getOptionsClass();
+
+ return new $optionsClass($options);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected function getOptionsClass()
+ {
+ return 'DoctrineORMModule\Options\SQLLoggerCollectorOptions';
+ }
+}
View
2  tests/DoctrineORMModuleTest/Collector/SQLLoggerCollectorTest.php
@@ -17,7 +17,7 @@
* <http://www.doctrine-project.org>.
*/
-namespace DoctrineORMModuleTest\Paginator;
+namespace DoctrineORMModuleTest\Collector;
use PHPUnit_Framework_TestCase as TestCase;
use DoctrineORMModule\Collector\SQLLoggerCollector;
View
55 tests/DoctrineORMModuleTest/Options/SQLLoggerCollectorOptionsTest.php
@@ -0,0 +1,55 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace DoctrineORMModuleTest\Collector;
+
+use PHPUnit_Framework_TestCase as TestCase;
+use DoctrineORMModule\Options\SQLLoggerCollectorOptions;
+
+
+class SQLLoggerCollectorOptionsTest extends TestCase
+{
+ public function testSetGetSQLLogger()
+ {
+ $options = new SQLLoggerCollectorOptions();
+ $options->setSqlLogger('sql-logger-name');
+ $this->assertSame('sql-logger-name', $options->getSqlLogger());
+ $options->setSqlLogger(null);
+ $this->assertSame(null, $options->getSqlLogger());
+ }
+
+ public function testSetGetConfiguration()
+ {
+ $options = new SQLLoggerCollectorOptions();
+ $options->setConfiguration('configuration-name');
+ $this->assertSame('configuration-name', $options->getConfiguration());
+ $options->setConfiguration(null);
+ $this->assertSame('doctrine.configuration.orm_default', $options->getConfiguration());
+ }
+
+ public function testSetGetName()
+ {
+ $options = new SQLLoggerCollectorOptions();
+ $this->assertSame('orm_default', $options->getName()); // testing defaults too!
+ $options->setName('collector-name');
+ $this->assertSame('collector-name', $options->getName());
+ $options->setName(null);
+ $this->assertSame('', $options->getName());
+ }
+}
View
167 tests/DoctrineORMModuleTest/Service/SQLLoggerCollectorFactoryTest.php
@@ -0,0 +1,167 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace DoctrineORMModuleTest\Service;
+
+use PHPUnit_Framework_TestCase as TestCase;
+use DoctrineORMModule\Service\SQLLoggerCollectorFactory;
+use Doctrine\DBAL\Logging\DebugStack;
+use Doctrine\ORM\Configuration as ORMConfiguration;
+use Zend\ServiceManager\ServiceManager;
+
+
+class SQLLoggerCollectorFactoryTest extends TestCase
+{
+ /**
+ * @var ServiceManager
+ */
+ protected $services;
+
+ /**
+ * @var SQLLoggerCollectorFactory
+ */
+ protected $factory;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp()
+ {
+ parent::setUp();
+ $this->services = new ServiceManager();
+ $this->factory = new SQLLoggerCollectorFactory('orm_default');
+ }
+
+ public function testCreateSQLLoggerCollector()
+ {
+ $configuration = new ORMConfiguration();
+ $this->services->setService('doctrine.configuration.orm_default', $configuration);
+ $this->services->setService(
+ 'Config',
+ array(
+ 'doctrine' => array(
+ 'sql_logger_collector' => array(
+ 'orm_default' => array(),
+ ),
+ ),
+ )
+ );
+ $service = $this->factory->createService($this->services);
+ $this->assertInstanceOf('DoctrineORMModule\Collector\SQLLoggerCollector', $service);
+ $this->assertInstanceOf('Doctrine\DBAL\Logging\SQLLogger', $configuration->getSQLLogger());
+ }
+
+ public function testCreateSQLLoggerWithCustomConfiguration()
+ {
+ $configuration = new ORMConfiguration();
+ $this->services->setService('configuration_service_id', $configuration);
+ $this->services->setService(
+ 'Config',
+ array(
+ 'doctrine' => array(
+ 'sql_logger_collector' => array(
+ 'orm_default' => array(
+ 'configuration' => 'configuration_service_id',
+ ),
+ ),
+ ),
+ )
+ );
+ $this->factory->createService($this->services);
+ $this->assertInstanceOf('Doctrine\DBAL\Logging\SQLLogger', $configuration->getSQLLogger());
+ }
+
+ public function testCreateSQLLoggerWithPreviousExistingLoggerChainsLoggers()
+ {
+ $originalLogger = $this->getMock('Doctrine\DBAL\Logging\SQLLogger');
+ $originalLogger
+ ->expects($this->once())
+ ->method('startQuery')
+ ->with($this->equalTo('test query'));
+ $injectedLogger = $this->getMock('Doctrine\DBAL\Logging\DebugStack');
+ $injectedLogger
+ ->expects($this->once())
+ ->method('startQuery')
+ ->with($this->equalTo('test query'));
+
+
+ $configuration = new ORMConfiguration();
+ $configuration->setSQLLogger($originalLogger);
+ $this->services->setService('doctrine.configuration.orm_default', $configuration);
+ $this->services->setService('custom_logger', $injectedLogger);
+ $this->services->setService(
+ 'Config',
+ array(
+ 'doctrine' => array(
+ 'sql_logger_collector' => array(
+ 'orm_default' => array(
+ 'sql_logger' => 'custom_logger',
+ ),
+ ),
+ ),
+ )
+ );
+ $this->factory->createService($this->services);
+ /* @var $logger \Doctrine\DBAL\Logging\SQLLogger */
+ $logger = $configuration->getSQLLogger();
+ $logger->startQuery('test query');
+ }
+
+ public function testCreateSQLLoggerWithCustomLogger()
+ {
+ $configuration = new ORMConfiguration();
+ $logger = new DebugStack();
+ $this->services->setService('doctrine.configuration.orm_default', $configuration);
+ $this->services->setService('logger_service_id', $logger);
+ $this->services->setService(
+ 'Config',
+ array(
+ 'doctrine' => array(
+ 'sql_logger_collector' => array(
+ 'orm_default' => array(
+ 'sql_logger' => 'logger_service_id',
+ ),
+ ),
+ ),
+ )
+ );
+ $this->factory->createService($this->services);
+ $this->assertSame($logger, $configuration->getSQLLogger());
+ }
+
+ public function testCreateSQLLoggerWithCustomName()
+ {
+ $this->services->setService('doctrine.configuration.orm_default', new ORMConfiguration());
+ $this->services->setService(
+ 'Config',
+ array(
+ 'doctrine' => array(
+ 'sql_logger_collector' => array(
+ 'orm_default' => array(
+ 'name' => 'test_collector_name',
+ ),
+ ),
+ ),
+ )
+ );
+ /* @var $service \DoctrineORMModule\Collector\SQLLoggerCollector */
+ $service = $this->factory->createService($this->services);
+ $this->assertSame('test_collector_name', $service->getName());
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.