Ejemplo n.º 1
0
 /**
  * Tests FUSE and lists, FUSE enforces no more than
  * 3 sugar cubes in coffee.
  *
  * @return void
  */
 public function testCoffeeWithSugarAndFUSE()
 {
     $coffee = R::dispense('coffee');
     $coffee->size = 'XL';
     $coffee->ownSugar = R::dispense('sugar', 5);
     $id = R::store($coffee);
     $coffee = R::load('coffee', $id);
     asrt(count($coffee->ownSugar), 3);
     $coffee->ownSugar = R::dispense('sugar', 2);
     $id = R::store($coffee);
     $coffee = R::load('coffee', $id);
     asrt(count($coffee->ownSugar), 2);
     $cocoa = R::dispense('cocoa');
     $cocoa->name = 'Fair Cocoa';
     list($taste1, $taste2) = R::dispense('taste', 2);
     $taste1->name = 'sweet';
     $taste2->name = 'bitter';
     $cocoa->ownTaste = array($taste1, $taste2);
     R::store($cocoa);
     $cocoa->name = 'Koko';
     R::store($cocoa);
     if (method_exists(R::getDatabaseAdapter()->getDatabase(), 'getPDO')) {
         $pdo = R::getDatabaseAdapter()->getDatabase()->getPDO();
         $driver = new RPDO($pdo);
         pass();
         asrt($pdo->getAttribute(\PDO::ATTR_ERRMODE), \PDO::ERRMODE_EXCEPTION);
         asrt($pdo->getAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE), \PDO::FETCH_ASSOC);
         asrt(strval($driver->GetCell('select 123')), '123');
     }
     $a = new SQL();
     $a->setSqlState('test');
     $b = strval($a);
     asrt(strpos($b, '[test] - ') === 0, TRUE);
 }
Ejemplo n.º 2
0
 /**
  * Adds a database to the facade, afterwards you can select the database using
  * selectDatabase($key), where $key is the name you assigned to this database.
  *
  * Usage:
  *
  * R::addDatabase( 'database-1', 'sqlite:/tmp/db1.txt' );
  * R::selectDatabase( 'database-1' ); //to select database again
  *
  * This method allows you to dynamically add (and select) new databases
  * to the facade. Adding a database with the same key will cause an exception.
  *
  * @param string      $key    ID for the database
  * @param string      $dsn    DSN for the database
  * @param string      $user   user for connection
  * @param NULL|string $pass   password for connection
  * @param bool        $frozen whether this database is frozen or not
  *
  * @return void
  */
 public static function addDatabase($key, $dsn, $user = NULL, $pass = NULL, $frozen = FALSE)
 {
     if (isset(self::$toolboxes[$key])) {
         throw new RedException('A database has already be specified for this key.');
     }
     if (is_object($dsn)) {
         $db = new RPDO($dsn);
         $dbType = $db->getDatabaseType();
     } else {
         $db = new RPDO($dsn, $user, $pass, TRUE);
         $dbType = substr($dsn, 0, strpos($dsn, ':'));
     }
     $adapter = new DBAdapter($db);
     $writers = array('pgsql' => 'PostgreSQL', 'sqlite' => 'SQLiteT', 'cubrid' => 'CUBRID', 'mysql' => 'MySQL', 'sqlsrv' => 'SQLServer');
     $wkey = trim(strtolower($dbType));
     if (!isset($writers[$wkey])) {
         trigger_error('Unsupported DSN: ' . $wkey);
     }
     $writerClass = '\\RedBeanPHP\\QueryWriter\\' . $writers[$wkey];
     $writer = new $writerClass($adapter);
     $redbean = new OODB($writer, $frozen);
     self::$toolboxes[$key] = new ToolBox($redbean, $adapter, $writer);
 }
Ejemplo n.º 3
0
 /**
  * Test whether connection failure does not reveal
  * credentials.
  * 
  * @return void
  */
 public function testConnect()
 {
     $driver = new RPDO('dsn:invalid', 'usr', 'psst');
     try {
         $driver->connect();
         fail();
     } catch (\PDOException $e) {
         asrt(strpos($e->getMessage(), 'invalid'), FALSE);
         asrt(strpos($e->getMessage(), 'usr'), FALSE);
         asrt(strpos($e->getMessage(), 'psst'), FALSE);
     }
 }