eZ components PHP Cross Reference Developer Tools

Source: /Database/tests/pdo_test.php - 106 lines - 2815 bytes - Summary - Text - Print

   1  <?php
   2  /**
   3   * @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved.
   4   * @license http://ez.no/licenses/new_bsd New BSD License
   5   * @version 1.4.7
   6   * @filesource
   7   * @package Database
   8   * @subpackage Tests
   9   */
  10  
  11  /**
  12   * Test the PDO system.
  13   *
  14   * @package Database
  15   * @subpackage Tests
  16   */
  17  class ezcPdoTest extends ezcTestCase
  18  {
  19      protected function setUp()
  20      {
  21          try
  22          {
  23              $db = ezcDbInstance::get();
  24          }
  25          catch ( Exception $e )
  26          {
  27              $this->markTestSkipped();
  28          }
  29  
  30          $this->q = new ezcQueryInsert( $db );
  31          try
  32          {
  33              $db->exec( 'DROP TABLE query_test' );
  34          }
  35          catch ( Exception $e ) {} // eat
  36  
  37          // insert some data
  38          $db->exec( 'CREATE TABLE query_test ( id int, company VARCHAR(255), section VARCHAR(255), employees int )' );
  39  
  40      }
  41  
  42      protected function tearDown()
  43      {
  44          $db = ezcDbInstance::get();
  45          $db->exec( 'DROP TABLE query_test' );
  46      }
  47  
  48  
  49      // This query probably fails when the PDO is linked to the wrong libmysql client.
  50      // E.g. it must be linked against libmysqlclient12 and not libmysqlclient14 
  51      // nor libmysqlclient15. 
  52      public function testIdNotFound()
  53      {
  54          $db = ezcDbInstance::get();
  55          if ( $db->getName() != 'mysql' )
  56          {
  57              return;  // no need to test it in RDBMS other than MySQL
  58          }
  59          
  60          $q = $db->prepare("INSERT INTO query_test VALUES( 1, 'name', 'section', 22)" );
  61          $q->execute();
  62  
  63          $stmt = $db->prepare('select * from `query_test` where `id`=:id');
  64          $stmt->bindValue(':id', 1);
  65          $stmt->execute();
  66          $row = $stmt->fetchAll( PDO::FETCH_ASSOC );
  67  
  68          $this->assertEquals( "1", $row[0]["id"] ); 
  69          $this->assertEquals( "name", $row[0]["company"] ); 
  70          $this->assertEquals( "section", $row[0]["section"] ); 
  71          $stmt->closeCursor();
  72      }
  73  
  74  
  75      // Works in PHP 5.2.1RC2, segfaults in PHP 5.1.4
  76  /*
  77      public function testSegfaultWrongFunctionCall()
  78      {
  79          $db = ezcDbInstance::get();
  80  
  81          $q = $db->prepare("INSERT INTO query_test VALUES( '', 'name', 'section', 22)" ); 
  82          $q->execute();
  83  
  84          $q->oasdfa(); // Wrong method call.
  85      }
  86  */
  87      // Works in PHP 5.1.4, Fails (hangs) in PHP 5.2.1RC2-dev.
  88      public function testInsertWithWrongColon()
  89      {
  90          $db = ezcDbInstance::get();
  91          if ( $db->getName() != 'mysql' )
  92          {
  93              return;  // no need to test it in RDBMS other than MySQL.
  94          }
  95  
  96          $q = $db->prepare("INSERT INTO query_test VALUES( ':id', 'name', 'section', 22)" ); // <-- ':id' should be :id (or a string without ":")
  97          $q->execute();
  98      }
  99  
 100      public static function suite()
 101      {
 102           return new PHPUnit_Framework_TestSuite( "ezcPdoTest" );
 103      }
 104  }
 105  
 106  ?>

title

Description

title

Description

title

Description

title

title

Body