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

22 23 24 25 26 27 28 29 30 31 32
/**
 * Doctrine_DataDict_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$
 */
33 34 35 36
class Doctrine_DataDict_Pgsql_TestCase extends Doctrine_UnitTestCase 
{
    public function getDeclaration($type) 
    {
37
        return $this->dataDict->getPortableDeclaration(array('type' => $type, 'name' => 'colname', 'length' => 2, 'fixed' => true));
38
    }
39 40
    public function testGetPortableDeclarationForUnknownNativeTypeThrowsException() 
    {
41 42 43
        try {
            $this->dataDict->getPortableDeclaration(array('type' => 'some_unknown_type'));
            $this->fail();
zYne's avatar
zYne committed
44
        } catch(Doctrine_DataDict_Exception $e) {
45 46 47
            $this->pass();
        }
    }   
48 49
    public function testGetPortableDeclarationSupportsNativeBlobTypes() 
    {
50 51
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'blob'));
        
zYne's avatar
zYne committed
52 53 54 55
        $this->assertEqual($type, array('type' => array('blob'), 
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
56 57 58

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

zYne's avatar
zYne committed
59 60 61 62
        $this->assertEqual($type, array('type' => array('blob'), 
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
63 64 65

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

zYne's avatar
zYne committed
66 67 68 69
        $this->assertEqual($type, array('type' => array('blob'), 
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
70 71 72
        
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'longblob'));

zYne's avatar
zYne committed
73 74 75 76
        $this->assertEqual($type, array('type' => array('blob'), 
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
77 78 79

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

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

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

zYne's avatar
zYne committed
87 88 89 90
        $this->assertEqual($type, array('type' => array('blob', 'clob'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
91
    }
92 93
    public function testGetPortableDeclarationSupportsNativeTimestampTypes()
    {
94 95
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'timestamp'));
        
zYne's avatar
zYne committed
96 97 98 99
        $this->assertEqual($type, array('type' => array('timestamp'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
100 101 102

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'datetime'));
        
zYne's avatar
zYne committed
103 104 105 106
        $this->assertEqual($type, array('type' => array('timestamp'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
107
    }
108 109
    public function testGetPortableDeclarationSupportsNativeDecimalTypes() 
    {
110 111
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'decimal'));

zYne's avatar
zYne committed
112 113 114 115
        $this->assertEqual($type, array('type' => array('decimal'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
116 117 118

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

zYne's avatar
zYne committed
119 120 121 122
        $this->assertEqual($type, array('type' => array('decimal'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
123 124 125

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

zYne's avatar
zYne committed
126 127 128 129
        $this->assertEqual($type, array('type' => array('decimal'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
130
    }
131 132
    public function testGetPortableDeclarationSupportsNativeFloatTypes() 
    {
133 134
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'float'));
        
zYne's avatar
zYne committed
135 136 137 138
        $this->assertEqual($type, array('type' => array('float'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
139 140 141

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'double'));
        
zYne's avatar
zYne committed
142 143 144 145
        $this->assertEqual($type, array('type' => array('float'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
146 147 148

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'real'));
        
zYne's avatar
zYne committed
149 150 151 152
        $this->assertEqual($type, array('type' => array('float'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
153
    }
154 155
    public function testGetPortableDeclarationSupportsNativeYearType() 
    {
156 157
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'year'));

zYne's avatar
zYne committed
158 159 160 161
        $this->assertEqual($type, array('type' => array('integer', 'date'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
162
    }
163 164
    public function testGetPortableDeclarationSupportsNativeDateType() 
    {
165 166
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'date'));
        
zYne's avatar
zYne committed
167 168 169 170
        $this->assertEqual($type, array('type' => array('date'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
171
    }
172 173
    public function testGetPortableDeclarationSupportsNativeTimeType() 
    {
174 175
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'time'));
        
zYne's avatar
zYne committed
176 177 178 179
        $this->assertEqual($type, array('type' => array('time'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
180
    }
181 182
    public function testGetPortableDeclarationSupportsNativeStringTypes() 
    {
183 184
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'text'));

zYne's avatar
zYne committed
185 186 187 188
        $this->assertEqual($type, array('type' => array('string', 'clob'),
                                        'length' => null, 
                                        'unsigned' => null, 
                                        'fixed' => null));
189 190 191

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

zYne's avatar
zYne committed
192 193 194 195
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => false));
196 197 198

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'unknown', 'length' => 1));
        
zYne's avatar
zYne committed
199 200 201 202 203
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => true));

204 205 206
        
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'char', 'length' => 1));

zYne's avatar
zYne committed
207 208 209 210 211
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => true));

212 213 214

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'bpchar', 'length' => 1));
        
zYne's avatar
zYne committed
215 216 217 218 219
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => true));

220
    }
221 222
    public function testGetPortableDeclarationSupportsNativeIntegerTypes() 
    {
223 224
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'smallint'));

zYne's avatar
zYne committed
225 226
        $this->assertEqual($this->getDeclaration('smallint'), array('type' => array('integer', 'boolean'), 'length' => 2, 'unsigned' => false, 'fixed' => null));
        $this->assertEqual($this->getDeclaration('int2'), array('type' => array('integer', 'boolean'), 'length' => 2, 'unsigned' => false, 'fixed' => null));
227

zYne's avatar
zYne committed
228 229 230 231 232
        $this->assertEqual($this->getDeclaration('int'), array('type' => array('integer'), 'length' => 4, 'unsigned' => false, 'fixed' => null));
        $this->assertEqual($this->getDeclaration('int4'), array('type' => array('integer'), 'length' => 4, 'unsigned' => false, 'fixed' => null));
        $this->assertEqual($this->getDeclaration('integer'), array('type' => array('integer'), 'length' => 4, 'unsigned' => false, 'fixed' => null));
        $this->assertEqual($this->getDeclaration('serial'), array('type' => array('integer'), 'length' => 4, 'unsigned' => false, 'fixed' => null));
        $this->assertEqual($this->getDeclaration('serial4'), array('type' => array('integer'), 'length' => 4, 'unsigned' => false, 'fixed' => null));
zYne's avatar
zYne committed
233

zYne's avatar
zYne committed
234 235 236 237
        $this->assertEqual($this->getDeclaration('bigint'), array('type' => array('integer'), 'length' => 8, 'unsigned' => false, 'fixed' => null));
        $this->assertEqual($this->getDeclaration('int8'), array('type' => array('integer'), 'length' => 8, 'unsigned' => false, 'fixed' => null));
        $this->assertEqual($this->getDeclaration('bigserial'), array('type' => array('integer'), 'length' => 8, 'unsigned' => false, 'fixed' => null));
        $this->assertEqual($this->getDeclaration('serial8'), array('type' => array('integer'), 'length' => 8, 'unsigned' => false, 'fixed' => null));
238
    }
239 240
    public function testGetPortableDeclarationSupportsNativeBooleanTypes()
    {
zYne's avatar
zYne committed
241 242
        $this->assertEqual($this->getDeclaration('bool'), array('type' => array('boolean'), 'length' => 1, 'unsigned' => false, 'fixed' => null));
        $this->assertEqual($this->getDeclaration('boolean'), array('type' => array('boolean'), 'length' => 1, 'unsigned' => false, 'fixed' => null));
243
    }
244

245 246
    public function testGetNativeDefinitionSupportsIntegerType() 
    {
zYne's avatar
zYne committed
247 248 249 250 251 252 253 254 255 256 257 258
        $a = array('type' => 'integer', 'length' => 20, 'fixed' => false);

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

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

        $a['length'] = 2;

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'SMALLINT');
    }
259 260
    public function testGetNativeDefinitionSupportsIntegerTypeWithAutoinc() 
    {
zYne's avatar
zYne committed
261 262
        $a = array('type' => 'integer', 'length' => 20, 'fixed' => false, 'autoincrement' => true);

zYne's avatar
zYne committed
263
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BIGSERIAL');
zYne's avatar
zYne committed
264 265 266

        $a['length'] = 4;

zYne's avatar
zYne committed
267
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'SERIAL');
zYne's avatar
zYne committed
268 269 270

        $a['length'] = 2;

zYne's avatar
zYne committed
271
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'SERIAL');
zYne's avatar
zYne committed
272
    }
273 274
    public function testGetNativeDefinitionSupportsFloatType() 
    {
zYne's avatar
zYne committed
275 276 277 278
        $a = array('type' => 'float', 'length' => 20, 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'FLOAT8');
    }
279 280
    public function testGetNativeDefinitionSupportsBooleanType()
    {
zYne's avatar
zYne committed
281 282 283 284
        $a = array('type' => 'boolean', 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BOOLEAN');
    }
285 286
    public function testGetNativeDefinitionSupportsDateType() 
    {
zYne's avatar
zYne committed
287 288 289 290
        $a = array('type' => 'date', 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'DATE');
    }
291 292
    public function testGetNativeDefinitionSupportsTimestampType() 
    {
zYne's avatar
zYne committed
293 294 295 296
        $a = array('type' => 'timestamp', 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TIMESTAMP without time zone');
    }
297 298
    public function testGetNativeDefinitionSupportsTimeType() 
    {
zYne's avatar
zYne committed
299 300 301 302
        $a = array('type' => 'time', 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TIME without time zone');
    }
303 304
    public function testGetNativeDefinitionSupportsClobType() 
    {
zYne's avatar
zYne committed
305 306 307 308
        $a = array('type' => 'clob');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
    }
309 310
    public function testGetNativeDefinitionSupportsBlobType() 
    {
zYne's avatar
zYne committed
311 312 313 314
        $a = array('type' => 'blob');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BYTEA');
    }
315 316
    public function testGetNativeDefinitionSupportsCharType() 
    {
zYne's avatar
zYne committed
317 318 319 320
        $a = array('type' => 'char', 'length' => 10);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(10)');
    }
321 322
    public function testGetNativeDefinitionSupportsVarcharType() 
    {
zYne's avatar
zYne committed
323 324 325 326
        $a = array('type' => 'varchar', 'length' => 10);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(10)');
    }
327 328
    public function testGetNativeDefinitionSupportsArrayType() 
    {
zYne's avatar
zYne committed
329 330 331 332
        $a = array('type' => 'array', 'length' => 40);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(40)');
    }
333 334
    public function testGetNativeDefinitionSupportsStringType() 
    {
zYne's avatar
zYne committed
335 336 337 338
        $a = array('type' => 'string');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
    }
339 340
    public function testGetNativeDefinitionSupportsArrayType2() 
    {
zYne's avatar
zYne committed
341 342 343 344
        $a = array('type' => 'array');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
    }
345 346
    public function testGetNativeDefinitionSupportsObjectType() 
    {
zYne's avatar
zYne committed
347 348 349 350
        $a = array('type' => 'object');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
    }
351
}