Example #1
0
 public function build($dsn = null, $user = null, $pass = null, $adapter = null)
 {
     if (null === $dsn) {
         $dsn = 'sqlite::memory:';
     }
     if (null === $adapter) {
         $adapter = new DBSQLite();
     }
     $con = new PropelPDO($dsn, $user, $pass);
     $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
     $this->buildSQL($con);
     $this->buildClasses();
     $name = $this->getDatabase()->getName();
     if (!Propel::isInit()) {
         Propel::setConfiguration(array());
     }
     Propel::setDB($name, $adapter);
     Propel::setConnection($name, $con, Propel::CONNECTION_READ);
     Propel::setConnection($name, $con, Propel::CONNECTION_WRITE);
     return $con;
 }
 /**
  * @return \PropelPDO
  */
 protected function getMockPropelConnection()
 {
     if (!class_exists('Lexik\\Bundle\\TranslationBundle\\Propel\\om\\BaseFile')) {
         // classes are built in-memory.
         $builder = new \PropelQuickBuilder();
         $builder->setSchema(file_get_contents(__DIR__ . '/../../Resources/config/propel/schema.xml'));
         $builder->setClassTargets(array('tablemap', 'peer', 'object', 'query'));
         $con = $builder->build();
     } else {
         // in memory-classes already exist, create connection and SQL manually
         $dsn = 'sqlite::memory:';
         $adapter = new \DBSQLite();
         $con = new \PropelPDO($dsn, null, null);
         $con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         $name = 'default';
         if (!\Propel::isInit()) {
             \Propel::setConfiguration(array('datasources' => array('default' => $name)));
         }
         \Propel::setDB($name, $adapter);
         \Propel::setConnection($name, $con, \Propel::CONNECTION_READ);
         \Propel::setConnection($name, $con, \Propel::CONNECTION_WRITE);
         // don't rebuild classes
         $builder = new \PropelQuickBuilder();
         $builder->setSchema(file_get_contents(__DIR__ . '/../../Resources/config/propel/schema.xml'));
         $builder->buildSQL($con);
     }
     return $con;
 }