MssqlTestCase.php 10.2 KB
Newer Older
zYne's avatar
zYne committed
1
<?php
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*
 *  $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>.
 */

/**
 * 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
 * @link        www.phpdoctrine.com
 * @since       1.0
 * @version     $Revision$
 */
33 34 35 36
class Doctrine_DataDict_Mssql_TestCase extends Doctrine_UnitTestCase 
{
    public function testGetPortableDeclarationForUnknownNativeTypeThrowsException() 
    {
37 38 39
        try {
            $this->dataDict->getPortableDeclaration(array('type' => 'some_unknown_type'));
            $this->fail();
zYne's avatar
zYne committed
40
        } catch(Doctrine_DataDict_Exception $e) {
41 42 43
            $this->pass();
        }
    }
44 45
    public function testGetPortableDeclarationSupportsNativeBitType() 
    {
46 47
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'bit'));
        
zYne's avatar
zYne committed
48 49 50 51
        $this->assertEqual($type, array('type' => array('boolean'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
52
    }
53 54
    public function testGetPortableDeclarationSupportsNativeStringTypes() 
    {
55 56
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'text'));

zYne's avatar
zYne committed
57 58 59 60
        $this->assertEqual($type, array('type' => array('string', 'clob'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
61 62

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

zYne's avatar
zYne committed
64 65 66 67
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => true));
68 69 70

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'varchar', 'length' => 1));
        
zYne's avatar
zYne committed
71 72 73 74
        $this->assertEqual($type, array('type' => array('string', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => false));
75
    }
76 77
    public function testGetPortableDeclarationSupportsNativeBlobTypes() 
    {
78 79
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'image'));
        
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' => 'varbinary'));

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

        $type = $this->dataDict->getPortableDeclaration(array('type' => 'int', 'length' => 1));
        
zYne's avatar
zYne committed
103 104 105 106
        $this->assertEqual($type, array('type' => array('integer', 'boolean'),
                                        'length' => 1,
                                        'unsigned' => null,
                                        'fixed' => null));
107
    }
108 109
    public function testGetPortableDeclarationSupportsNativeTimestampType() 
    {
110 111
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'datetime'));
        
zYne's avatar
zYne committed
112 113 114 115
        $this->assertEqual($type, array('type' => array('timestamp'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
116
    }
117 118
    public function testGetPortableDeclarationSupportsNativeDecimalTypes() 
    {
119 120
        $type = $this->dataDict->getPortableDeclaration(array('type' => 'decimal'));

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

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

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

zYne's avatar
zYne committed
137 138 139 140
        $this->assertEqual($type, array('type' => array('float'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
141 142 143

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

zYne's avatar
zYne committed
144 145 146 147
        $this->assertEqual($type, array('type' => array('float'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
148 149 150

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

zYne's avatar
zYne committed
151 152 153 154
        $this->assertEqual($type, array('type' => array('float'),
                                        'length' => null,
                                        'unsigned' => null,
                                        'fixed' => null));
zYne's avatar
zYne committed
155
    }
156 157
    public function testGetNativeDefinitionSupportsIntegerType() 
    {
zYne's avatar
zYne committed
158 159
        $a = array('type' => 'integer', 'length' => 20, 'fixed' => false);

160
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INT');
zYne's avatar
zYne committed
161 162 163 164 165 166 167
        
        $a['length'] = 4;

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

        $a['length'] = 2;

168
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'INT');
zYne's avatar
zYne committed
169 170
    }

171 172
    public function testGetNativeDefinitionSupportsFloatType() 
    {
zYne's avatar
zYne committed
173 174
        $a = array('type' => 'float', 'length' => 20, 'fixed' => false);

175
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'FLOAT');
zYne's avatar
zYne committed
176
    }
177 178
    public function testGetNativeDefinitionSupportsBooleanType() 
    {
zYne's avatar
zYne committed
179 180
        $a = array('type' => 'boolean', 'fixed' => false);

181
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'BIT');
zYne's avatar
zYne committed
182
    }
183 184
    public function testGetNativeDefinitionSupportsDateType() 
    {
zYne's avatar
zYne committed
185 186
        $a = array('type' => 'date', 'fixed' => false);

187
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(10)');
zYne's avatar
zYne committed
188
    }
189 190
    public function testGetNativeDefinitionSupportsTimestampType() 
    {
zYne's avatar
zYne committed
191 192
        $a = array('type' => 'timestamp', 'fixed' => false);

193
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(19)');
zYne's avatar
zYne committed
194
    }
195 196
    public function testGetNativeDefinitionSupportsTimeType() 
    {
zYne's avatar
zYne committed
197 198
        $a = array('type' => 'time', 'fixed' => false);

199
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(8)');
zYne's avatar
zYne committed
200
    }
201 202
    public function testGetNativeDefinitionSupportsClobType() 
    {
zYne's avatar
zYne committed
203 204
        $a = array('type' => 'clob');

205
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
zYne's avatar
zYne committed
206
    }
207 208
    public function testGetNativeDefinitionSupportsBlobType() 
    {
zYne's avatar
zYne committed
209 210
        $a = array('type' => 'blob');

211
        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'IMAGE');
zYne's avatar
zYne committed
212
    }
213 214
    public function testGetNativeDefinitionSupportsCharType() 
    {
zYne's avatar
zYne committed
215 216 217 218
        $a = array('type' => 'char', 'length' => 10);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'CHAR(10)');
    }
219 220
    public function testGetNativeDefinitionSupportsVarcharType() 
    {
zYne's avatar
zYne committed
221 222 223 224
        $a = array('type' => 'varchar', 'length' => 10);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(10)');
    }
225 226
    public function testGetNativeDefinitionSupportsArrayType() 
    {
zYne's avatar
zYne committed
227 228 229 230
        $a = array('type' => 'array', 'length' => 40);

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'VARCHAR(40)');
    }
231 232
    public function testGetNativeDefinitionSupportsStringType() 
    {
zYne's avatar
zYne committed
233 234 235 236
        $a = array('type' => 'string');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
    }
237 238
    public function testGetNativeDefinitionSupportsArrayType2() 
    {
zYne's avatar
zYne committed
239 240 241 242
        $a = array('type' => 'array');

        $this->assertEqual($this->dataDict->getNativeDeclaration($a), 'TEXT');
    }
243 244
    public function testGetNativeDefinitionSupportsObjectType() 
    {
zYne's avatar
zYne committed
245 246 247 248 249
        $a = array('type' => 'object');

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