OracleTestCase.php 12.4 KB
Newer Older
1
<?php
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 *  $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>.
 */

/**
23
 * Doctrine_DataDict_Oracle_TestCase
24 25 26 27 28 29 30 31 32
 *
 * @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$
 */
33
class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase {
34 35
    public function testGetPortableDeclarationForUnknownNativeTypeThrowsException() 
    {
36 37 38
        try {
            $this->dataDict->getPortableDeclaration(array('type' => 'some_unknown_type'));
            $this->fail();
zYne's avatar
zYne committed
39
        } catch(Doctrine_DataDict_Exception $e) {
40 41 42
            $this->pass();
        }
    }
43 44
    public function testGetPortableDeclarationSupportsNativeFloatType() 
    {
45
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'float'));
zYne's avatar
zYne committed
46 47 48 49 50

        $this->assertEqual($type, array('type' => array('float'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
51
    }
zYne's avatar
zYne committed
52
    public function testGetPortableDeclarationSupportsNativeIntegerTypes()
53
    {
54 55
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'integer'));
        
zYne's avatar
zYne committed
56 57 58 59
        $this->assertEqual($type, array('type' => array('integer'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
60 61 62

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'pls_integer', 'length' => 1));
        
zYne's avatar
zYne committed
63 64 65 66
        $this->assertEqual($type, array('type' => array('integer', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => null));
67 68 69

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'binary_integer', 'length' => 1));
        
zYne's avatar
zYne committed
70 71 72 73
        $this->assertEqual($type, array('type' => array('integer', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => null));
74
    }
75 76
    public function testGetPortableDeclarationSupportsNativeStringTypes() 
    {
77 78
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'varchar'));

zYne's avatar
zYne committed
79 80 81 82
        $this->assertEqual($type, array('type' => array('string'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
83 84 85

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'varchar2', 'length' => 1));

zYne's avatar
zYne committed
86 87 88 89
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => false));
90 91 92

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'nvarchar2', 'length' => 1));
        
zYne's avatar
zYne committed
93 94 95 96
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => false));
97 98 99
        
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'char', 'length' => 1));

zYne's avatar
zYne committed
100 101 102 103
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => true));
104 105 106

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'nchar', 'length' => 1));
        
zYne's avatar
zYne committed
107 108 109 110
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => true));
111
    }
112 113
    public function testGetPortableDeclarationSupportsNativeNumberType() 
    {
114 115
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'number'));
        
zYne's avatar
zYne committed
116 117 118 119 120
        $this->assertEqual($type, array('type' => array('integer'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));

121 122 123

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'number', 'length' => 1));
        
zYne's avatar
zYne committed
124 125 126 127 128
        $this->assertEqual($type, array('type' => array('integer', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => null));

129
    }
130 131
    public function testGetPortableDeclarationSupportsNativeTimestampType() 
    {
132 133
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'date'));
        
zYne's avatar
zYne committed
134 135 136 137
        $this->assertEqual($type, array('type' => array('timestamp'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
138 139 140

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'timestamp'));
        
zYne's avatar
zYne committed
141 142 143 144
        $this->assertEqual($type, array('type' => array('timestamp'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
145
    }
146 147
    public function testGetPortableDeclarationSupportsNativeClobTypes() 
    {
148 149
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'clob'));
        
zYne's avatar
zYne committed
150 151 152 153
        $this->assertEqual($type, array('type' => array('clob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
154 155 156

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'long'));
        
zYne's avatar
zYne committed
157 158 159 160
        $this->assertEqual($type, array('type' => array('string', 'clob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
161 162 163
        
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'nclob'));
        
zYne's avatar
zYne committed
164 165 166 167
        $this->assertEqual($type, array('type' => array('clob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
168 169

    }
170 171
    public function testGetPortableDeclarationSupportsNativeBlobTypes() 
    {
172 173
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'blob'));
        
zYne's avatar
zYne committed
174 175 176 177
        $this->assertEqual($type, array('type' => array('blob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
178 179 180

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'long raw'));

zYne's avatar
zYne committed
181 182 183 184
        $this->assertEqual($type, array('type' => array('blob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
185 186 187

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'long raw'));

zYne's avatar
zYne committed
188 189 190 191
        $this->assertEqual($type, array('type' => array('blob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
192 193
        
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'raw'));
194

zYne's avatar
zYne committed
195 196 197 198
        $this->assertEqual($type, array('type' => array('blob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
199
    }
200 201
    public function testGetNativeDefinitionSupportsIntegerType() 
    {
202 203 204 205 206 207 208 209 210 211 212 213 214
        $a = array('type' => 'integer', 'length' => 20, 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'NUMBER(20)');
        
        $a['length'] = 4;

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'NUMBER(4)');

        $a['length'] = 2;

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'NUMBER(2)');
    }

215 216
    public function testGetNativeDefinitionSupportsFloatType() 
    {
217 218 219 220
        $a = array('type' => 'float', 'length' => 20, 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'NUMBER');
    }
221 222
    public function testGetNativeDefinitionSupportsBooleanType() 
    {
223 224 225 226
        $a = array('type' => 'boolean', 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'NUMBER(1)');
    }
227 228
    public function testGetNativeDefinitionSupportsDateType() 
    {
229 230 231 232
        $a = array('type' => 'date', 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'DATE');
    }
233 234
    public function testGetNativeDefinitionSupportsTimestampType() 
    {
235 236 237 238
        $a = array('type' => 'timestamp', 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'DATE');
    }
239 240
    public function testGetNativeDefinitionSupportsTimeType() 
    {
241 242 243 244
        $a = array('type' => 'time', 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'DATE');
    }
245 246
    public function testGetNativeDefinitionSupportsClobType() 
    {
247 248 249 250
        $a = array('type' => 'clob');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CLOB');
    }
251 252
    public function testGetNativeDefinitionSupportsBlobType() 
    {
253 254 255 256
        $a = array('type' => 'blob');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BLOB');
    }
257 258
    public function testGetNativeDefinitionSupportsCharType() 
    {
259 260 261 262
        $a = array('type' => 'char', 'length' => 10);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(10)');
    }
263 264
    public function testGetNativeDefinitionSupportsVarcharType() 
    {
265 266 267 268
        $a = array('type' => 'varchar', 'length' => 10);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR2(10)');
    }
269 270
    public function testGetNativeDefinitionSupportsArrayType() 
    {
271 272 273 274
        $a = array('type' => 'array', 'length' => 40);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR2(40)');
    }
275 276
    public function testGetNativeDefinitionSupportsStringType() 
    {
277 278 279 280
        $a = array('type' => 'string');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR2(16777215)');
    }
281 282
    public function testGetNativeDefinitionSupportsArrayType2() 
    {
283 284 285 286
        $a = array('type' => 'array');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR2(16777215)');
    }
287 288
    public function testGetNativeDefinitionSupportsObjectType() 
    {
289 290 291 292 293
        $a = array('type' => 'object');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR2(16777215)');
    }
}