Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
78d43097
Commit
78d43097
authored
Jun 20, 2009
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Testing all dbal types and making sure they are fully implemented
parent
ab2b3999
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
295 additions
and
53 deletions
+295
-53
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+5
-0
MsSqlPlatform.php
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
+8
-0
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+8
-0
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+8
-0
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+8
-0
ArrayType.php
lib/Doctrine/DBAL/Types/ArrayType.php
+16
-1
BigIntType.php
lib/Doctrine/DBAL/Types/BigIntType.php
+1
-1
BooleanType.php
lib/Doctrine/DBAL/Types/BooleanType.php
+10
-10
CharType.php
lib/Doctrine/DBAL/Types/CharType.php
+0
-13
DateTimeType.php
lib/Doctrine/DBAL/Types/DateTimeType.php
+0
-13
DateType.php
lib/Doctrine/DBAL/Types/DateType.php
+0
-13
DecimalType.php
lib/Doctrine/DBAL/Types/DecimalType.php
+1
-1
IntegerType.php
lib/Doctrine/DBAL/Types/IntegerType.php
+1
-1
ObjectType.php
lib/Doctrine/DBAL/Types/ObjectType.php
+31
-0
Type.php
lib/Doctrine/DBAL/Types/Type.php
+3
-0
AllTests.php
tests/Doctrine/Tests/DBAL/AllTests.php
+6
-0
ArrayTest.php
tests/Doctrine/Tests/DBAL/Types/ArrayTest.php
+35
-0
BooleanTest.php
tests/Doctrine/Tests/DBAL/Types/BooleanTest.php
+35
-0
DecimalTest.php
tests/Doctrine/Tests/DBAL/Types/DecimalTest.php
+28
-0
IntegerTest.php
tests/Doctrine/Tests/DBAL/Types/IntegerTest.php
+28
-0
ObjectTest.php
tests/Doctrine/Tests/DBAL/Types/ObjectTest.php
+35
-0
SmallIntTest.php
tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php
+28
-0
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
78d43097
...
...
@@ -1529,6 +1529,11 @@ abstract class AbstractPlatform
*/
abstract
public
function
getVarcharTypeDeclarationSql
(
array
$field
);
public
function
getBooleanTypeDeclarationSql
(
array
$field
)
{
return
$this
->
getIntegerTypeDeclarationSql
(
$field
);
}
/**
* Get the platform name for this instance
*
...
...
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
View file @
78d43097
...
...
@@ -408,6 +408,14 @@ class MsSqlPlatform extends AbstractPlatform
return
'CHAR('
.
strlen
(
'YYYY-MM-DD HH:MM:SS'
)
.
')'
;
}
/**
* @override
*/
public
function
getBooleanTypeDeclarationSql
(
array
$field
)
{
return
'BIT'
;
}
/**
* Get the platform name for this instance
*
...
...
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
78d43097
...
...
@@ -266,6 +266,14 @@ class MySqlPlatform extends AbstractPlatform
return
'DATETIME'
;
}
/**
* @override
*/
public
function
getBooleanTypeDeclarationSql
(
array
$field
)
{
return
'TINYINT(1)'
;
}
/**
* Obtain DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration to be used in statements like CREATE TABLE.
...
...
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
78d43097
...
...
@@ -184,6 +184,14 @@ class OraclePlatform extends AbstractPlatform
return
'DATE'
;
}
/**
* @override
*/
public
function
getBooleanTypeDeclarationSql
(
array
$field
)
{
return
'NUMBER(1)'
;
}
/**
* @override
*/
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
78d43097
...
...
@@ -698,6 +698,14 @@ class PostgreSqlPlatform extends AbstractPlatform
return
'TIMESTAMP without time zone'
;
}
/**
* @override
*/
public
function
getBooleanTypeDeclarationSql
(
array
$field
)
{
return
'BOOLEAN'
;
}
/**
* @override
*/
...
...
lib/Doctrine/DBAL/Types/ArrayType.php
View file @
78d43097
...
...
@@ -3,12 +3,27 @@
namespace
Doctrine\DBAL\Types
;
/**
* Type that maps a PHP array to a
VARCHAR
SQL type.
* Type that maps a PHP array to a
clob
SQL type.
*
* @since 2.0
*/
class
ArrayType
extends
Type
{
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$platform
->
getClobDeclarationSql
(
$fieldDeclaration
);
}
public
function
convertToDatabaseValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
serialize
(
$value
);
}
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
unserialize
(
$value
);
}
public
function
getName
()
{
return
'Array'
;
...
...
lib/Doctrine/DBAL/Types/BigIntType.php
View file @
78d43097
...
...
@@ -12,7 +12,7 @@ class BigIntType extends Type
{
public
function
getName
()
{
return
"BigInteger"
;
return
'BigInteger'
;
}
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
...
...
lib/Doctrine/DBAL/Types/BooleanType.php
View file @
78d43097
...
...
@@ -9,23 +9,23 @@ namespace Doctrine\DBAL\Types;
*/
class
BooleanType
extends
Type
{
/**
* {@inheritdoc}
*
* @override
*/
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$platform
->
getBooleanDeclarationSql
();
}
public
function
convertToDatabaseValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$platform
->
convertBooleans
(
$value
);
}
/**
* {@inheritdoc}
*
* @override
*/
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
(
bool
)
$value
;
}
public
function
getName
()
{
return
'boolean'
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Types/CharType.php
deleted
100644 → 0
View file @
ab2b3999
<?php
namespace
Doctrine\DBAL\Types
;
/**
* Type that maps a database CHAR to a PHP string.
*
* @author robo
*/
class
CharType
{
//put your code here
}
\ No newline at end of file
lib/Doctrine/DBAL/Types/DateTimeType.php
View file @
78d43097
...
...
@@ -14,29 +14,16 @@ class DateTimeType extends Type
return
'DateTime'
;
}
/**
* {@inheritdoc}
*/
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$platform
->
getDateTimeTypeDeclarationSql
(
$fieldDeclaration
);
}
/**
* {@inheritdoc}
*
* @override
*/
public
function
convertToDatabaseValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$value
->
format
(
$platform
->
getDateTimeFormatString
());
}
/**
* {@inheritdoc}
*
* @override
*/
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
\DateTime
::
createFromFormat
(
$platform
->
getDateTimeFormatString
(),
$value
);
...
...
lib/Doctrine/DBAL/Types/DateType.php
View file @
78d43097
...
...
@@ -14,29 +14,16 @@ class DateType extends Type
return
'Date'
;
}
/**
* {@inheritdoc}
*/
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$platform
->
getDateTypeDeclarationSql
(
$fieldDeclaration
);
}
/**
* {@inheritdoc}
*
* @override
*/
public
function
convertToDatabaseValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$value
->
format
(
$platform
->
getDateFormatString
());
}
/**
* {@inheritdoc}
*
* @override
*/
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
\DateTime
::
createFromFormat
(
$platform
->
getDateFormatString
(),
$value
);
...
...
lib/Doctrine/DBAL/Types/DecimalType.php
View file @
78d43097
...
...
@@ -11,7 +11,7 @@ class DecimalType extends Type
{
public
function
getName
()
{
return
"Decimal"
;
return
'Decimal'
;
}
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
...
...
lib/Doctrine/DBAL/Types/IntegerType.php
View file @
78d43097
...
...
@@ -10,7 +10,7 @@ class IntegerType extends Type
{
public
function
getName
()
{
return
"Integer"
;
return
'Integer'
;
}
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
...
...
lib/Doctrine/DBAL/Types/ObjectType.php
0 → 100644
View file @
78d43097
<?php
namespace
Doctrine\DBAL\Types
;
/**
* Type that maps a PHP object to a clob SQL type.
*
* @since 2.0
*/
class
ObjectType
extends
Type
{
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$platform
->
getClobDeclarationSql
(
$fieldDeclaration
);
}
public
function
convertToDatabaseValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
serialize
(
$value
);
}
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
unserialize
(
$value
);
}
public
function
getName
()
{
return
'Object'
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Types/Type.php
View file @
78d43097
...
...
@@ -26,6 +26,9 @@ abstract class Type
private
static
$_typeObjects
=
array
();
private
static
$_typesMap
=
array
(
'array'
=>
'Doctrine\DBAL\Types\ArrayType'
,
'object'
=>
'Doctrine\DBAL\Types\ObjectType'
,
'boolean'
=>
'Doctrine\DBAL\Types\BooleanType'
,
'integer'
=>
'Doctrine\DBAL\Types\IntegerType'
,
'int'
=>
'Doctrine\DBAL\Types\IntegerType'
,
'smallint'
=>
'Doctrine\DBAL\Types\SmallIntType'
,
...
...
tests/Doctrine/Tests/DBAL/AllTests.php
View file @
78d43097
...
...
@@ -30,9 +30,15 @@ class AllTests
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Platforms\MsSqlPlatformTest'
);
// Type tests
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\ArrayTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\ObjectTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\DateTimeTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\DateTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\TimeTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\BooleanTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\DecimalTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\IntegerTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\SmallIntTest'
);
$suite
->
addTest
(
Functional\AllTests
::
suite
());
...
...
tests/Doctrine/Tests/DBAL/Types/ArrayTest.php
0 → 100644
View file @
78d43097
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
ArrayTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$_platform
,
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
\Doctrine\Tests\DBAL\Mocks\MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'array'
);
}
public
function
testArrayConvertsToDatabaseValue
()
{
$this
->
assertTrue
(
is_string
(
$this
->
_type
->
convertToDatabaseValue
(
array
(),
$this
->
_platform
))
);
}
public
function
testArrayConvertsToPHPValue
()
{
$this
->
assertTrue
(
is_array
(
$this
->
_type
->
convertToPHPValue
(
serialize
(
array
()),
$this
->
_platform
))
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Types/BooleanTest.php
0 → 100644
View file @
78d43097
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
BooleanTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$_platform
,
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
\Doctrine\Tests\DBAL\Mocks\MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'boolean'
);
}
public
function
testBooleanConvertsToDatabaseValue
()
{
$this
->
assertTrue
(
is_integer
(
$this
->
_type
->
convertToDatabaseValue
(
1
,
$this
->
_platform
))
);
}
public
function
testBooleanConvertsToPHPValue
()
{
$this
->
assertTrue
(
is_bool
(
$this
->
_type
->
convertToPHPValue
(
0
,
$this
->
_platform
))
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Types/DecimalTest.php
0 → 100644
View file @
78d43097
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
DecimalTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$_platform
,
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
\Doctrine\Tests\DBAL\Mocks\MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'decimal'
);
}
public
function
testDecimalConvertsToPHPValue
()
{
$this
->
assertTrue
(
is_float
(
$this
->
_type
->
convertToPHPValue
(
'5.5'
,
$this
->
_platform
))
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Types/IntegerTest.php
0 → 100644
View file @
78d43097
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
IntegerTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$_platform
,
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
\Doctrine\Tests\DBAL\Mocks\MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'integer'
);
}
public
function
testDecimalConvertsToPHPValue
()
{
$this
->
assertTrue
(
is_integer
(
$this
->
_type
->
convertToPHPValue
(
'1'
,
$this
->
_platform
))
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Types/ObjectTest.php
0 → 100644
View file @
78d43097
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
ObjectTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$_platform
,
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
\Doctrine\Tests\DBAL\Mocks\MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'object'
);
}
public
function
testObjectConvertsToDatabaseValue
()
{
$this
->
assertTrue
(
is_string
(
$this
->
_type
->
convertToDatabaseValue
(
new
\stdClass
(),
$this
->
_platform
))
);
}
public
function
testObjectConvertsToPHPValue
()
{
$this
->
assertTrue
(
is_object
(
$this
->
_type
->
convertToPHPValue
(
serialize
(
new
\stdClass
),
$this
->
_platform
))
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php
0 → 100644
View file @
78d43097
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
SmallIntTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$_platform
,
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
\Doctrine\Tests\DBAL\Mocks\MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'smallint'
);
}
public
function
testDecimalConvertsToPHPValue
()
{
$this
->
assertTrue
(
is_integer
(
$this
->
_type
->
convertToPHPValue
(
'1'
,
$this
->
_platform
))
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment