db = ezcDbInstance::get(); } catch ( Exception $e ) { $this->markTestSkipped(); } } public function testIndexFields() { $schema = new ezcDbSchema( array( 'bugdb' => new ezcDbSchemaTable( array ( 'field1' => new ezcDbSchemaField( 'integer' ), 'field2' => new ezcDbSchemaField( 'integer' ), ), array ( 'index1' => new ezcDbSchemaIndex( array ( 'field1' => new ezcDbSchemaIndexField() ) ), 'index2' => new ezcDbSchemaIndex( array ( 'field3' => new ezcDbSchemaIndexField() ) ), 'index3' => new ezcDbSchemaIndex( array ( 'field2' => new ezcDbSchemaIndexField(), 'field3' => new ezcDbSchemaIndexField() ) ), ) ), ) ); $expected = array( "Index references unknown field name .", "Index references unknown field name .", ); self::assertEquals( $expected, ezcDbSchemaValidator::validate( $schema ) ); } public function testTypes() { $schema = new ezcDbSchema( array( 'bugdb' => new ezcDbSchemaTable( array ( 'integerfield1' => new ezcDbSchemaField( 'integer' ), 'integerfield2' => new ezcDbSchemaField( 'int' ), 'booleanfield1' => new ezcDbSchemaField( 'boolean' ), 'booleanfield2' => new ezcDbSchemaField( 'bool' ), 'floatfield1' => new ezcDbSchemaField( 'float' ), 'floatfield2' => new ezcDbSchemaField( 'double' ), 'decimalfield1' => new ezcDbSchemaField( 'decimal' ), 'decimalfield2' => new ezcDbSchemaField( 'numeric' ), 'timestampfield1' => new ezcDbSchemaField( 'timestamp' ), 'timefield1' => new ezcDbSchemaField( 'time' ), 'datefield1' => new ezcDbSchemaField( 'date' ), 'textfield1' => new ezcDbSchemaField( 'text' ), 'textfield2' => new ezcDbSchemaField( 'char' ), 'textfield3' => new ezcDbSchemaField( 'varchar' ), 'blobfield1' => new ezcDbSchemaField( 'blob' ), 'clobfield1' => new ezcDbSchemaField( 'clob' ) ) ), ) ); $expected = array( "Field uses the unsupported type .", "Field uses the unsupported type .", "Field uses the unsupported type .", "Field uses the unsupported type .", "Field uses the unsupported type .", "Field uses the unsupported type ." ); self::assertEquals( $expected, ezcDbSchemaValidator::validate( $schema ) ); } public function testMissingIndexForAutoincrementField() { $schema = new ezcDbSchema( array( 'bugdb' => new ezcDbSchemaTable( array ( 'id' => new ezcDbSchemaField( 'integer', false, true, null, true ), ) ), 'bugdb2' => new ezcDbSchemaTable( array ( 'id' => new ezcDbSchemaField( 'integer', false, true, null, true ), ), array ( 'primary' => new ezcDbSchemaIndex( array ( 'id' => new ezcDbSchemaIndexField() ), true ), ) ), ) ); $expected = array( "Field is auto increment but there is no primary index defined.", ); self::assertEquals( $expected, ezcDbSchemaValidator::validate( $schema ) ); } public static function suite() { return new ezcTestSuite( 'ezcDatabaseSchemaValidatorTest' ); } } ?>