Пример #1
0
 /**
  * Tests the Driver::log method.
  *
  * @return  void
  *
  * @covers  Joomla\Database\DatabaseDriver::log
  * @covers  Joomla\Database\DatabaseDriver::setLogger
  * @since   1.0
  */
 public function testLog()
 {
     $this->logs = array();
     $mockLogger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();
     $mockLogger->expects($this->any())->method('log')->willReturnCallback(array($this, 'mockLog'));
     $this->instance->log(Log\LogLevel::DEBUG, 'Debug', array('sql' => true));
     $this->assertEmpty($this->logs, 'Logger not set up yet.');
     // Set the logger and try again.
     $this->instance->setLogger($mockLogger);
     $this->instance->log(Log\LogLevel::DEBUG, 'Debug', array('sql' => true));
     $this->assertEquals(Log\LogLevel::DEBUG, $this->logs[0]['level']);
     $this->assertEquals('Debug', $this->logs[0]['message']);
     $this->assertEquals(array('sql' => true), $this->logs[0]['context']);
 }
Пример #2
0
 /**
  * Merges the incoming structure definition with the existing structure.
  *
  * @return  void
  *
  * @note    Currently only supports XML format.
  * @since   1.0
  * @throws  \RuntimeException on error.
  */
 public function mergeStructure()
 {
     $tables = $this->db->getTableList();
     if ($this->from instanceof \SimpleXMLElement) {
         $xml = $this->from;
     } else {
         $xml = new \SimpleXMLElement($this->from);
     }
     // Get all the table definitions.
     $xmlTables = $xml->xpath('database/table_structure');
     foreach ($xmlTables as $table) {
         // Convert the magic prefix into the real table name.
         $tableName = $this->getRealTableName((string) $table['name']);
         if (in_array($tableName, $tables)) {
             // The table already exists. Now check if there is any difference.
             if ($queries = $this->getAlterTableql($xml->database->table_structure)) {
                 // Run the queries to upgrade the data structure.
                 foreach ($queries as $query) {
                     $this->db->setQuery((string) $query);
                     try {
                         $this->db->execute();
                     } catch (\RuntimeException $e) {
                         $this->db->log(LogLevel::DEBUG, 'Fail: ' . $this->db->getQuery());
                         throw $e;
                     }
                     $this->db->log(LogLevel::DEBUG, 'Pass: '******'Fail: ' . $this->db->getQuery());
                 throw $e;
             }
             $this->db->log(LogLevel::DEBUG, 'Pass: ' . $this->db->getQuery());
         }
     }
 }