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
1442262d
Commit
1442262d
authored
Jun 26, 2010
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge DBAL-22 into master
parents
fc28444a
687e197a
Changes
25
Show whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
425 additions
and
36 deletions
+425
-36
OCI8Statement.php
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
+1
-1
OracleSessionInit.php
lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php
+1
-1
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+22
-3
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+1
-1
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+20
-2
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+10
-2
AbstractSchemaManager.php
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
+13
-2
Column.php
lib/Doctrine/DBAL/Schema/Column.php
+1
-1
ArrayType.php
lib/Doctrine/DBAL/Types/ArrayType.php
+5
-1
ConversionException.php
lib/Doctrine/DBAL/Types/ConversionException.php
+48
-0
DateTimeType.php
lib/Doctrine/DBAL/Types/DateTimeType.php
+5
-3
DateTimeTzType.php
lib/Doctrine/DBAL/Types/DateTimeTzType.php
+76
-0
DateType.php
lib/Doctrine/DBAL/Types/DateType.php
+5
-3
ObjectType.php
lib/Doctrine/DBAL/Types/ObjectType.php
+5
-1
TimeType.php
lib/Doctrine/DBAL/Types/TimeType.php
+5
-3
Type.php
lib/Doctrine/DBAL/Types/Type.php
+2
-0
AllTests.php
tests/Doctrine/Tests/DBAL/AllTests.php
+1
-0
AllTests.php
tests/Doctrine/Tests/DBAL/Functional/AllTests.php
+16
-5
TypeConversionTest.php
tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php
+90
-0
ArrayTest.php
tests/Doctrine/Tests/DBAL/Types/ArrayTest.php
+14
-0
DateTest.php
tests/Doctrine/Tests/DBAL/Types/DateTest.php
+6
-0
DateTimeTest.php
tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php
+15
-7
DateTimeTzTest.php
tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php
+45
-0
ObjectTest.php
tests/Doctrine/Tests/DBAL/Types/ObjectTest.php
+12
-0
TimeTest.php
tests/Doctrine/Tests/DBAL/Types/TimeTest.php
+6
-0
No files found.
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
View file @
1442262d
...
...
@@ -186,7 +186,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
*/
public
function
fetchColumn
(
$columnIndex
=
0
)
{
$row
=
oci_fetch_
row
(
$this
->
_sth
);
$row
=
oci_fetch_
array
(
$this
->
_sth
,
OCI_NUM
|
OCI_RETURN_NULLS
|
OCI_RETURN_LOBS
);
return
$row
[
$columnIndex
];
}
...
...
lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php
View file @
1442262d
...
...
@@ -45,7 +45,7 @@ class OracleSessionInit implements EventSubscriber
{
protected
$_defaultSessionVars
=
array
(
'NLS_TIME_FORMAT'
=>
"HH24:MI:SS"
,
'NLS_DATE_FORMAT'
=>
"YYYY-MM-DD"
,
'NLS_DATE_FORMAT'
=>
"YYYY-MM-DD
HH24:MI:SS
"
,
'NLS_TIMESTAMP_FORMAT'
=>
"YYYY-MM-DD HH24:MI:SS"
,
'NLS_TIMESTAMP_TZ_FORMAT'
=>
"YYYY-MM-DD HH24:MI:SS TZH:TZM"
,
);
...
...
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
1442262d
...
...
@@ -1668,6 +1668,17 @@ abstract class AbstractPlatform
throw
DBALException
::
notSupported
(
__METHOD__
);
}
/**
* Obtain DBMS specific SQL to be used to create datetime with timezone offset fields.
*
* @param array $fieldDeclaration
*/
public
function
getDateTimeTzTypeDeclarationSQL
(
array
$fieldDeclaration
)
{
return
$this
->
getDateTimeTypeDeclarationSQL
(
$fieldDeclaration
);
}
/**
* Obtain DBMS specific SQL to be used to create date fields in statements
* like CREATE TABLE.
...
...
@@ -1841,15 +1852,23 @@ abstract class AbstractPlatform
* the format of a stored datetime value of this platform.
*
* @return string The format string.
*
* @todo We need to get the specific format for each dbms and override this
* function for each platform
*/
public
function
getDateTimeFormatString
()
{
return
'Y-m-d H:i:s'
;
}
/**
* Gets the format string, as accepted by the date() function, that describes
* the format of a stored datetime with timezone value of this platform.
*
* @return string The format string.
*/
public
function
getDateTimeTzFormatString
()
{
return
'Y-m-d H:i:s'
;
}
/**
* Gets the format string, as accepted by the date() function, that describes
* the format of a stored date value of this platform.
...
...
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
1442262d
...
...
@@ -172,7 +172,7 @@ class MySqlPlatform extends AbstractPlatform
/** @override */
public
function
getClobTypeDeclarationSQL
(
array
$field
)
{
if
(
!
empty
(
$field
[
'length'
]))
{
if
(
!
empty
(
$field
[
'length'
])
&&
is_numeric
(
$field
[
'length'
])
)
{
$length
=
$field
[
'length'
];
if
(
$length
<=
255
)
{
return
'TINYTEXT'
;
...
...
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
1442262d
...
...
@@ -192,6 +192,14 @@ class OraclePlatform extends AbstractPlatform
* @override
*/
public
function
getDateTimeTypeDeclarationSQL
(
array
$fieldDeclaration
)
{
return
'TIMESTAMP(0)'
;
}
/**
* @override
*/
public
function
getDateTimeTzTypeDeclarationSQL
(
array
$fieldDeclaration
)
{
return
'TIMESTAMP(0) WITH TIME ZONE'
;
}
...
...
@@ -602,11 +610,21 @@ LEFT JOIN all_cons_columns r_cols
return
"CREATE GLOBAL TEMPORARY TABLE"
;
}
public
function
getDateTimeFormatString
()
public
function
getDateTime
Tz
FormatString
()
{
return
'Y-m-d H:i:sP'
;
}
public
function
getDateFormatString
()
{
return
'Y-m-d 00:00:00'
;
}
public
function
getTimeFormatString
()
{
return
'1900-01-01 H:i:s'
;
}
public
function
fixSchemaElementName
(
$schemaElementName
)
{
if
(
strlen
(
$schemaElementName
)
>
30
)
{
...
...
@@ -672,7 +690,7 @@ LEFT JOIN all_cons_columns r_cols
'char'
=>
'string'
,
'nchar'
=>
'string'
,
'date'
=>
'datetime'
,
'timestamp'
=>
'datetime'
,
'timestamp'
=>
'datetime
tz
'
,
'float'
=>
'decimal'
,
'long'
=>
'string'
,
'clob'
=>
'text'
,
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
1442262d
...
...
@@ -534,6 +534,14 @@ class PostgreSqlPlatform extends AbstractPlatform
* @override
*/
public
function
getDateTimeTypeDeclarationSQL
(
array
$fieldDeclaration
)
{
return
'TIMESTAMP(0) WITHOUT TIME ZONE'
;
}
/**
* @override
*/
public
function
getDateTimeTzTypeDeclarationSQL
(
array
$fieldDeclaration
)
{
return
'TIMESTAMP(0) WITH TIME ZONE'
;
}
...
...
@@ -614,7 +622,7 @@ class PostgreSqlPlatform extends AbstractPlatform
return
strtolower
(
$column
);
}
public
function
getDateTimeFormatString
()
public
function
getDateTime
Tz
FormatString
()
{
return
'Y-m-d H:i:sO'
;
}
...
...
@@ -669,7 +677,7 @@ class PostgreSqlPlatform extends AbstractPlatform
'date'
=>
'date'
,
'datetime'
=>
'datetime'
,
'timestamp'
=>
'datetime'
,
'timestamptz'
=>
'datetime'
,
'timestamptz'
=>
'datetime
tz
'
,
'time'
=>
'time'
,
'timetz'
=>
'time'
,
'float'
=>
'decimal'
,
...
...
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
View file @
1442262d
<?php
/*
* $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
...
...
@@ -171,6 +169,19 @@ abstract class AbstractSchemaManager
return
$this
->
_getPortableTableIndexesList
(
$tableIndexes
,
$table
);
}
/**
* Return true if all the given tables exist.
*
* @param array $tableNames
* @return bool
*/
public
function
tablesExist
(
$tableNames
)
{
$tableNames
=
array_map
(
'strtolower'
,
(
array
)
$tableNames
);
return
count
(
$tableNames
)
==
count
(
\array_intersect
(
$tableNames
,
array_map
(
'strtolower'
,
$this
->
listTableNames
())));
}
/**
* Return a list of all tables in the current database
*
...
...
lib/Doctrine/DBAL/Schema/Column.php
View file @
1442262d
...
...
@@ -41,7 +41,7 @@ class Column extends AbstractAsset
/**
* @var int
*/
protected
$_length
=
255
;
protected
$_length
=
null
;
/**
* @var int
...
...
lib/Doctrine/DBAL/Types/ArrayType.php
View file @
1442262d
...
...
@@ -41,7 +41,11 @@ class ArrayType extends Type
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
$value
=
(
is_resource
(
$value
))
?
stream_get_contents
(
$value
)
:
$value
;
return
unserialize
(
$value
);
$val
=
unserialize
(
$value
);
if
(
$val
===
false
)
{
throw
ConversionException
::
conversionFailed
(
$value
,
$this
->
getName
());
}
return
$val
;
}
public
function
getName
()
...
...
lib/Doctrine/DBAL/Types/ConversionException.php
0 → 100644
View file @
1442262d
<?php
/*
* 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.doctrine-project.org>.
*/
/**
* Conversion Exception is thrown when the database to PHP conversion fails
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
namespace
Doctrine\DBAL\Types
;
class
ConversionException
extends
\Doctrine\DBAL\DBALException
{
/**
* Thrown when a Database to Doctrine Type Conversion fails.
*
* @param string $value
* @param string $toType
* @return ConversionException
*/
static
public
function
conversionFailed
(
$value
,
$toType
)
{
$value
=
(
strlen
(
$value
)
>
32
)
?
substr
(
$value
,
0
,
20
)
.
"..."
:
$value
;
return
new
self
(
'Could not convert database value "'
.
$value
.
'" to Doctrine Type '
.
$toType
);
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Types/DateTimeType.php
View file @
1442262d
<?php
/*
* $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
...
...
@@ -48,7 +46,11 @@ class DateTimeType extends Type
public
function
convertToPHPValue
(
$value
,
AbstractPlatform
$platform
)
{
return
(
$value
!==
null
)
$val
=
(
$value
!==
null
)
?
\DateTime
::
createFromFormat
(
$platform
->
getDateTimeFormatString
(),
$value
)
:
null
;
if
(
!
$val
)
{
throw
ConversionException
::
conversionFailed
(
$value
,
$this
->
getName
());
}
return
$val
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Types/DateTimeTzType.php
0 → 100644
View file @
1442262d
<?php
/*
* 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.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
* DateTime type saving additional timezone information.
*
* Caution: Databases are not necessarily experts at storing timezone related
* data of dates. First, of all the supported vendors only PostgreSQL and Oracle
* support storing Timezone data. But those two don't save the actual timezone
* attached to a DateTime instance (for example "Europe/Berlin" or "America/Montreal")
* but the current offset of them related to UTC. That means depending on daylight saving times
* or not you may get different offsets.
*
* This datatype makes only sense to use, if your application works with an offset, not
* with an actual timezone that uses transitions. Otherwise your DateTime instance
* attached with a timezone such as Europe/Berlin gets saved into the database with
* the offset and re-created from persistence with only the offset, not the original timezone
* attached.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 1.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class
DateTimeTzType
extends
Type
{
public
function
getName
()
{
return
Type
::
DATETIMETZ
;
}
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
AbstractPlatform
$platform
)
{
return
$platform
->
getDateTimeTzTypeDeclarationSQL
(
$fieldDeclaration
);
}
public
function
convertToDatabaseValue
(
$value
,
AbstractPlatform
$platform
)
{
return
(
$value
!==
null
)
?
$value
->
format
(
$platform
->
getDateTimeTzFormatString
())
:
null
;
}
public
function
convertToPHPValue
(
$value
,
AbstractPlatform
$platform
)
{
$val
=
(
$value
!==
null
)
?
\DateTime
::
createFromFormat
(
$platform
->
getDateTimeTzFormatString
(),
$value
)
:
null
;
if
(
!
$val
)
{
throw
ConversionException
::
conversionFailed
(
$value
,
$this
->
getName
());
}
return
$val
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Types/DateType.php
View file @
1442262d
<?php
/*
* $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
...
...
@@ -48,7 +46,11 @@ class DateType extends Type
public
function
convertToPHPValue
(
$value
,
AbstractPlatform
$platform
)
{
return
(
$value
!==
null
)
$val
=
(
$value
!==
null
)
?
\DateTime
::
createFromFormat
(
'!'
.
$platform
->
getDateFormatString
(),
$value
)
:
null
;
if
(
!
$val
)
{
throw
ConversionException
::
conversionFailed
(
$value
,
$this
->
getName
());
}
return
$val
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Types/ObjectType.php
View file @
1442262d
...
...
@@ -22,7 +22,11 @@ class ObjectType extends Type
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
$value
=
(
is_resource
(
$value
))
?
stream_get_contents
(
$value
)
:
$value
;
return
unserialize
(
$value
);
$val
=
unserialize
(
$value
);
if
(
$val
===
false
)
{
throw
ConversionException
::
conversionFailed
(
$value
,
$this
->
getName
());
}
return
$val
;
}
public
function
getName
()
...
...
lib/Doctrine/DBAL/Types/TimeType.php
View file @
1442262d
<?php
/*
* $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
...
...
@@ -57,7 +55,11 @@ class TimeType extends Type
*/
public
function
convertToPHPValue
(
$value
,
AbstractPlatform
$platform
)
{
return
(
$value
!==
null
)
$val
=
(
$value
!==
null
)
?
\DateTime
::
createFromFormat
(
$platform
->
getTimeFormatString
(),
$value
)
:
null
;
if
(
!
$val
)
{
throw
ConversionException
::
conversionFailed
(
$value
,
$this
->
getName
());
}
return
$val
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Types/Type.php
View file @
1442262d
...
...
@@ -38,6 +38,7 @@ abstract class Type
const
BIGINT
=
'bigint'
;
const
BOOLEAN
=
'boolean'
;
const
DATETIME
=
'datetime'
;
const
DATETIMETZ
=
'datetimetz'
;
const
DATE
=
'date'
;
const
TIME
=
'time'
;
const
DECIMAL
=
'decimal'
;
...
...
@@ -61,6 +62,7 @@ abstract class Type
self
::
STRING
=>
'Doctrine\DBAL\Types\StringType'
,
self
::
TEXT
=>
'Doctrine\DBAL\Types\TextType'
,
self
::
DATETIME
=>
'Doctrine\DBAL\Types\DateTimeType'
,
self
::
DATETIMETZ
=>
'Doctrine\DBAL\Types\DateTimeTzType'
,
self
::
DATE
=>
'Doctrine\DBAL\Types\DateType'
,
self
::
TIME
=>
'Doctrine\DBAL\Types\TimeType'
,
self
::
DECIMAL
=>
'Doctrine\DBAL\Types\DecimalType'
...
...
tests/Doctrine/Tests/DBAL/AllTests.php
View file @
1442262d
...
...
@@ -34,6 +34,7 @@ class AllTests
$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\DateTimeTzTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\DateTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\TimeTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\BooleanTest'
);
...
...
tests/Doctrine/Tests/DBAL/Functional/AllTests.php
View file @
1442262d
...
...
@@ -3,6 +3,7 @@
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\Tests\TestUtil
;
if
(
!
defined
(
'PHPUnit_MAIN_METHOD'
))
{
define
(
'PHPUnit_MAIN_METHOD'
,
'Dbal_Functional_AllTests::main'
);
...
...
@@ -21,15 +22,25 @@ class AllTests
{
$suite
=
new
\Doctrine\Tests\DbalFunctionalTestSuite
(
'Doctrine Dbal Functional'
);
$conn
=
TestUtil
::
getConnection
();
$sm
=
$conn
->
getSchemaManager
();
if
(
$sm
instanceof
Doctrine\DBAL\Schema\SqliteSchemaManager
)
{
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Functional\Schema\SqliteSchemaManagerTest'
);
}
else
if
(
$sm
instanceof
Doctrine\DBAL\Schema\MySqlSchemaManager
)
{
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Functional\Schema\MySqlSchemaManagerTest'
);
}
else
if
(
$sm
instanceof
Doctrine\DBAL\Schema\PostgreSqlSchemaManager
)
{
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Functional\Schema\PostgreSqlSchemaManagerTest'
);
}
else
if
(
$sm
instanceof
Doctrine\DBAL\Schema\OracleSchemaManager
)
{
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Functional\Schema\OracleSchemaManagerTest'
);
}
else
if
(
$sm
instanceof
Doctrine\DBAL\Schema\DB2SchemaManager
)
{
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Functional\Schema\Db2SchemaManagerTest'
);
}
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Functional\ConnectionTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Functional\DataAccessTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Functional\WriteTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Functional\LoggingTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Functional\TypeConversionTest'
);
return
$suite
;
}
...
...
tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php
0 → 100644
View file @
1442262d
<?php
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\Types\Type
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
TypeConversionTest
extends
\Doctrine\Tests\DbalFunctionalTestCase
{
static
private
$typeCounter
=
0
;
public
function
setUp
()
{
parent
::
setUp
();
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
$sm
=
$this
->
_conn
->
getSchemaManager
();
if
(
!
$sm
->
tablesExist
(
array
(
'type_conversion'
)))
{
$table
=
new
\Doctrine\DBAL\Schema\Table
(
"type_conversion"
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_string'
,
'string'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_boolean'
,
'boolean'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_bigint'
,
'bigint'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_smallint'
,
'bigint'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_datetime'
,
'datetime'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_datetimetz'
,
'datetimetz'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_date'
,
'date'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_time'
,
'time'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_text'
,
'text'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_array'
,
'array'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_object'
,
'object'
,
array
(
'notnull'
=>
false
));
$table
->
setPrimaryKey
(
array
(
'id'
));
$sm
->
createTable
(
$table
);
}
}
static
public
function
dataIdempotentDataConversion
()
{
$obj
=
new
\stdClass
();
$obj
->
foo
=
"bar"
;
$obj
->
bar
=
"baz"
;
return
array
(
array
(
'string'
,
'ABCDEFGaaaBBB'
,
'string'
),
array
(
'boolean'
,
true
,
'bool'
),
array
(
'boolean'
,
false
,
'bool'
),
array
(
'bigint'
,
12345678
,
'string'
),
array
(
'smallint'
,
123
,
'int'
),
array
(
'datetime'
,
new
\DateTime
(
'2010-04-05 10:10:10'
),
'DateTime'
),
array
(
'datetimetz'
,
new
\DateTime
(
'2010-04-05 10:10:10'
),
'DateTime'
),
array
(
'date'
,
new
\DateTime
(
'2010-04-05'
),
'DateTime'
),
array
(
'time'
,
new
\DateTime
(
'10:10:10'
),
'DateTime'
),
array
(
'text'
,
str_repeat
(
'foo '
,
1000
),
'string'
),
array
(
'array'
,
array
(
'foo'
=>
'bar'
),
'array'
),
array
(
'object'
,
$obj
,
'object'
),
);
}
/**
* @dataProvider dataIdempotentDataConversion
* @param string $type
* @param mixed $originalValue
* @param string $expectedPhpType
*/
public
function
testIdempotentDataConversion
(
$type
,
$originalValue
,
$expectedPhpType
)
{
$columnName
=
"test_"
.
$type
;
$typeInstance
=
Type
::
getType
(
$type
);
$insertionValue
=
$typeInstance
->
convertToDatabaseValue
(
$originalValue
,
$this
->
_conn
->
getDatabasePlatform
());
$this
->
_conn
->
insert
(
'type_conversion'
,
array
(
'id'
=>
++
self
::
$typeCounter
,
$columnName
=>
$insertionValue
));
$sql
=
"SELECT "
.
$columnName
.
" FROM type_conversion WHERE id = "
.
self
::
$typeCounter
;
$actualDbValue
=
$typeInstance
->
convertToPHPValue
(
$this
->
_conn
->
fetchColumn
(
$sql
),
$this
->
_conn
->
getDatabasePlatform
());
$this
->
assertType
(
$expectedPhpType
,
$actualDbValue
,
"The expected type from the conversion to and back from the database should be "
.
$expectedPhpType
);
if
(
$type
!==
"datetimetz"
)
{
$this
->
assertEquals
(
$originalValue
,
$actualDbValue
,
"Conversion between values should produce the same out as in value, but doesnt!"
);
if
(
$originalValue
instanceof
\DateTime
)
{
$this
->
assertEquals
(
$originalValue
->
getTimezone
()
->
getName
(),
$actualDbValue
->
getTimezone
()
->
getName
(),
"Timezones should be the same."
);
}
}
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Types/ArrayTest.php
View file @
1442262d
...
...
@@ -19,6 +19,12 @@ class ArrayTest extends \Doctrine\Tests\DbalTestCase
$this
->
_type
=
Type
::
getType
(
'array'
);
}
public
function
tearDown
()
{
error_reporting
(
-
1
);
// reactive all error levels
}
public
function
testArrayConvertsToDatabaseValue
()
{
$this
->
assertTrue
(
...
...
@@ -32,4 +38,12 @@ class ArrayTest extends \Doctrine\Tests\DbalTestCase
is_array
(
$this
->
_type
->
convertToPHPValue
(
serialize
(
array
()),
$this
->
_platform
))
);
}
public
function
testConversionFailure
()
{
error_reporting
(
(
E_ALL
|
E_STRICT
)
-
\E_NOTICE
);
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
_platform
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Types/DateTest.php
View file @
1442262d
...
...
@@ -61,4 +61,10 @@ class DateTest extends \Doctrine\Tests\DbalTestCase
$this
->
assertEquals
(
'00:00:00'
,
$date
->
format
(
'H:i:s'
));
$this
->
assertEquals
(
'2009-11-01'
,
$date
->
format
(
'Y-m-d'
));
}
public
function
testInvalidDateFormatConversion
()
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
_platform
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php
View file @
1442262d
...
...
@@ -21,17 +21,25 @@ class DateTimeTest extends \Doctrine\Tests\DbalTestCase
public
function
testDateTimeConvertsToDatabaseValue
()
{
$this
->
assertTrue
(
is_string
(
$this
->
_type
->
convertToDatabaseValue
(
new
\DateTime
(),
$this
->
_platform
))
);
$date
=
new
\DateTime
(
'1985-09-01 10:10:10'
);
$expected
=
$date
->
format
(
$this
->
_platform
->
getDateTimeTzFormatString
());
$actual
=
is_string
(
$this
->
_type
->
convertToDatabaseValue
(
$date
,
$this
->
_platform
));
$this
->
assertEquals
(
$expected
,
$actual
);
}
public
function
testDateTimeConvertsToPHPValue
()
{
// Birthday of jwage and also birthday of Doctrine. Send him a present ;)
$this
->
assertTrue
(
$this
->
_type
->
convertToPHPValue
(
'1985-09-01 00:00:00'
,
$this
->
_platform
)
instanceof
\DateTime
);
$date
=
$this
->
_type
->
convertToPHPValue
(
'1985-09-01 00:00:00'
,
$this
->
_platform
);
$this
->
assertType
(
'DateTime'
,
$date
);
$this
->
assertEquals
(
'1985-09-01 00:00:00'
,
$date
->
format
(
'Y-m-d H:i:s'
));
}
public
function
testInvalidDateTimeFormatConversion
()
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
_platform
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php
0 → 100644
View file @
1442262d
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
DateTimeTzTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$_platform
,
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
\Doctrine\Tests\DBAL\Mocks\MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'datetimetz'
);
}
public
function
testDateTimeConvertsToDatabaseValue
()
{
$date
=
new
\DateTime
(
'1985-09-01 10:10:10'
);
$expected
=
$date
->
format
(
$this
->
_platform
->
getDateTimeTzFormatString
());
$actual
=
is_string
(
$this
->
_type
->
convertToDatabaseValue
(
$date
,
$this
->
_platform
));
$this
->
assertEquals
(
$expected
,
$actual
);
}
public
function
testDateTimeConvertsToPHPValue
()
{
// Birthday of jwage and also birthday of Doctrine. Send him a present ;)
$date
=
$this
->
_type
->
convertToPHPValue
(
'1985-09-01 00:00:00'
,
$this
->
_platform
);
$this
->
assertType
(
'DateTime'
,
$date
);
$this
->
assertEquals
(
'1985-09-01 00:00:00'
,
$date
->
format
(
'Y-m-d H:i:s'
));
}
public
function
testInvalidDateFormatConversion
()
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
_platform
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Types/ObjectTest.php
View file @
1442262d
...
...
@@ -19,6 +19,11 @@ class ObjectTest extends \Doctrine\Tests\DbalTestCase
$this
->
_type
=
Type
::
getType
(
'object'
);
}
public
function
tearDown
()
{
error_reporting
(
-
1
);
// reactive all error levels
}
public
function
testObjectConvertsToDatabaseValue
()
{
$this
->
assertTrue
(
...
...
@@ -32,4 +37,11 @@ class ObjectTest extends \Doctrine\Tests\DbalTestCase
is_object
(
$this
->
_type
->
convertToPHPValue
(
serialize
(
new
\stdClass
),
$this
->
_platform
))
);
}
public
function
testConversionFailure
()
{
error_reporting
(
(
E_ALL
|
E_STRICT
)
-
\E_NOTICE
);
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
_platform
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Types/TimeTest.php
View file @
1442262d
...
...
@@ -33,4 +33,10 @@ class TimeTest extends \Doctrine\Tests\DbalTestCase
instanceof
\DateTime
);
}
public
function
testInvalidTimeFormatConversion
()
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToPHPValue
(
'abcdefg'
,
$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