FirebirdTestCase.php 3.48 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_Firebird_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_Firebird_TestCase extends Doctrine_UnitTestCase
zYne's avatar
zYne committed
34
{
35
    public function testCreateDatabaseDoesNotExecuteSql()
zYne's avatar
zYne committed
36
    {
zYne's avatar
zYne committed
37 38 39
        try {
            $this->export->createDatabase('db');
            $this->fail();
40
        } catch(Doctrine_Export_Exception $e) {
zYne's avatar
zYne committed
41 42 43
            $this->pass();
        }
    }
44
    public function testDropDatabaseDoesNotExecuteSql()
zYne's avatar
zYne committed
45
    {
zYne's avatar
zYne committed
46 47 48
        try {
            $this->export->dropDatabase('db');
            $this->fail();
49
        } catch(Doctrine_Export_Exception $e) {
zYne's avatar
zYne committed
50 51 52
            $this->pass();
        }
    }
53
    public function testCreateTableSupportsAutoincPks()
zYne's avatar
zYne committed
54
    {
zYne's avatar
zYne committed
55
        $name = 'mytable';
56

zYne's avatar
zYne committed
57 58 59 60
        $fields  = array('id' => array('type' => 'integer', 'unsigned' => 1, 'autoincrement' => true));

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

zYne's avatar
zYne committed
61
        $this->assertEqual($this->adapter->pop(), 'CREATE TRIGGER mytable_AUTOINCREMENT_PK FOR mytable ACTIVE BEFORE INSERT POSITION 0 AS BEGIN IF (NEW.id IS NULL OR NEW.id = 0) THEN NEW.id = GEN_ID(mytable_seq, 1) END');
zYne's avatar
zYne committed
62
    }
63
    public function testCreateTableSupportsDefaultAttribute()
zYne's avatar
zYne committed
64
    {
zYne's avatar
zYne committed
65 66 67 68
        $name = 'mytable';
        $fields  = array('name' => array('type' => 'char', 'length' => 10, 'default' => 'def'),
                         'type' => array('type' => 'integer', 'length' => 3, 'default' => 12)
                         );
69

zYne's avatar
zYne committed
70 71 72 73 74
        $options = array('primary' => array('name', 'type'));
        $this->export->createTable($name, $fields, $options);

        $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (name CHAR(10) DEFAULT \'def\', type INT DEFAULT 12, PRIMARY KEY(name, type))');
    }
75
    public function testCreateTableSupportsMultiplePks()
zYne's avatar
zYne committed
76
    {
zYne's avatar
zYne committed
77 78 79
        $name = 'mytable';
        $fields  = array('name' => array('type' => 'char', 'length' => 10),
                         'type' => array('type' => 'integer', 'length' => 3));
80

zYne's avatar
zYne committed
81 82
        $options = array('primary' => array('name', 'type'));
        $this->export->createTable($name, $fields, $options);
83 84

        $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (name CHAR(10) DEFAULT NULL, type INT DEFAULT NULL, PRIMARY KEY(name, type))');
zYne's avatar
zYne committed
85 86
    }
}