OracleTestCase.php 6.36 KB
Newer Older
zYne's avatar
zYne committed
1
<?php
zYne's avatar
zYne committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 *  $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
19
 * <http://www.phpdoctrine.org>.
zYne's avatar
zYne committed
20 21 22 23 24 25 26 27 28
 */

/**
 * 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
29
 * @link        www.phpdoctrine.org
zYne's avatar
zYne committed
30 31 32
 * @since       1.0
 * @version     $Revision$
 */
33
class Doctrine_Export_Oracle_TestCase extends Doctrine_UnitTestCase
zYne's avatar
zYne committed
34
{
35
    public function testCreateSequenceExecutesSql()
zYne's avatar
zYne committed
36
    {
zYne's avatar
zYne committed
37 38 39 40 41
        $sequenceName = 'sequence';
        $start = 1;
        $query = 'CREATE SEQUENCE ' . $sequenceName . '_seq START WITH ' . $start . ' INCREMENT BY 1 NOCACHE';

        $this->export->createSequence($sequenceName, $start);
42

zYne's avatar
zYne committed
43 44 45
        $this->assertEqual($this->adapter->pop(), $query);
    }

46
    public function testDropSequenceExecutesSql()
zYne's avatar
zYne committed
47
    {
zYne's avatar
zYne committed
48 49 50 51 52
        $sequenceName = 'sequence';

        $query = 'DROP SEQUENCE ' . $sequenceName;

        $this->export->dropSequence($sequenceName);
53

zYne's avatar
zYne committed
54 55
        $this->assertEqual($this->adapter->pop(), $query . '_seq');
    }
56
    public function testCreateTableExecutesSql()
zYne's avatar
zYne committed
57
    {
zYne's avatar
zYne committed
58
        $name = 'mytable';
59

zYne's avatar
zYne committed
60 61
        $fields  = array('id' => array('type' => 'integer'));
        $options = array('type' => 'MYISAM');
62

zYne's avatar
zYne committed
63 64 65
        $this->export->createTable($name, $fields);

        $this->assertEqual($this->adapter->pop(), 'COMMIT');
66
        $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id INT DEFAULT NULL)');
zYne's avatar
zYne committed
67 68
        $this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');
    }
69
    public function testCreateTableSupportsDefaultAttribute()
zYne's avatar
zYne committed
70
    {
zYne's avatar
zYne committed
71 72 73 74
        $name = 'mytable';
        $fields  = array('name' => array('type' => 'char', 'length' => 10, 'default' => 'def'),
                         'type' => array('type' => 'integer', 'length' => 3, 'default' => 12)
                         );
75

zYne's avatar
zYne committed
76 77
        $options = array('primary' => array('name', 'type'));
        $this->export->createTable($name, $fields, $options);
78

zYne's avatar
zYne committed
79 80 81 82 83

        $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');
    }
84
    public function testCreateTableSupportsMultiplePks()
zYne's avatar
zYne committed
85
    {
zYne's avatar
zYne committed
86 87 88
        $name = 'mytable';
        $fields  = array('name' => array('type' => 'char', 'length' => 10),
                         'type' => array('type' => 'integer', 'length' => 3));
89

zYne's avatar
zYne committed
90 91
        $options = array('primary' => array('name', 'type'));
        $this->export->createTable($name, $fields, $options);
92

zYne's avatar
zYne committed
93 94

        $this->assertEqual($this->adapter->pop(), 'COMMIT');
95
        $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (name CHAR(10) DEFAULT NULL, type NUMBER(3) DEFAULT NULL, PRIMARY KEY(name, type))');
zYne's avatar
zYne committed
96 97
        $this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');
    }
98
    public function testCreateTableSupportsAutoincPks()
zYne's avatar
zYne committed
99
    {
zYne's avatar
zYne committed
100
        $name = 'mytable';
101

zYne's avatar
zYne committed
102 103
        $fields  = array('id' => array('type' => 'integer', 'autoincrement' => true));

zYne's avatar
zYne committed
104

zYne's avatar
zYne committed
105 106 107 108
        $this->export->createTable($name, $fields);

        $this->assertEqual($this->adapter->pop(), 'COMMIT');
        $this->assertEqual(substr($this->adapter->pop(),0, 14), 'CREATE TRIGGER');
109
        $this->assertEqual($this->adapter->pop(), 'CREATE SEQUENCE MYTABLE_seq START WITH 1 INCREMENT BY 1 NOCACHE');
zYne's avatar
zYne committed
110
        $this->assertEqual($this->adapter->pop(), 'ALTER TABLE MYTABLE ADD CONSTRAINT MYTABLE_AI_PK_idx PRIMARY KEY (id)');
111
        $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id INT DEFAULT NULL)');
zYne's avatar
zYne committed
112 113 114
        $this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');
    }

115
    public function testCreateTableSupportsCharType()
zYne's avatar
zYne committed
116
    {
zYne's avatar
zYne committed
117
        $name = 'mytable';
118

zYne's avatar
zYne committed
119 120 121 122 123
        $fields  = array('id' => array('type' => 'char', 'length' => 3));

        $this->export->createTable($name, $fields);

        $this->adapter->pop();
124
        $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id CHAR(3) DEFAULT NULL)');
zYne's avatar
zYne committed
125
    }
zYne's avatar
zYne committed
126 127 128 129 130 131 132 133 134 135 136
    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);

137
        $this->assertEqual($sql[0], 'CREATE TABLE sometable (id INT DEFAULT NULL UNIQUE, name VARCHAR2(4) DEFAULT NULL, PRIMARY KEY(id))');
zYne's avatar
zYne committed
138 139
    }
    public function testCreateTableSupportsIndexes()
zYne's avatar
zYne committed
140 141 142 143 144 145 146 147 148
    {
        $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')))
                         );

zYne's avatar
zYne committed
149
        $sql = $this->export->createTableSql('sometable', $fields, $options);
zYne's avatar
zYne committed
150

151
        $this->assertEqual($sql[0], 'CREATE TABLE sometable (id INT DEFAULT NULL UNIQUE, name VARCHAR2(4) DEFAULT NULL, PRIMARY KEY(id), INDEX myindex (id, name))');
zYne's avatar
zYne committed
152
    }
zYne's avatar
zYne committed
153
}