浏览代码

[tests] yaml mapping tests for loggable extension

Gediminas Morkevicius 14 年之前
父节点
当前提交
d6d08496a6

+ 2 - 0
tests/Gedmo/Mapping/Driver/Yaml/Mapping.Fixture.Yaml.Category.dcm.yml

@@ -13,6 +13,8 @@ Mapping\Fixture\Yaml\Category:
       locale: localeField
     tree:
       type: nested
+    loggable:
+      logEntryClass: Gedmo\Loggable\Entity\LogEntry
   fields:
     title:
       type: string

+ 61 - 0
tests/Gedmo/Mapping/LoggableMappingTest.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace Gedmo\Loggable;
+
+use Doctrine\Common\Util\Debug,
+    Doctrine\ORM\Mapping\Driver\YamlDriver,
+    Doctrine\ORM\Mapping\Driver\DriverChain,
+    Mapping\Fixture\Yaml\Category,
+    Gedmo\Mapping\ExtensionMetadataFactory;
+
+/**
+ * These are mapping tests for tree extension
+ * 
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @package Gedmo.Mapping
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+class TreeMappingTest extends \PHPUnit_Framework_TestCase
+{
+    const YAML_CATEGORY = 'Mapping\Fixture\Yaml\Category';
+    private $em;
+
+    public function setUp()
+    {        
+        $config = new \Doctrine\ORM\Configuration();
+        $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
+        $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
+        $config->setProxyDir(__DIR__ . '/Proxy');
+        $config->setProxyNamespace('Gedmo\Mapping\Proxy');
+        $chainDriverImpl = new DriverChain;
+        $chainDriverImpl->addDriver(
+            new YamlDriver(array(__DIR__ . '/Driver/Yaml')), 
+            'Mapping\Fixture\Yaml'
+        );
+        $config->setMetadataDriverImpl($chainDriverImpl);
+
+        $conn = array(
+            'driver' => 'pdo_sqlite',
+            'memory' => true,
+        );
+
+        //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
+        
+        $evm = new \Doctrine\Common\EventManager();
+        $evm->addEventSubscriber(new LoggableListener());
+        $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
+    }
+    
+    public function testLoggableMapping()
+    {
+        $meta = $this->em->getClassMetadata(self::YAML_CATEGORY);
+        $cacheId = ExtensionMetadataFactory::getCacheId(self::YAML_CATEGORY, 'Gedmo\Loggable');
+        $config = $this->em->getMetadataFactory()->getCacheDriver()->fetch($cacheId);
+        
+        $this->assertArrayHasKey('loggable', $config);
+        $this->assertEquals(true, $config['loggable']);
+        $this->assertArrayHasKey('logEntryClass', $config);
+        $this->assertEquals('Gedmo\\Loggable\\Entity\\LogEntry', $config['logEntryClass']);
+    }
+}