コード例 #1
0
ファイル: SqlTestBase.php プロジェクト: jivoo/data
 protected function getDb()
 {
     $def = new DatabaseDefinitionBuilder();
     $tableDef = new DefinitionBuilder();
     $tableDef->a = DataType::string();
     $tableDef->b = DataType::string();
     $tableDef->c = DataType::string();
     $def->addDefinition('Foo', $tableDef);
     $typeAdapter = $this->getMockBuilder('Jivoo\\Data\\Database\\TypeAdapter')->getMock();
     $typeAdapter->method('encode')->willReturnCallback(function ($type, $value) {
         return '"' . $value . '"';
     });
     $db = $this->getMockBuilder('Jivoo\\Data\\Database\\Common\\SqlDatabase')->getMock();
     $db->method('getTypeAdapter')->willReturn($typeAdapter);
     $db->method('getDefinition')->willReturn($def);
     $db->method('sqlLimitOffset')->willReturnCallback(function ($limit, $offset) {
         if (isset($offset)) {
             return 'LIMIT ' . $limit . ' OFFSET ' . $offset;
         }
         return 'LIMIT ' . $limit;
     });
     $db->method('tableName')->willReturnCallback(function ($table) {
         return \Jivoo\Utilities::camelCaseToUnderscores($table);
     });
     $db->method('quoteModel')->willReturnCallback(function ($model) {
         return '{' . $model . '}';
     });
     $db->method('quoteField')->willReturnCallback(function ($field) {
         return $field;
     });
     $db->method('quoteLiteral')->willReturnCallback(function ($type, $value) {
         return '"' . $value . '"';
     });
     $db->method('quoteString')->willReturnCallback(function ($value) {
         return '"' . $value . '"';
     });
     return $db;
 }
コード例 #2
0
ファイル: SqlDatabaseBase.php プロジェクト: jivoo/data
 /**
  * {@inheritdoc}
  */
 public function tableName($name)
 {
     return $this->tablePrefix . Utilities::camelCaseToUnderscores($name);
 }