2006-12-28 00:30:25 +03:00
< ? php
2007-01-27 13:11:25 +03:00
/*
* $Id $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT
* LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL ,
* SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT
* LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL . For more information , see
* < http :// www . phpdoctrine . com >.
*/
/**
* Doctrine_Export_Oracle_TestCase
*
* @ package Doctrine
* @ author Konsta Vesterinen < kvesteri @ cc . hut . fi >
* @ license http :// www . opensource . org / licenses / lgpl - license . php LGPL
* @ category Object Relational Mapping
* @ link www . phpdoctrine . com
* @ since 1.0
* @ version $Revision $
*/
2008-01-10 16:18:33 +03:00
class Doctrine_Export_Oracle_TestCase extends Doctrine_UnitTestCase
2007-01-27 13:13:13 +03:00
{
2008-01-10 16:18:33 +03:00
public function testCreateSequenceExecutesSql ()
2007-01-27 13:13:13 +03:00
{
2006-12-28 00:30:25 +03:00
$sequenceName = 'sequence' ;
$start = 1 ;
$query = 'CREATE SEQUENCE ' . $sequenceName . '_seq START WITH ' . $start . ' INCREMENT BY 1 NOCACHE' ;
$this -> export -> createSequence ( $sequenceName , $start );
2008-01-10 16:18:33 +03:00
2006-12-28 00:30:25 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), $query );
}
2008-01-10 16:18:33 +03:00
public function testDropSequenceExecutesSql ()
2007-01-27 13:13:13 +03:00
{
2006-12-28 00:30:25 +03:00
$sequenceName = 'sequence' ;
$query = 'DROP SEQUENCE ' . $sequenceName ;
$this -> export -> dropSequence ( $sequenceName );
2008-01-10 16:18:33 +03:00
2006-12-28 00:30:25 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), $query . '_seq' );
}
2008-01-10 16:18:33 +03:00
public function testCreateTableExecutesSql ()
2007-01-27 13:13:13 +03:00
{
2006-12-28 00:30:25 +03:00
$name = 'mytable' ;
2008-01-10 16:18:33 +03:00
2006-12-28 00:30:25 +03:00
$fields = array ( 'id' => array ( 'type' => 'integer' ));
$options = array ( 'type' => 'MYISAM' );
2008-01-10 16:18:33 +03:00
2006-12-28 00:30:25 +03:00
$this -> export -> createTable ( $name , $fields );
$this -> assertEqual ( $this -> adapter -> pop (), 'COMMIT' );
2008-01-10 16:18:33 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE mytable (id INT DEFAULT NULL)' );
2006-12-28 00:30:25 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), 'BEGIN TRANSACTION' );
}
2008-01-10 16:18:33 +03:00
public function testCreateTableSupportsDefaultAttribute ()
2007-01-27 13:13:13 +03:00
{
2006-12-28 00:30:25 +03:00
$name = 'mytable' ;
$fields = array ( 'name' => array ( 'type' => 'char' , 'length' => 10 , 'default' => 'def' ),
'type' => array ( 'type' => 'integer' , 'length' => 3 , 'default' => 12 )
);
2008-01-10 16:18:33 +03:00
2006-12-28 00:30:25 +03:00
$options = array ( 'primary' => array ( 'name' , 'type' ));
$this -> export -> createTable ( $name , $fields , $options );
2008-01-10 16:18:33 +03:00
2006-12-28 00:30:25 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), 'COMMIT' );
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE mytable (name CHAR(10) DEFAULT \'def\', type NUMBER(3) DEFAULT 12, PRIMARY KEY(name, type))' );
$this -> assertEqual ( $this -> adapter -> pop (), 'BEGIN TRANSACTION' );
}
2008-01-10 16:18:33 +03:00
public function testCreateTableSupportsMultiplePks ()
2007-01-27 13:13:13 +03:00
{
2006-12-28 00:30:25 +03:00
$name = 'mytable' ;
$fields = array ( 'name' => array ( 'type' => 'char' , 'length' => 10 ),
'type' => array ( 'type' => 'integer' , 'length' => 3 ));
2008-01-10 16:18:33 +03:00
2006-12-28 00:30:25 +03:00
$options = array ( 'primary' => array ( 'name' , 'type' ));
$this -> export -> createTable ( $name , $fields , $options );
2008-01-10 16:18:33 +03:00
2006-12-28 00:30:25 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), 'COMMIT' );
2008-01-10 16:18:33 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE mytable (name CHAR(10) DEFAULT NULL, type NUMBER(3) DEFAULT NULL, PRIMARY KEY(name, type))' );
2006-12-28 00:30:25 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), 'BEGIN TRANSACTION' );
}
2008-01-10 16:18:33 +03:00
public function testCreateTableSupportsAutoincPks ()
2007-01-27 13:13:13 +03:00
{
2006-12-28 00:30:25 +03:00
$name = 'mytable' ;
2008-01-10 16:18:33 +03:00
2006-12-28 00:30:25 +03:00
$fields = array ( 'id' => array ( 'type' => 'integer' , 'autoincrement' => true ));
2007-06-18 23:58:11 +04:00
2006-12-28 00:30:25 +03:00
$this -> export -> createTable ( $name , $fields );
$this -> assertEqual ( $this -> adapter -> pop (), 'COMMIT' );
$this -> assertEqual ( substr ( $this -> adapter -> pop (), 0 , 14 ), 'CREATE TRIGGER' );
2008-01-10 16:18:33 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE SEQUENCE MYTABLE_seq START WITH 1 INCREMENT BY 1 NOCACHE' );
2006-12-28 00:30:25 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), 'ALTER TABLE MYTABLE ADD CONSTRAINT MYTABLE_AI_PK_idx PRIMARY KEY (id)' );
2008-01-10 16:18:33 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE mytable (id INT DEFAULT NULL)' );
2006-12-28 00:30:25 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), 'BEGIN TRANSACTION' );
}
2008-01-10 16:18:33 +03:00
public function testCreateTableSupportsCharType ()
2007-01-27 13:13:13 +03:00
{
2006-12-28 00:30:25 +03:00
$name = 'mytable' ;
2008-01-10 16:18:33 +03:00
2006-12-28 00:30:25 +03:00
$fields = array ( 'id' => array ( 'type' => 'char' , 'length' => 3 ));
$this -> export -> createTable ( $name , $fields );
$this -> adapter -> pop ();
2008-01-10 16:18:33 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE mytable (id CHAR(3) DEFAULT NULL)' );
2006-12-28 00:30:25 +03:00
}
2007-02-17 14:09:34 +03:00
public function testCreateTableSupportsUniqueConstraint ()
{
$fields = array ( 'id' => array ( 'type' => 'integer' , 'unsigned' => 1 , 'autoincrement' => true , 'unique' => true ),
'name' => array ( 'type' => 'string' , 'length' => 4 ),
);
$options = array ( 'primary' => array ( 'id' ),
);
$sql = $this -> export -> createTableSql ( 'sometable' , $fields , $options );
2008-01-10 16:18:33 +03:00
$this -> assertEqual ( $sql [ 0 ], 'CREATE TABLE sometable (id INT DEFAULT NULL UNIQUE, name VARCHAR2(4) DEFAULT NULL, PRIMARY KEY(id))' );
2007-02-17 14:09:34 +03:00
}
public function testCreateTableSupportsIndexes ()
2007-02-11 00:19:06 +03:00
{
$fields = array ( 'id' => array ( 'type' => 'integer' , 'unsigned' => 1 , 'autoincrement' => true , 'unique' => true ),
'name' => array ( 'type' => 'string' , 'length' => 4 ),
);
$options = array ( 'primary' => array ( 'id' ),
'indexes' => array ( 'myindex' => array ( 'fields' => array ( 'id' , 'name' )))
);
2007-02-17 14:09:34 +03:00
$sql = $this -> export -> createTableSql ( 'sometable' , $fields , $options );
2007-02-11 00:19:06 +03:00
2008-01-10 16:18:33 +03:00
$this -> assertEqual ( $sql [ 0 ], 'CREATE TABLE sometable (id INT DEFAULT NULL UNIQUE, name VARCHAR2(4) DEFAULT NULL, PRIMARY KEY(id), INDEX myindex (id, name))' );
2007-02-11 00:19:06 +03:00
}
2006-12-28 00:30:25 +03:00
}