MysqlTestCase.php 15 KB
Newer Older
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_DataDict_Mysql_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 33
 * @since       1.0
 * @version     $Revision$
 */
class Doctrine_DataDict_Mysql_TestCase extends Doctrine_UnitTestCase {
34 35
    public function testGetCharsetFieldDeclarationReturnsValidSql() 
    {
zYne's avatar
zYne committed
36 37
        $this->assertEqual($this->dataDict->getCharsetFieldDeclaration('UTF-8'), 'CHARACTER SET UTF-8');
    }
38 39
    public function testGetCollationFieldDeclarationReturnsValidSql() 
    {
zYne's avatar
zYne committed
40 41
        $this->assertEqual($this->dataDict->getCollationFieldDeclaration('xx'), 'COLLATE xx');
    }
42 43
    public function testGetPortableDeclarationForUnknownNativeTypeThrowsException() 
    {
zYne's avatar
zYne committed
44 45 46
        try {
            $this->dataDict->getPortableDeclaration(array('type' => 'some_unknown_type'));
            $this->fail();
zYne's avatar
zYne committed
47
        } catch(Doctrine_DataDict_Exception $e) {
zYne's avatar
zYne committed
48 49 50
            $this->pass();
        }
    }
51 52
    public function testGetPortableDeclarationSupportsNativeIntegerTypes() 
    {
zYne's avatar
zYne committed
53 54 55
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'tinyint'));


zYne's avatar
zYne committed
56 57 58 59
        $this->assertEqual($type, array('type' => array('integer', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
60 61
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'smallint unsigned'));

zYne's avatar
zYne committed
62 63 64 65
        $this->assertEqual($type, array('type' => array('integer'), 
                                        'length' => 2, 
                                        'unsigned' => true,
                                        'fixed' => null));
zYne's avatar
zYne committed
66 67 68

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

zYne's avatar
zYne committed
69 70 71 72
        $this->assertEqual($type, array('type' => array('integer'), 
                                        'length' => 3,
                                        'unsigned' => true,
                                        'fixed' => null));
zYne's avatar
zYne committed
73 74 75

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

zYne's avatar
zYne committed
76 77 78 79
        $this->assertEqual($type, array('type' => array('integer'), 
                                        'length' => 4,
                                        'unsigned' => true,
                                        'fixed' => null));
zYne's avatar
zYne committed
80 81 82

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

zYne's avatar
zYne committed
83 84 85 86
        $this->assertEqual($type, array('type' => array('integer'), 
                                        'length' => 4,
                                        'unsigned' => true,
                                        'fixed' => null));
zYne's avatar
zYne committed
87 88 89

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

zYne's avatar
zYne committed
90 91 92 93
        $this->assertEqual($type, array('type' => array('integer'), 
                                        'length' => 8,
                                        'unsigned' => true,
                                        'fixed' => null));
94
    }
95 96
    public function testGetPortableDeclarationSupportsNativeStringTypes() 
    {
zYne's avatar
zYne committed
97 98
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'text'));

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

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

zYne's avatar
zYne committed
106 107 108 109
        $this->assertEqual($type, array('type' => array('string', 'clob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => false));
zYne's avatar
zYne committed
110 111 112
        
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'mediumtext'));

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

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

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

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

zYne's avatar
zYne committed
127 128 129 130
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => true));
zYne's avatar
zYne committed
131 132 133

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

zYne's avatar
zYne committed
134 135 136 137
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => false));
zYne's avatar
zYne committed
138
    }
139 140
    public function testGetPortableDeclarationSupportsNativeFloatTypes() 
    {
zYne's avatar
zYne committed
141 142
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'float'));
        
zYne's avatar
zYne committed
143 144 145 146
        $this->assertEqual($type, array('type' => array('float'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
147 148 149

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

zYne's avatar
zYne committed
150 151 152 153
        $this->assertEqual($type, array('type' => array('float'),
                                        'length' => null,
                                        'unsigned' => true,
                                        'fixed' => null));
zYne's avatar
zYne committed
154 155 156

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'double'));
        
zYne's avatar
zYne committed
157 158 159 160
        $this->assertEqual($type, array('type' => array('float'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
161 162
    }

163 164
    public function testGetPortableDeclarationSupportsNativeDateType() 
    {
zYne's avatar
zYne committed
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));
zYne's avatar
zYne committed
171
    }
172 173
    public function testGetPortableDeclarationSupportsNativeDecimalTypes() 
    {
zYne's avatar
zYne committed
174 175
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'decimal'));
        
