コード例 #1
0
ファイル: DBSRTest.php プロジェクト: dvdgiessen/dbsr
 public function testGetPHPType()
 {
     // Test case array
     $testCases = array();
     // Base test case settings (for automatic generation)
     // TODO: add BIT and all date/time types
     $baseTestCases = array('boolean' => array('BOOL' => 0, 'BOOLEAN' => 0), 'integer' => array('INT' => 1, 'INTEGER' => 1, 'TINYINT' => 1, 'SMALLINT' => 1, 'MEDIUMINT' => 1, 'BIGINT' => 1), 'float' => array('DECIMAL' => 2, 'NUMERIC' => 2, 'FLOAT' => 2, 'DOUBLE' => 2, 'DOUBLE PRECISION' => 2, 'REAL' => 2, 'DEC' => 2, 'FIXED' => 2), 'string' => array('CHAR' => 1, 'VARCHAR' => 1, 'BINARY' => 1, 'VARBINARY' => 1, 'BLOB' => 0, 'TINYBLOB' => 0, 'MEDIUMBLOB' => 0, 'LONGBLOB' => 0, 'TEXT' => 0, 'TINYTEXT' => 0, 'MEDIUMTEXT' => 0, 'LONGTEXT' => 0, 'ENUM' => 0, 'SET' => 0));
     // Generate numeric test cases
     foreach ($baseTestCases as $expected => $tests) {
         foreach ($tests as $type => $argc) {
             $testCases[$expected][] = $type;
             $testCases[$expected][] = strtolower($type);
             $testCases[$expected][] = ' ' . $type . ' ';
             if ($argc >= 1) {
                 $testCases[$expected][] = $type . '(10)';
                 $testCases[$expected][] = strtolower($type) . '(10)';
                 $testCases[$expected][] = ' ' . $type . '(10) ';
                 $testCases[$expected][] = $type . '( 10 )';
             }
             if ($argc >= 2) {
                 $testCases[$expected][] = $type . '(10,5)';
                 $testCases[$expected][] = strtolower($type) . '(10,5)';
                 $testCases[$expected][] = ' ' . $type . '(10,5) ';
                 $testCases[$expected][] = $type . '( 10 , 5 )';
             }
         }
     }
     // Run test cases
     foreach ($testCases as $expected => $testCase) {
         foreach ($testCase as $test) {
             $this->assertEquals($expected, DBSR::getPHPType($test), 'MySQL type "' . $test . '" should convert to a PHP ' . $expected);
         }
     }
 }