public function setUp() { $reader = new \Doctrine\Common\Annotations\AnnotationReader(); $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader); $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setProxyDir(sys_get_temp_dir()); $config->setProxyNamespace('SimpleThings\\EntityAudit\\Tests\\Proxies'); $config->setMetadataDriverImpl($driver); $conn = array('driver' => $GLOBALS['DOCTRINE_DRIVER'], 'memory' => $GLOBALS['DOCTRINE_MEMORY'], 'dbname' => $GLOBALS['DOCTRINE_DATABASE'], 'user' => $GLOBALS['DOCTRINE_USER'], 'password' => $GLOBALS['DOCTRINE_PASSWORD'], 'host' => $GLOBALS['DOCTRINE_HOST']); $auditConfig = new AuditConfiguration(); $auditConfig->setCurrentUsername("beberlei"); $auditConfig->setAuditedEntityClasses($this->auditedEntities); $auditConfig->setGlobalIgnoreColumns(array('ignoreme')); $this->auditManager = new AuditManager($auditConfig); $this->auditManager->registerEvents($evm = new EventManager()); if (php_sapi_name() == 'cli' && isset($_SERVER['argv']) && (in_array('-v', $_SERVER['argv']) || in_array('--verbose', $_SERVER['argv']))) { $config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); } $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $em = $this->em; try { $schemaTool->createSchema(array_map(function ($value) use($em) { return $em->getClassMetadata($value); }, $this->schemaEntities)); } catch (\Exception $e) { if ($GLOBALS['DOCTRINE_DRIVER'] != 'pdo_mysql' || !($e instanceof \PDOException && strpos($e->getMessage(), 'Base table or view already exists') !== false)) { throw $e; } } }
public function testFindCurrentRevision() { $user = new UserAudit('Broncha'); $this->em->persist($user); $this->em->flush(); $user->setName("Rajesh"); $this->em->flush(); $reader = $this->auditManager->createAuditReader($this->em); $revision = $reader->getCurrentRevision(get_class($user), $user->getId()); $this->assertEquals(2, $revision); $user->setName("David"); $this->em->flush(); $revision = $reader->getCurrentRevision(get_class($user), $user->getId()); $this->assertEquals(3, $revision); }
public function testGlobalIgnoreColumns() { $user = new UserAudit("welante"); $article = new ArticleAudit("testcolumn", "yadda!", $user, 'text'); $this->em->persist($user); $this->em->persist($article); $this->em->flush(); $article->setText("testcolumn2"); $this->em->persist($article); $this->em->flush(); $reader = $this->auditManager->createAuditReader($this->em); $revision = $reader->getCurrentRevision(get_class($article), $article->getId()); $this->assertEquals(2, $revision); $article->setIgnoreme("textnew"); $this->em->persist($article); $this->em->flush(); $revision = $reader->getCurrentRevision(get_class($article), $article->getId()); $this->assertEquals(2, $revision); }
public function __construct(AuditManager $auditManager) { $this->config = $auditManager->getConfiguration(); $this->metadataFactory = $auditManager->getMetadataFactory(); }
/** * @return AuditManager */ protected function getAuditManager() { if (null !== $this->auditManager) { return $this->auditManager; } $auditConfig = AuditConfiguration::forEntities($this->auditedEntities); $auditConfig->setGlobalIgnoreColumns(array('ignoreme')); $auditConfig->setUsernameCallable(function () { return 'beberlei'; }); $auditManager = new AuditManager($auditConfig); $auditManager->registerEvents($this->_getConnection()->getEventManager()); return $this->auditManager = $auditManager; }