zYne's avatar
zYne committed
176 177 178 179
        $this->assertEqual($type, array('type' => array('decimal'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
180 181 182

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'unknown'));
        
zYne's avatar
zYne committed
183 184 185 186
        $this->assertEqual($type, array('type' => array('decimal'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
187 188 189
        
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'numeric'));
        
zYne's avatar
zYne committed
190 191 192 193
        $this->assertEqual($type, array('type' => array('decimal'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
194 195
    }

196 197
    public function testGetPortableDeclarationSupportsNativeTimestampTypes() 
    {
zYne's avatar
zYne committed
198 199
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'timestamp'));
        
zYne's avatar
zYne committed
200 201 202 203
        $this->assertEqual($type, array('type' => array('timestamp'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
204 205 206
        
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'datetime'));
        
zYne's avatar
zYne committed
207 208 209 210
        $this->assertEqual($type, array('type' => array('timestamp'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
211
    }
212 213
    public function testGetPortableDeclarationSupportsNativeYearType() 
    {
zYne's avatar
zYne committed
214 215
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'year'));

zYne's avatar
zYne committed
216 217 218 219 220
        
        $this->assertEqual($type, array('type' => array('integer', 'date'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
221
    }
222 223
    public function testGetPortableDeclarationSupportsNativeBlobTypes() 
    {
zYne's avatar
zYne committed
224 225
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'blob'));

zYne's avatar
zYne committed
226 227 228 229
        $this->assertEqual($type, array('type' => array('blob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
230 231 232

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

zYne's avatar
zYne committed
233 234 235 236
        $this->assertEqual($type, array('type' => array('blob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
237 238 239
        
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'tinyblob'));

zYne's avatar
zYne committed
240 241 242 243
        $this->assertEqual($type, array('type' => array('blob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
244 245 246

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

zYne's avatar
zYne committed
247 248 249 250
        $this->assertEqual($type, array('type' => array('blob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
251 252
    }

253 254
    public function testGetNativeDefinitionSupportsIntegerType() 
    {
255 256 257 258 259 260
        $a = array('type' => 'integer', 'length' => 20, 'fixed' => false);

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

zYne's avatar
zYne committed
261
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'INT');
262 263 264

        $a['length'] = 2;

zYne's avatar
zYne committed
265
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'SMALLINT');
266 267
    }

268 269
    public function testGetNativeDeclarationSupportsFloatType() 
    {
270 271
        $a = array('type' => 'float', 'length' => 20, 'fixed' => false);

zYne's avatar
zYne committed
272
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'DOUBLE');
273
    }
274 275
    public function testGetNativeDeclarationSupportsBooleanType() 
    {
276 277
        $a = array('type' => 'boolean', 'fixed' => false);

zYne's avatar
zYne committed
278
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TINYINT(1)');
279
    }
280 281
    public function testGetNativeDeclarationSupportsDateType() 
    {
282 283
        $a = array('type' => 'date', 'fixed' => false);

zYne's avatar
zYne committed
284
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'DATE');
285
    }
286 287
    public function testGetNativeDeclarationSupportsTimestampType() 
    {
288 289
        $a = array('type' => 'timestamp', 'fixed' => false);

zYne's avatar
zYne committed
290
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'DATETIME');
291
    }
292 293
    public function testGetNativeDeclarationSupportsTimeType() 
    {
294 295
        $a = array('type' => 'time', 'fixed' => false);

zYne's avatar
zYne committed
296
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TIME');
297
    }
298 299
    public function testGetNativeDeclarationSupportsClobType() 
    {
300 301
        $a = array('type' => 'clob');

zYne's avatar
zYne committed
302
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'LONGTEXT');
303
    }
304 305
    public function testGetNativeDeclarationSupportsBlobType() 
    {
306 307
        $a = array('type' => 'blob');

zYne's avatar
zYne committed
308
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'LONGBLOB');
309
    }
310 311
    public function testGetNativeDeclarationSupportsCharType() 
    {
312 313
        $a = array('type' => 'char', 'length' => 10);

zYne's avatar
zYne committed
314
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'CHAR(10)');
315
    }
316 317
    public function testGetNativeDeclarationSupportsVarcharType() 
    {
318 319
        $a = array('type' => 'varchar', 'length' => 10);

zYne's avatar
zYne committed
320
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'VARCHAR(10)');
321
    }
322 323
    public function testGetNativeDeclarationSupportsArrayType() 
    {
324 325
        $a = array('type' => 'array', 'length' => 40);

zYne's avatar
zYne committed
326
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'VARCHAR(40)');
327
    }
328 329
    public function testGetNativeDeclarationSupportsStringType() 
    {
330 331
        $a = array('type' => 'string');

zYne's avatar
zYne committed
332
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TEXT');
333
    }
334 335
    public function testGetNativeDeclarationSupportsStringTypeWithLongLength() 
    {
336 337 338 339
        $a = array('type' => 'string', 'length' => 2000);

        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TEXT');
    }
340 341
    public function testGetNativeDeclarationSupportsArrayType2() 
    {
342 343
        $a = array('type' => 'array');

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

zYne's avatar
zYne committed
350
        $this->assertEqual($this->dataDict->GetNativeDeclaration($a), 'TEXT');
351
    }
zYne's avatar
zYne committed
352

353
}