PgsqlTestCase.php 16.3 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
        $this->assertEqual($type, array('type' => array('blob', 'clob'),
                                        'length' => null, 
zYne's avatar
zYne committed
89
                                        'unsigned' => null,
zYne's avatar
zYne committed
90
                                        '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 192 193 194 195 196
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'interval'));

        $this->assertEqual($type, array('type' => array('string'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => false));

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

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

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

211 212 213
        
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'char', 'length' => 1));

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

219 220 221

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'bpchar', 'length' => 1));
        
zYne's avatar
zYne committed
222 223 224 225 226
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => true));

227
    }
228 229
    public function testGetPortableDeclarationSupportsNativeIntegerTypes() 
    {
230 231
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'smallint'));

zYne's avatar
zYne committed
232 233
        $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));
234

zYne's avatar
zYne committed
235 236 237 238 239
        $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
240

zYne's avatar
zYne committed
241 242 243 244
        $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));
245
    }
246 247
    public function testGetPortableDeclarationSupportsNativeBooleanTypes()
    {
zYne's avatar
zYne committed
248 249
        $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));
250
    }
251

252 253
    public function testGetNativeDefinitionSupportsIntegerType() 
    {
zYne's avatar
zYne committed
254 255 256 257 258 259 260 261 262 263 264 265
        $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');
    }
266 267
    public function testGetNativeDefinitionSupportsIntegerTypeWithAutoinc() 
    {
zYne's avatar
zYne committed
268 269
        $a = array('type' => 'integer', 'length' => 20, 'fixed' => false, 'autoincrement' => true);

zYne's avatar
zYne committed
270
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BIGSERIAL');
zYne's avatar
zYne committed
271 272 273

        $a['length'] = 4;

zYne's avatar
zYne committed
274
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'SERIAL');
zYne's avatar
zYne committed
275 276 277

        $a['length'] = 2;

zYne's avatar
zYne committed
278
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'SERIAL');
zYne's avatar
zYne committed
279
    }
280 281
    public function testGetNativeDefinitionSupportsFloatType() 
    {
zYne's avatar
zYne committed
282 283
        $a = array('type' => 'float', 'length' => 20, 'fixed' => false);

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

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BOOLEAN');
    }
292 293
    public function testGetNativeDefinitionSupportsDateType() 
    {
zYne's avatar
zYne committed
294 295 296 297
        $a = array('type' => 'date', 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'DATE');
    }
298 299
    public function testGetNativeDefinitionSupportsTimestampType() 
    {
zYne's avatar
zYne committed
300 301 302 303
        $a = array('type' => 'timestamp', 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TIMESTAMP without time zone');
    }
304 305
    public function testGetNativeDefinitionSupportsTimeType() 
    {
zYne's avatar
zYne committed
306 307 308 309
        $a = array('type' => 'time', 'fixed' => false);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TIME without time zone');
    }
310 311
    public function testGetNativeDefinitionSupportsClobType() 
    {
zYne's avatar
zYne committed
312 313 314 315
        $a = array('type' => 'clob');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
    }
316 317
    public function testGetNativeDefinitionSupportsBlobType() 
    {
zYne's avatar
zYne committed
318 319 320 321
        $a = array('type' => 'blob');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BYTEA');
    }
322 323
    public function testGetNativeDefinitionSupportsCharType() 
    {
zYne's avatar
zYne committed
324 325 326 327
        $a = array('type' => 'char', 'length' => 10);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(10)');
    }
328 329
    public function testGetNativeDefinitionSupportsVarcharType() 
    {
zYne's avatar
zYne committed
330 331 332 333
        $a = array('type' => 'varchar', 'length' => 10);

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

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(40)');
    }
340 341
    public function testGetNativeDefinitionSupportsStringType() 
    {
zYne's avatar
zYne committed
342 343 344 345
        $a = array('type' => 'string');

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

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
    }
352 353
    public function testGetNativeDefinitionSupportsObjectType() 
    {
zYne's avatar
zYne committed
354 355 356 357
        $a = array('type' => 'object');

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