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
87fd08e4
Commit
87fd08e4
authored
Feb 17, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Some fixes for ClassExporterTest.
parent
32d43c36
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
104 additions
and
60 deletions
+104
-60
Connection.php
lib/Doctrine/DBAL/Connection.php
+10
-0
DriverManager.php
lib/Doctrine/DBAL/DriverManager.php
+1
-1
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+3
-3
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+13
-29
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+6
-6
ClassExporter.php
lib/Doctrine/ORM/Export/ClassExporter.php
+7
-2
ConnectionMock.php
tests/Doctrine/Tests/Mocks/ConnectionMock.php
+2
-1
DriverMock.php
tests/Doctrine/Tests/Mocks/DriverMock.php
+21
-6
SchemaManagerMock.php
tests/Doctrine/Tests/Mocks/SchemaManagerMock.php
+20
-0
EntityPersisterTest.php
tests/Doctrine/Tests/ORM/EntityPersisterTest.php
+1
-1
ClassExporterTest.php
tests/Doctrine/Tests/ORM/Export/ClassExporterTest.php
+13
-6
UnitOfWorkTest.php
tests/Doctrine/Tests/ORM/UnitOfWorkTest.php
+1
-1
OrmTestCase.php
tests/Doctrine/Tests/OrmTestCase.php
+6
-4
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
87fd08e4
...
...
@@ -181,6 +181,16 @@ class Connection
$this
->
_transactionIsolationLevel
=
$this
->
_platform
->
getDefaultTransactionIsolationLevel
();
}
/**
* Gets the DBAL driver instance.
*
* @return Doctrine\DBAL\Driver
*/
public
function
getDriver
()
{
return
$this
->
_driver
;
}
/**
* Gets the Configuration used by the Connection.
*
...
...
lib/Doctrine/DBAL/DriverManager.php
View file @
87fd08e4
...
...
@@ -16,7 +16,7 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.
phpdoctrine
.org>.
* <http://www.
doctrine-project
.org>.
*/
namespace
Doctrine\DBAL
;
...
...
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
87fd08e4
...
...
@@ -1013,13 +1013,13 @@ abstract class AbstractPlatform
}
}
$query
=
'CREATE TABLE '
.
$this
->
conn
->
quoteIdentifier
(
$nam
e
,
true
)
.
' ('
.
$queryFields
;
$query
=
'CREATE TABLE '
.
$this
->
quoteIdentifier
(
$tabl
e
,
true
)
.
' ('
.
$queryFields
;
$check
=
$this
->
getCheckDeclaration
(
$columns
);
/*
$check = $this->getCheckDeclaration($columns);
if ( ! empty($check)) {
$query .= ', ' . $check;
}
}
*/
$query
.=
')'
;
...
...
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
87fd08e4
...
...
@@ -114,7 +114,6 @@ class MySqlPlatform extends AbstractPlatform
);*/
/**
* Constructor.
* Creates a new MySqlPlatform instance.
*/
public
function
__construct
()
...
...
@@ -1041,56 +1040,43 @@ class MySqlPlatform extends AbstractPlatform
*/
public
function
getIntegerTypeDeclarationSql
(
array
$field
)
{
return
'INT
'
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
return
'INT'
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getBigIntTypeDeclarationSql
(
array
$field
)
{
return
'BIGINT
'
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
return
'BIGINT'
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getTinyIntTypeDeclarationSql
(
array
$field
)
{
return
'TINYINT
'
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
return
'TINYINT'
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getSmallIntTypeDeclarationSql
(
array
$field
)
{
return
'SMALLINT
'
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
return
'SMALLINT'
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getMediumIntTypeDeclarationSql
(
array
$field
)
{
return
'MEDIUMINT
'
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
return
'MEDIUMINT'
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
protected
function
_getCommonIntegerTypeDeclarationSql
(
array
$columnDef
)
{
$
default
=
$
autoinc
=
''
;
$autoinc
=
''
;
if
(
!
empty
(
$columnDef
[
'autoincrement'
]))
{
$autoinc
=
' AUTO_INCREMENT'
;
}
elseif
(
array_key_exists
(
'default'
,
$columnDef
))
{
if
(
$columnDef
[
'default'
]
===
''
)
{
$columnDef
[
'default'
]
=
empty
(
$columnDef
[
'notnull'
])
?
null
:
0
;
}
if
(
is_null
(
$columnDef
[
'default'
]))
{
$default
=
' DEFAULT NULL'
;
}
else
{
$default
=
' DEFAULT '
.
$this
->
quote
(
$columnDef
[
'default'
]);
}
}
elseif
(
empty
(
$columnDef
[
'notnull'
]))
{
$default
=
' DEFAULT NULL'
;
}
$notnull
=
(
isset
(
$columnDef
[
'notnull'
])
&&
$columnDef
[
'notnull'
])
?
' NOT NULL'
:
''
;
$unsigned
=
(
isset
(
$columnDef
[
'unsigned'
])
&&
$columnDef
[
'unsigned'
])
?
' UNSIGNED'
:
''
;
return
$unsigned
.
$
default
.
$notnull
.
$
autoinc
;
return
$unsigned
.
$autoinc
;
}
/**
...
...
@@ -1104,33 +1090,31 @@ class MySqlPlatform extends AbstractPlatform
*/
public
function
getDefaultFieldDeclarationSql
(
$field
)
{
$default
=
empty
(
$field
[
'notnull'
])
&&
!
in_array
(
$field
[
'type'
],
array
(
'clob'
,
'blob'
))
?
' DEFAULT NULL'
:
''
;
$default
=
empty
(
$field
[
'notnull'
])
?
' DEFAULT NULL'
:
''
;
if
(
isset
(
$field
[
'default'
])
&&
(
!
isset
(
$field
[
'length'
])
||
$field
[
'length'
]
<=
255
))
{
if
(
$field
[
'default'
]
===
''
)
{
$field
[
'default'
]
=
null
;
if
(
!
empty
(
$field
[
'notnull'
])
&&
array_key_exists
(
$field
[
'type'
],
$this
->
valid_default_values
))
{
/*if (
! empty($field['notnull']) && array_key_exists($field['type'], $this->valid_default_values)) {
$field['default'] = $this->valid_default_values[$field['type']];
}
if ($field['default'] === ''
&& ($this->_conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EMPTY_TO_NULL)
) {
$field['default'] = ' ';
}
}
*/
}
if
(
$field
[
'type'
]
==
'enum'
&&
$this
->
_conn
->
getAttribute
(
Doctrine
::
ATTR_USE_NATIVE_ENUM
))
{
/*
if ($field['type'] == 'enum' && $this->_conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
$fieldType = 'varchar';
} else {
if ($field['type'] === 'boolean') {
$fields['default'] = $this->convertBooleans($field['default']);
}
$fieldType = $field['type'];
}
}
*/
$default
=
' DEFAULT '
.
$this
->
quote
(
$field
[
'default'
],
$field
Type
);
$default
=
' DEFAULT '
.
$this
->
quote
(
$field
[
'default'
],
$field
[
'type'
]
);
}
return
$default
;
}
...
...
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
87fd08e4
...
...
@@ -450,10 +450,10 @@ class SqlitePlatform extends AbstractPlatform
/** @override */
protected
function
_getCommonIntegerTypeDeclarationSql
(
array
$columnDef
)
{
$autoinc
=
!
empty
(
$columnDef
[
'autoincrement'
])
?
'AUTOINCREMENT'
:
''
;
$pk
=
!
empty
(
$columnDef
[
'primary'
])
&&
!
empty
(
$autoinc
)
?
'PRIMARY KEY'
:
''
;
$autoinc
=
!
empty
(
$columnDef
[
'autoincrement'
])
?
'
AUTOINCREMENT'
:
''
;
$pk
=
!
empty
(
$columnDef
[
'primary'
])
&&
!
empty
(
$autoinc
)
?
'
PRIMARY KEY'
:
''
;
return
"INTEGER
$pk
$autoinc
"
;
return
"INTEGER
"
.
$pk
.
$autoinc
;
}
/**
...
...
@@ -513,13 +513,13 @@ class SqlitePlatform extends AbstractPlatform
$name
=
$this
->
quoteIdentifier
(
$name
,
true
);
$sql
=
'CREATE TABLE '
.
$name
.
' ('
.
$queryFields
;
if
(
$check
=
$this
->
getCheckDeclarationSql
(
$fields
))
{
/*
if ($check = $this->getCheckDeclarationSql($fields)) {
$sql .= ', ' . $check;
}
if (isset($options['checks']) && $check = $this->getCheckDeclarationSql($options['checks'])) {
$sql .= ', ' . $check;
}
}
*/
$sql
.=
')'
;
...
...
@@ -527,7 +527,7 @@ class SqlitePlatform extends AbstractPlatform
if
(
isset
(
$options
[
'indexes'
])
&&
!
empty
(
$options
[
'indexes'
]))
{
foreach
(
$options
[
'indexes'
]
as
$index
=>
$definition
)
{
$query
[]
=
$this
->
c
reateIndexSql
(
$name
,
$index
,
$definition
);
$query
[]
=
$this
->
getC
reateIndexSql
(
$name
,
$index
,
$definition
);
}
}
return
$query
;
...
...
lib/Doctrine/ORM/Export/ClassExporter.php
View file @
87fd08e4
...
...
@@ -94,6 +94,7 @@ class ClassExporter
$column
[
'notnull'
]
=
!
$mapping
[
'nullable'
];
if
(
$class
->
isIdentifier
(
$fieldName
))
{
$column
[
'primary'
]
=
true
;
$options
[
'primary'
][]
=
$mapping
[
'columnName'
];
if
(
$class
->
isIdGeneratorIdentity
())
{
$column
[
'autoincrement'
]
=
true
;
}
...
...
@@ -124,6 +125,7 @@ class ClassExporter
}
else
if
(
$mapping
->
isManyToMany
()
&&
$mapping
->
isOwningSide
())
{
//... create join table
$joinTableColumns
=
array
();
$joinTableOptions
=
array
();
$joinTable
=
$mapping
->
getJoinTable
();
$constraint1
=
array
();
$constraint1
[
'tableName'
]
=
$joinTable
[
'name'
];
...
...
@@ -133,6 +135,7 @@ class ClassExporter
foreach
(
$joinTable
[
'joinColumns'
]
as
$joinColumn
)
{
$column
=
array
();
$column
[
'primary'
]
=
true
;
$joinTableOptions
[
'primary'
][]
=
$joinColumn
[
'name'
];
$column
[
'name'
]
=
$joinColumn
[
'name'
];
$column
[
'type'
]
=
$class
->
getTypeOfColumn
(
$joinColumn
[
'referencedColumnName'
]);
$joinTableColumns
[
$joinColumn
[
'name'
]]
=
$column
;
...
...
@@ -149,6 +152,7 @@ class ClassExporter
foreach
(
$joinTable
[
'inverseJoinColumns'
]
as
$inverseJoinColumn
)
{
$column
=
array
();
$column
[
'primary'
]
=
true
;
$joinTableOptions
[
'primary'
][]
=
$inverseJoinColumn
[
'name'
];
$column
[
'name'
]
=
$inverseJoinColumn
[
'name'
];
$column
[
'type'
]
=
$this
->
_em
->
getClassMetadata
(
$mapping
->
getTargetEntityName
())
->
getTypeOfColumn
(
$inverseJoinColumn
[
'referencedColumnName'
]);
...
...
@@ -158,7 +162,8 @@ class ClassExporter
}
$foreignKeyConstraints
[]
=
$constraint2
;
$sql
=
array_merge
(
$sql
,
$this
->
_platform
->
getCreateTableSql
(
$joinTable
[
'name'
],
$joinTableColumns
,
array
()));
$sql
=
array_merge
(
$sql
,
$this
->
_platform
->
getCreateTableSql
(
$joinTable
[
'name'
],
$joinTableColumns
,
$joinTableOptions
));
}
}
...
...
@@ -168,7 +173,7 @@ class ClassExporter
// Now create the foreign key constraints
if
(
$this
->
_platform
->
supportsForeignKeyConstraints
())
{
foreach
(
$foreignKeyConstraints
as
$fkConstraint
)
{
$sql
=
array_merge
(
$sql
,
$this
->
_platform
->
getCreateForeignKeySql
(
$fkConstraint
[
'tableName'
],
$fkConstraint
));
$sql
=
array_merge
(
$sql
,
(
array
)
$this
->
_platform
->
getCreateForeignKeySql
(
$fkConstraint
[
'tableName'
],
$fkConstraint
));
}
}
...
...
tests/Doctrine/Tests/Mocks/ConnectionMock.php
View file @
87fd08e4
...
...
@@ -8,7 +8,8 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
private
$_lastInsertId
=
0
;
private
$_inserts
=
array
();
public
function
__construct
()
{
public
function
__construct
(
array
$params
,
$driver
,
$config
=
null
,
$eventManager
=
null
)
{
parent
::
__construct
(
$params
,
$driver
,
$config
,
$eventManager
);
$this
->
_platformMock
=
new
DatabasePlatformMock
();
$this
->
_platform
=
$this
->
_platformMock
;
}
...
...
tests/Doctrine/Tests/Mocks/DriverMock.php
View file @
87fd08e4
...
...
@@ -3,11 +3,10 @@
namespace
Doctrine\Tests\Mocks
;
// THIS FILE DOES NOT EXIST YET!!!!
//require_once 'lib/mocks/Doctrine_SchemaManagerMock.php';
class
DriverMock
implements
\Doctrine\DBAL\Driver
{
private
$_platformMock
;
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
array
())
{
return
new
DriverConnectionMock
();
...
...
@@ -24,14 +23,30 @@ class DriverMock implements \Doctrine\DBAL\Driver
return
""
;
}
/**
* @override
*/
public
function
getDatabasePlatform
()
{
return
new
DatabasePlatformMock
();
if
(
!
$this
->
_platformMock
)
{
$this
->
_platformMock
=
new
DatabasePlatformMock
;
}
return
$this
->
_platformMock
;
}
/**
* @override
*/
public
function
getSchemaManager
(
\Doctrine\DBAL\Connection
$conn
)
{
return
new
SchemaManagerMock
(
$conn
);
}
/* MOCK API */
public
function
setDatabasePlatform
(
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
$this
->
_platformMock
=
$platform
;
}
}
tests/Doctrine/Tests/Mocks/SchemaManagerMock.php
0 → 100644
View file @
87fd08e4
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace
Doctrine\Tests\Mocks
;
/**
* Description of SchemaManagerMock
*
* @author robo
*/
class
SchemaManagerMock
extends
\Doctrine\DBAL\Schema\AbstractSchemaManager
{
public
function
__construct
(
\Doctrine\DBAL\Connection
$conn
)
{
parent
::
__construct
(
$conn
);
}
}
tests/Doctrine/Tests/ORM/EntityPersisterTest.php
View file @
87fd08e4
...
...
@@ -24,7 +24,7 @@ class EntityPersisterTest extends \Doctrine\Tests\OrmTestCase
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
_connMock
=
new
ConnectionMock
(
array
());
$this
->
_connMock
=
new
ConnectionMock
(
array
()
,
new
\Doctrine\Tests\Mocks\DriverMock
()
);
$this
->
_emMock
=
EntityManagerMock
::
create
(
$this
->
_connMock
);
$this
->
_uowMock
=
new
UnitOfWorkMock
(
$this
->
_emMock
);
$this
->
_emMock
->
setUnitOfWork
(
$this
->
_uowMock
);
...
...
tests/Doctrine/Tests/ORM/Export/ClassExporterTest.php
View file @
87fd08e4
...
...
@@ -16,7 +16,7 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.
phpdoctrine
.org>.
* <http://www.
doctrine-project
.org>.
*/
namespace
Doctrine\Tests\ORM\Export
;
...
...
@@ -40,15 +40,22 @@ class ClassExporterTest extends \Doctrine\Tests\OrmTestCase
{
public
function
testTest
()
{
/*
$em = $this->_getTestEntityManager();
// DDL is platform dependant. We can inject the platform to test into the driver mock.
$driver
=
new
\Doctrine\Tests\Mocks\DriverMock
;
$conn
=
new
\Doctrine\Tests\Mocks\ConnectionMock
(
array
(),
$driver
);
//$conn->setDatabasePlatform(new \Doctrine\DBAL\Platforms\SqlitePlatform());
$conn
->
setDatabasePlatform
(
new
\Doctrine\DBAL\Platforms\MySqlPlatform
());
$classes = array($em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'));
$em
=
$this
->
_getTestEntityManager
(
$conn
);
$classes
=
array
(
$em
->
getClassMetadata
(
'Doctrine\Tests\Models\CMS\CmsUser'
),
$em
->
getClassMetadata
(
'Doctrine\Tests\Models\CMS\CmsPhonenumber'
)
);
$exporter
=
new
ClassExporter
(
$em
);
$sql
=
$exporter
->
getExportClassesSql
(
$classes
);
print_r
(
$sql
);
exit('test');
*/
}
}
\ No newline at end of file
tests/Doctrine/Tests/ORM/UnitOfWorkTest.php
View file @
87fd08e4
...
...
@@ -27,7 +27,7 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
_connectionMock
=
new
ConnectionMock
(
array
());
$this
->
_connectionMock
=
new
ConnectionMock
(
array
()
,
new
\Doctrine\Tests\Mocks\DriverMock
()
);
$this
->
_emMock
=
EntityManagerMock
::
create
(
$this
->
_connectionMock
);
// SUT
$this
->
_unitOfWork
=
new
UnitOfWorkMock
(
$this
->
_emMock
);
...
...
tests/Doctrine/Tests/OrmTestCase.php
View file @
87fd08e4
...
...
@@ -15,18 +15,20 @@ class OrmTestCase extends DoctrineTestCase
*
* @return Doctrine\ORM\EntityManager
*/
protected
function
_getTestEntityManager
(
$conf
=
null
,
$eventManager
=
null
)
protected
function
_getTestEntityManager
(
$con
n
=
null
,
$con
f
=
null
,
$eventManager
=
null
)
{
$config
=
new
\Doctrine\ORM\Configuration
();
$config
->
setMetadataCacheImpl
(
self
::
getSharedMetadataCacheImpl
());
$eventManager
=
new
\Doctrine\Common\EventManager
();
$connectionOptions
=
array
(
if
(
is_null
(
$conn
))
{
$conn
=
array
(
'driverClass'
=>
'Doctrine\Tests\Mocks\DriverMock'
,
'wrapperClass'
=>
'Doctrine\Tests\Mocks\ConnectionMock'
,
'user'
=>
'john'
,
'password'
=>
'wayne'
);
return
\Doctrine\ORM\EntityManager
::
create
(
$connectionOptions
,
$config
,
$eventManager
);
}
return
\Doctrine\ORM\EntityManager
::
create
(
$conn
,
$config
,
$eventManager
);
}
private
static
function
getSharedMetadataCacheImpl
()
...
...
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