/** * {@inheritdoc} */ public function setUp() { $this->connection = new MysqlPersistentConnection(); $params = $this->connection->getConnectionParams(); $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/Entity'], true, null, null, false); $this->em = EntityManager::create($params, $config); // create tables in the database $metadata = $this->em->getMetadataFactory()->getAllMetadata(); $schema_tool = new SchemaTool($this->em); $schema_tool->createSchema($metadata); $this->provider = new EntityMutationMetadataProvider(new AnnotationReader()); }
/** * @depends testConstruction */ public function testDestruction() { $connection = new MysqlPersistentConnection(); $params = $connection->getConnectionParams(); new MysqlPersistentConnection(); // Immediately out of scope. $tmp = new MysqlPersistentConnection(); // Still in scope because of variable. // No race here because we give the db time to cleanup by adding the $tmp // connection and we wait for it to be established. // // Having two databases now ensures that multiple databases with // unique names are created by the connection class. $this->assertEquals(2, count($this->listDatabases($params))); // If a connection disappears, it should clean up it's databases. unset($tmp); $this->assertEquals(1, count($this->listDatabases($params))); }
public static function setUpBeforeClass() { self::$connection = new MysqlPersistentConnection(); $params = self::$connection->getConnectionParams(); $configuration = Setup::createConfiguration(true); $event_manager = new EventManager(); $annotation_reader = new AnnotationReader(); $configuration->setMetadataDriverImpl(new AnnotationDriver($annotation_reader, [__DIR__ . '/Entity'])); $annotation_metadata_provider = new EntityAnnotationMetadataProvider($annotation_reader); $mutation_metadata_provider = new EntityMutationMetadataProvider($annotation_reader); $entity_changed_listener = new EntityChangedListener($annotation_metadata_provider, $mutation_metadata_provider); $mutation_resolver = new MutationResolver($annotation_metadata_provider); $mutation_listener = new MutationListener($mutation_resolver); $event_manager->addEventListener('prePersist', $entity_changed_listener); $event_manager->addEventListener('preFlush', $entity_changed_listener); $event_manager->addEventListener('entityChanged', $mutation_listener); self::$entity_manager = EntityManager::create($params, $configuration, $event_manager); $metadata = self::$entity_manager->getMetadataFactory()->getAllMetadata(); $schema_tool = new SchemaTool(self::$entity_manager); $schema_tool->createSchema($metadata); }