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
7131ab9e
Commit
7131ab9e
authored
Jan 15, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
bf749ae4
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
93 additions
and
243 deletions
+93
-243
Doctrine.php
lib/Doctrine.php
+3
-3
Connection.php
lib/Doctrine/Connection.php
+7
-7
Mssql.php
lib/Doctrine/Connection/Mssql.php
+2
-3
Db.php
lib/Doctrine/Db.php
+1
-1
Mysql.php
lib/Doctrine/Export/Mysql.php
+12
-12
Hydrate.php
lib/Doctrine/Hydrate.php
+2
-1
ConnectionTestCase.php
tests/ConnectionTestCase.php
+4
-186
DriverTestCase.php
tests/DriverTestCase.php
+42
-11
SequenceTestCase.php
tests/SequenceTestCase.php
+15
-15
UnitTestCase.php
tests/UnitTestCase.php
+5
-4
No files found.
lib/Doctrine.php
View file @
7131ab9e
...
...
@@ -407,14 +407,14 @@ final class Doctrine
* @return boolean
*/
public
static
function
autoload
(
$classname
)
{
if
(
class_exists
(
$classname
))
{
{
if
(
class_exists
(
$classname
,
false
))
{
return
false
;
}
if
(
!
self
::
$path
)
{
self
::
$path
=
dirname
(
__FILE__
);
}
$class
=
self
::
$path
.
DIRECTORY_SEPARATOR
.
str_replace
(
'_'
,
DIRECTORY_SEPARATOR
,
$classname
)
.
'.php'
;
$class
=
self
::
$path
.
DIRECTORY_SEPARATOR
.
str_replace
(
'_'
,
DIRECTORY_SEPARATOR
,
$classname
)
.
'.php'
;
if
(
!
file_exists
(
$class
))
{
return
false
;
...
...
lib/Doctrine/Connection.php
View file @
7131ab9e
...
...
@@ -488,7 +488,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return array
*/
public
function
fetchAll
(
$statement
,
array
$params
=
array
())
{
return
$this
->
query
(
$statement
,
$params
)
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
return
$this
->
execute
(
$statement
,
$params
)
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
}
/**
* fetchOne
...
...
@@ -509,7 +509,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return array
*/
public
function
fetchRow
(
$statement
,
array
$params
=
array
())
{
return
$this
->
query
(
$statement
,
$params
)
->
fetch
(
PDO
::
FETCH_ASSOC
);
return
$this
->
execute
(
$statement
,
$params
)
->
fetch
(
PDO
::
FETCH_ASSOC
);
}
/**
* fetchArray
...
...
@@ -519,7 +519,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return array
*/
public
function
fetchArray
(
$statement
,
array
$params
=
array
())
{
return
$this
->
query
(
$statement
,
$params
)
->
fetch
(
PDO
::
FETCH_NUM
);
return
$this
->
execute
(
$statement
,
$params
)
->
fetch
(
PDO
::
FETCH_NUM
);
}
/**
* fetchColumn
...
...
@@ -530,7 +530,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return array
*/
public
function
fetchColumn
(
$statement
,
array
$params
=
array
(),
$colnum
=
0
)
{
return
$this
->
query
(
$statement
,
$params
)
->
fetchAll
(
PDO
::
FETCH_COLUMN
,
$colnum
);
return
$this
->
execute
(
$statement
,
$params
)
->
fetchAll
(
PDO
::
FETCH_COLUMN
,
$colnum
);
}
/**
* fetchAssoc
...
...
@@ -540,7 +540,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return array
*/
public
function
fetchAssoc
(
$statement
,
array
$params
=
array
())
{
return
$this
->
query
(
$statement
,
$params
)
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
return
$this
->
execute
(
$statement
,
$params
)
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
}
/**
* fetchBoth
...
...
@@ -550,7 +550,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return array
*/
public
function
fetchBoth
(
$statement
,
array
$params
=
array
())
{
return
$this
->
query
(
$statement
,
$params
)
->
fetchAll
(
PDO
::
FETCH_BOTH
);
return
$this
->
execute
(
$statement
,
$params
)
->
fetchAll
(
PDO
::
FETCH_BOTH
);
}
/**
* query
...
...
@@ -650,7 +650,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if
(
!
empty
(
$params
))
{
$stmt
=
$this
->
dbh
->
prepare
(
$query
);
$stmt
->
execute
(
$params
);
return
$stmt
;
return
$stmt
->
rowCount
()
;
}
else
{
return
$this
->
dbh
->
exec
(
$query
);
}
...
...
lib/Doctrine/Connection/Mssql.php
View file @
7131ab9e
...
...
@@ -79,7 +79,7 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection
*/
public
function
quoteIdentifier
(
$identifier
,
$checkOption
=
false
)
{
if
(
$checkOption
&&
!
$this
->
options
[
'quote_identifier'
]
)
{
if
(
$checkOption
&&
!
$this
->
getAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
)
)
{
return
$identifier
;
}
return
'['
.
str_replace
(
']'
,
']]'
,
$identifier
)
.
']'
;
...
...
@@ -143,9 +143,8 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection
*
* @param bool $native determines if the raw version string should be returned
* @return mixed array/string with version information or MDB2 error object
* @access public
*/
function
getServerVersion
(
$native
=
false
)
public
function
getServerVersion
(
$native
=
false
)
{
if
(
$this
->
connected_server_info
)
{
$serverInfo
=
$this
->
connected_server_info
;
...
...
lib/Doctrine/Db.php
View file @
7131ab9e
...
...
@@ -192,7 +192,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$this
->
dbh
=
new
PDO
(
$this
->
options
[
'dsn'
],
$this
->
options
[
'username'
],
$this
->
options
[
'password'
]);
$this
->
dbh
->
setAttribute
(
PDO
::
ATTR_ERRMODE
,
PDO
::
ERRMODE_EXCEPTION
);
$this
->
dbh
->
setAttribute
(
PDO
::
ATTR_STATEMENT_CLASS
,
array
(
"Doctrine_Db_Statement"
,
array
(
$this
)));
$this
->
dbh
->
setAttribute
(
PDO
::
ATTR_STATEMENT_CLASS
,
array
(
'Doctrine_Db_Statement'
,
array
(
$this
)));
foreach
(
$this
->
pendingAttributes
as
$attr
=>
$value
)
{
$this
->
dbh
->
setAttribute
(
$attr
,
$value
);
...
...
lib/Doctrine/Export/Mysql.php
View file @
7131ab9e
...
...
@@ -84,7 +84,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
* @param array $options An associative array of table options:
* array(
* 'comment' => 'Foo',
* 'char
acter_
set' => 'utf8',
* 'charset' => 'utf8',
* 'collate' => 'utf8_unicode_ci',
* 'collate' => 'utf8_unicode_ci',
* 'type' => 'innodb',
...
...
@@ -94,18 +94,18 @@ class Doctrine_Export_Mysql extends Doctrine_Export
*/
public
function
createTable
(
$name
,
array
$fields
,
array
$options
=
array
())
{
if
(
!
$name
)
throw
new
Doctrine_Export_
Mysql_
Exception
(
'no valid table name specified'
);
throw
new
Doctrine_Export_Exception
(
'no valid table name specified'
);
if
(
empty
(
$fields
))
{
throw
new
Doctrine_Export_
Mysql_
Exception
(
'no fields specified for table "'
.
$name
.
'"'
);
throw
new
Doctrine_Export_Exception
(
'no fields specified for table "'
.
$name
.
'"'
);
}
$query
_f
ields
=
$this
->
getFieldDeclarationList
(
$fields
);
$query
F
ields
=
$this
->
getFieldDeclarationList
(
$fields
);
if
(
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$query
_fields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_values
(
$options
[
'primary'
]))
.
')'
;
$query
Fields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_values
(
$options
[
'primary'
]))
.
')'
;
}
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
,
true
);
$query
=
'CREATE TABLE '
.
$name
.
' ('
.
$query
_f
ields
.
')'
;
$query
=
'CREATE TABLE '
.
$name
.
' ('
.
$query
F
ields
.
')'
;
$optionStrings
=
array
();
...
...
@@ -227,7 +227,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
public
function
alterTable
(
$name
,
array
$changes
,
$check
)
{
if
(
!
$name
)
throw
new
Doctrine_Export_
Mysql_
Exception
(
'no valid table name specified'
);
throw
new
Doctrine_Export_Exception
(
'no valid table name specified'
);
foreach
(
$changes
as
$changeName
=>
$change
)
{
switch
(
$changeName
)
{
...
...
@@ -238,7 +238,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
case
'name'
:
break
;
default
:
throw
new
Doctrine_Export_
Mysql_
Exception
(
'change type "'
.
$changeName
.
'" not yet supported'
);
throw
new
Doctrine_Export_Exception
(
'change type "'
.
$changeName
.
'" not yet supported'
);
}
}
...
...
@@ -324,7 +324,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
{
$query
=
'CREATE TABLE '
.
$sequenceName
.
' ('
.
$seqcolName
.
' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
.
$seqcol
_n
ame
.
'))'
.
$seqcol
N
ame
.
'))'
.
strlen
(
$this
->
conn
->
default_table_type
)
?
' TYPE = '
.
$this
->
conn
->
default_table_type
:
''
;
...
...
@@ -334,7 +334,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
return
true
;
$query
=
'INSERT INTO '
.
$sequenceName
.
' ('
.
$seqcol
_n
ame
.
') VALUES ('
.
(
$start
-
1
)
.
')'
;
.
' ('
.
$seqcol
N
ame
.
') VALUES ('
.
(
$start
-
1
)
.
')'
;
$res
=
$this
->
conn
->
exec
(
$query
);
...
...
@@ -342,10 +342,10 @@ class Doctrine_Export_Mysql extends Doctrine_Export
try
{
$result
=
$this
->
conn
->
exec
(
'DROP TABLE '
.
$sequenceName
);
}
catch
(
Exception
$e
)
{
throw
new
Doctrine_Export_
Mysql_
Exception
(
'could not drop inconsistent sequence table'
);
throw
new
Doctrine_Export_Exception
(
'could not drop inconsistent sequence table'
);
}
throw
new
Doctrine_
Mysql_
Export_Exception
(
'could not create sequence table'
);
throw
new
Doctrine_Export_Exception
(
'could not create sequence table'
);
}
/**
* Get the stucture of a field into an array
...
...
lib/Doctrine/Hydrate.php
View file @
7131ab9e
...
...
@@ -642,7 +642,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
$b
=
array
();
foreach
(
$map
as
$field
=>
$value
)
{
if
(
$index
>
0
)
{
$b
[]
=
'('
.
$tableAlias
.
'.'
.
$field
.
' = '
.
$value
.
' OR '
.
$tableAlias
.
'.'
.
$field
.
' IS NULL)'
;
$b
[]
=
'('
.
$tableAlias
.
'.'
.
$field
.
' = '
.
$value
.
' OR '
.
$tableAlias
.
'.'
.
$field
.
' IS NULL)'
;
}
else
{
$b
[]
=
$tableAlias
.
'.'
.
$field
.
' = '
.
$value
;
}
...
...
tests/ConnectionTestCase.php
View file @
7131ab9e
...
...
@@ -31,7 +31,6 @@
* @version $Revision$
*/
class
Doctrine_Connection_TestCase
extends
Doctrine_UnitTestCase
{
public
function
testUnknownModule
()
{
try
{
$this
->
connection
->
unknown
;
...
...
@@ -47,8 +46,9 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
$this
->
connection
->
transaction
instanceof
Doctrine_Transaction
);
$this
->
assertTrue
(
$this
->
connection
->
export
instanceof
Doctrine_Export
);
}
public
function
testFetchAll
()
{
$this
->
conn
->
exec
(
'CREATE TABLE entity (id INTEGER, name TEXT)'
);
public
function
testFetchAll
()
{
$this
->
conn
->
exec
(
'DROP TABLE entity'
);
$this
->
conn
->
exec
(
'CREATE TABLE entity (id INT, name TEXT)'
);
$this
->
conn
->
exec
(
"INSERT INTO entity (id, name) VALUES (1, 'zYne')"
);
$this
->
conn
->
exec
(
"INSERT INTO entity (id, name) VALUES (2, 'John')"
);
...
...
@@ -127,172 +127,11 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
));
}
public
function
testFetchPairs
()
{
$this
->
conn
->
exec
(
'DROP TABLE entity'
);
}
public
function
testFlush
()
{
$user
=
$this
->
connection
->
getTable
(
'User'
)
->
find
(
4
);
$this
->
assertTrue
(
is_numeric
(
$user
->
Phonenumber
[
0
]
->
entity_id
));
$user
=
$this
->
connection
->
create
(
'Email'
);
$user
=
$this
->
connection
->
create
(
'User'
);
$record
=
$this
->
connection
->
create
(
'Phonenumber'
);
$user
->
Email
->
address
=
'example@drinkmore.info'
;
$this
->
assertTrue
(
$user
->
email_id
instanceof
Email
);
$user
->
name
=
'Example user'
;
$user
->
Group
[
0
]
->
name
=
'Example group 1'
;
$user
->
Group
[
1
]
->
name
=
'Example group 2'
;
$user
->
Phonenumber
[
0
]
->
phonenumber
=
'123 123'
;
$user
->
Phonenumber
[
1
]
->
phonenumber
=
'321 2132'
;
$user
->
Phonenumber
[
2
]
->
phonenumber
=
'123 123'
;
$user
->
Phonenumber
[
3
]
->
phonenumber
=
'321 2132'
;
$this
->
assertTrue
(
$user
->
Phonenumber
[
0
]
->
entity_id
instanceof
User
);
$this
->
assertTrue
(
$user
->
Phonenumber
[
2
]
->
entity_id
instanceof
User
);
$this
->
connection
->
flush
();
$this
->
assertTrue
(
is_numeric
(
$user
->
Phonenumber
[
0
]
->
entity_id
));
$this
->
assertEqual
(
count
(
$user
->
Group
),
2
);
$user2
=
$user
;
$user
=
$this
->
objTable
->
find
(
$user
->
id
);
$this
->
assertEqual
(
$user
->
id
,
$user2
->
id
);
$this
->
assertTrue
(
is_numeric
(
$user
->
id
));
$this
->
assertTrue
(
is_numeric
(
$user
->
email_id
));
$this
->
assertTrue
(
is_numeric
(
$user
->
Phonenumber
[
0
]
->
entity_id
));
$this
->
assertTrue
(
$user
->
Phonenumber
->
count
(),
4
);
$this
->
assertEqual
(
$user
->
Group
->
count
(),
2
);
$user
=
$this
->
objTable
->
find
(
5
);
$pf
=
$this
->
connection
->
getTable
(
'Phonenumber'
);
$this
->
assertTrue
(
$user
->
Phonenumber
instanceof
Doctrine_Collection
);
$this
->
assertTrue
(
$user
->
Phonenumber
->
count
()
==
3
);
$coll
=
new
Doctrine_Collection
(
$pf
);
$user
->
Phonenumber
=
$coll
;
$this
->
assertTrue
(
$user
->
Phonenumber
->
count
()
==
0
);
$this
->
connection
->
flush
();
unset
(
$user
);
$user
=
$this
->
objTable
->
find
(
5
);
$this
->
assertEqual
(
$user
->
Phonenumber
->
count
(),
0
);
// ADDING REFERENCES
$user
->
Phonenumber
[
0
]
->
phonenumber
=
'123 123'
;
$this
->
assertTrue
(
is_numeric
(
$user
->
Phonenumber
[
0
]
->
entity_id
));
$user
->
Phonenumber
[
1
]
->
phonenumber
=
'123 123'
;
$this
->
connection
->
flush
();
$this
->
assertEqual
(
$user
->
Phonenumber
->
count
(),
2
);
unset
(
$user
);
$user
=
$this
->
objTable
->
find
(
5
);
$this
->
assertEqual
(
$user
->
Phonenumber
->
count
(),
2
);
$user
->
Phonenumber
[
3
]
->
phonenumber
=
'123 123'
;
$this
->
connection
->
flush
();
$this
->
assertEqual
(
$user
->
Phonenumber
->
count
(),
3
);
unset
(
$user
);
$user
=
$this
->
objTable
->
find
(
5
);
$this
->
assertEqual
(
$user
->
Phonenumber
->
count
(),
3
);
// DELETING REFERENCES
$user
->
Phonenumber
->
delete
();
$this
->
assertEqual
(
$user
->
Phonenumber
->
count
(),
0
);
unset
(
$user
);
$user
=
$this
->
objTable
->
find
(
5
);
$this
->
assertEqual
(
$user
->
Phonenumber
->
count
(),
0
);
// ADDING REFERENCES WITH STRING KEYS
$user
->
Phonenumber
[
'home'
]
->
phonenumber
=
'123 123'
;
$user
->
Phonenumber
[
'work'
]
->
phonenumber
=
'444 444'
;
$this
->
assertEqual
(
$user
->
Phonenumber
->
count
(),
2
);
$this
->
connection
->
flush
();
$this
->
assertEqual
(
$user
->
Phonenumber
->
count
(),
2
);
unset
(
$user
);
$user
=
$this
->
objTable
->
find
(
5
);
$this
->
assertEqual
(
$user
->
Phonenumber
->
count
(),
2
);
// REPLACING ONE-TO-MANY REFERENCE
unset
(
$coll
);
$coll
=
new
Doctrine_Collection
(
$pf
);
$coll
[
0
]
->
phonenumber
=
'123 123'
;
$coll
[
'home'
]
->
phonenumber
=
'444 444'
;
$coll
[
'work'
]
->
phonenumber
=
'444 444'
;
$user
->
Phonenumber
=
$coll
;
$this
->
connection
->
flush
();
$this
->
assertEqual
(
$user
->
Phonenumber
->
count
(),
3
);
$user
=
$this
->
objTable
->
find
(
5
);
$this
->
assertEqual
(
$user
->
Phonenumber
->
count
(),
3
);
// ONE-TO-ONE REFERENCES
$user
->
Email
->
address
=
'drinker@drinkmore.info'
;
$this
->
assertTrue
(
$user
->
Email
instanceof
Email
);
$this
->
connection
->
flush
();
$this
->
assertTrue
(
$user
->
Email
instanceof
Email
);
$user
=
$this
->
objTable
->
find
(
5
);
$this
->
assertEqual
(
$user
->
Email
->
address
,
'drinker@drinkmore.info'
);
$id
=
$user
->
Email
->
id
;
// REPLACING ONE-TO-ONE REFERENCES
$email
=
$this
->
connection
->
create
(
'Email'
);
$email
->
address
=
'absolutist@nottodrink.com'
;
$user
->
Email
=
$email
;
$this
->
assertTrue
(
$user
->
Email
instanceof
Email
);
$this
->
assertEqual
(
$user
->
Email
->
address
,
'absolutist@nottodrink.com'
);
$this
->
connection
->
flush
();
unset
(
$user
);
$user
=
$this
->
objTable
->
find
(
5
);
$this
->
assertTrue
(
$user
->
Email
instanceof
Email
);
$this
->
assertEqual
(
$user
->
Email
->
address
,
'absolutist@nottodrink.com'
);
$emails
=
$this
->
connection
->
query
(
"FROM Email WHERE Email.id =
$id
"
);
//$this->assertEqual(count($emails),0);
}
public
function
testGetManager
()
{
$this
->
assertEqual
(
$this
->
connection
->
getManager
(),
$this
->
manager
);
}
public
function
testQuery
()
{
$this
->
assertTrue
(
$this
->
connection
->
query
(
'FROM User'
)
instanceof
Doctrine_Collection
);
}
public
function
testDelete
()
{
$user
=
$this
->
connection
->
create
(
'User'
);
$this
->
connection
->
delete
(
$user
);
...
...
@@ -333,27 +172,6 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
public
function
testGetTables
()
{
$this
->
assertTrue
(
is_array
(
$this
->
connection
->
getTables
()));
}
public
function
testTransactions
()
{
$this
->
connection
->
beginTransaction
();
$this
->
assertEqual
(
$this
->
connection
->
transaction
->
getState
(),
Doctrine_Transaction
::
STATE_ACTIVE
);
$this
->
connection
->
commit
();
$this
->
assertEqual
(
$this
->
connection
->
transaction
->
getState
(),
Doctrine_Transaction
::
STATE_SLEEP
);
$this
->
connection
->
beginTransaction
();
$user
=
$this
->
objTable
->
find
(
6
);
$user
->
name
=
'Jack Daniels'
;
$this
->
connection
->
flush
();
$this
->
connection
->
commit
();
$user
=
$this
->
objTable
->
find
(
6
);
$this
->
assertEqual
(
$user
->
name
,
'Jack Daniels'
);
}
public
function
testRollback
()
{
$this
->
connection
->
beginTransaction
();
$this
->
assertEqual
(
$this
->
connection
->
transaction
->
getTransactionLevel
(),
1
);
...
...
tests/DriverTestCase.php
View file @
7131ab9e
...
...
@@ -5,24 +5,35 @@ class AdapterMock implements Doctrine_Adapter_Interface {
private
$queries
=
array
();
private
$exception
=
array
();
private
$lastInsertIdFail
=
false
;
public
function
__construct
(
$name
)
{
public
function
__construct
(
$name
)
{
$this
->
name
=
$name
;
}
public
function
getName
()
{
public
function
getName
()
{
return
$this
->
name
;
}
public
function
pop
()
{
public
function
pop
()
{
return
array_pop
(
$this
->
queries
);
}
public
function
forceException
(
$name
,
$message
=
''
,
$code
=
0
)
{
public
function
forceException
(
$name
,
$message
=
''
,
$code
=
0
)
{
$this
->
exception
=
array
(
$name
,
$message
,
$code
);
}
public
function
prepare
(
$prepareString
){
return
new
AdapterStatementMock
;
public
function
prepare
(
$query
)
{
return
new
AdapterStatementMock
(
$this
,
$query
);
}
public
function
addQuery
(
$query
)
{
$this
->
queries
[]
=
$query
;
}
public
function
query
(
$query
String
)
{
$this
->
queries
[]
=
$query
String
;
public
function
query
(
$query
)
{
$this
->
queries
[]
=
$query
;
$e
=
$this
->
exception
;
...
...
@@ -34,7 +45,7 @@ class AdapterMock implements Doctrine_Adapter_Interface {
throw
new
$name
(
$e
[
1
],
$e
[
2
]);
}
return
new
AdapterStatementMock
;
return
new
AdapterStatementMock
(
$this
,
$query
)
;
}
public
function
getAll
()
{
return
$this
->
queries
;
...
...
@@ -57,10 +68,17 @@ class AdapterMock implements Doctrine_Adapter_Interface {
return
0
;
}
public
function
forceLastInsertIdFail
()
{
$this
->
lastInsertIdFail
=
true
;
}
public
function
lastInsertId
()
{
$this
->
queries
[]
=
'LAST_INSERT_ID()'
;
return
1
;
if
(
$this
->
lastInsertIdFail
)
{
return
null
;
}
else
{
return
1
;
}
}
public
function
beginTransaction
(){
$this
->
queries
[]
=
'BEGIN TRANSACTION'
;
...
...
@@ -68,7 +86,10 @@ class AdapterMock implements Doctrine_Adapter_Interface {
public
function
commit
(){
$this
->
queries
[]
=
'COMMIT'
;
}
public
function
rollBack
(){
}
public
function
rollBack
()
{
$this
->
queries
[]
=
'ROLLBACK'
;
}
public
function
errorCode
(){
}
public
function
errorInfo
(){
}
public
function
getAttribute
(
$attribute
)
{
...
...
@@ -80,6 +101,15 @@ class AdapterMock implements Doctrine_Adapter_Interface {
}
}
class
AdapterStatementMock
{
private
$mock
;
private
$query
;
public
function
__construct
(
AdapterMock
$mock
,
$query
)
{
$this
->
mock
=
$mock
;
$this
->
query
=
$query
;
}
public
function
fetch
(
$fetchMode
)
{
return
array
();
}
...
...
@@ -87,6 +117,7 @@ class AdapterStatementMock {
return
array
();
}
public
function
execute
()
{
$this
->
mock
->
addQuery
(
$this
->
query
);
return
true
;
}
public
function
fetchColumn
(
$colnum
)
{
...
...
tests/SequenceTestCase.php
View file @
7131ab9e
...
...
@@ -40,29 +40,29 @@ class Doctrine_Sequence_TestCase extends Doctrine_UnitTestCase
}
public
function
testSequencesAreSupportedForRecords
()
{
$this
->
profiler
=
new
Doctrine_Db_Profiler
();
$this
->
dbh
->
setListener
(
$this
->
profiler
);
$this
->
adapter
->
forceLastInsertIdFail
();
$r
=
new
CustomSequenceRecord
;
$r
->
name
=
'custom seq'
;
$r
->
save
();
/**
// the last profiled event is transaction commit
$this
->
assertEqual
(
$this
->
profiler
->
pop
()
->
getType
(),
Doctrine_Db_Event
::
COMMIT
);
// query execution
$this
->
assertEqual
(
$this
->
profiler
->
pop
()
->
getQuery
(),
'INSERT INTO custom_sequence_record (name, id) VALUES (?, ?)'
);
$this->assertEqual($this->adapter->pop(), 'COMMIT');
// query execution
$this->assertEqual($this->adapter->pop(), 'INSERT INTO custom_sequence_record (name, id) VALUES (?, ?)');
// query prepare
$this
->
assertEqual
(
$this
->
profiler
->
pop
()
->
getQuery
(),
'INSERT INTO custom_sequence_record (name, id) VALUES (?, ?)'
);
$this->assertEqual($this->
adapter->pop
(), 'INSERT INTO custom_sequence_record (name, id) VALUES (?, ?)');
// sequence generation (first fails)
$this
->
assertEqual
(
$this
->
profiler
->
pop
()
->
getQuery
(),
'INSERT INTO custom_seq_seq (id) VALUES (1)'
);
$this
->
assertEqual
(
$this
->
profiler
->
pop
()
->
getQuery
(),
'CREATE TABLE custom_seq_seq (id INTEGER PRIMARY KEY DEFAULT 0 NOT NULL)'
);
$this
->
assertEqual
(
$this
->
profiler
->
pop
()
->
getQuery
(),
'INSERT INTO custom_seq_seq (id) VALUES (NULL)'
);
$this->assertEqual($this->
adapter->pop
(), 'INSERT INTO custom_seq_seq (id) VALUES (1)');
$this->assertEqual($this->
adapter->pop
(), 'CREATE TABLE custom_seq_seq (id INTEGER PRIMARY KEY DEFAULT 0 NOT NULL)');
$this->assertEqual($this->
adapter->pop
(), 'INSERT INTO custom_seq_seq (id) VALUES (NULL)');
// transaction begin
$this
->
assertEqual
(
$this
->
profiler
->
pop
()
->
getType
(),
Doctrine_Db_Event
::
BEGIN
);
$this
->
assertEqual
(
$this
->
profiler
->
pop
()
->
getQuery
(),
'CREATE TABLE custom_sequence_record (id INTEGER, name VARCHAR(2147483647), PRIMARY KEY(id))'
);
$this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE custom_sequence_record (id INTEGER, name VARCHAR(2147483647), PRIMARY KEY(id))');
*/
}
}
class
CustomSequenceRecord
extends
Doctrine_Record
{
...
...
tests/UnitTestCase.php
View file @
7131ab9e
...
...
@@ -20,7 +20,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
protected
$expr
;
protected
$dataDict
;
protected
$transaction
;
private
$init
=
false
;
...
...
@@ -63,6 +63,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
case
'Expression'
:
case
'Transaction'
:
case
'DataDict'
:
case
'Sequence'
:
$this
->
driverName
=
'Sqlite'
;
break
;
}
...
...
@@ -83,7 +84,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
}
try
{
$this
->
connection
=
$this
->
manager
->
getConnection
(
$this
->
driverName
);
$this
->
conn
=
$this
->
conn
ection
=
$this
->
manager
->
getConnection
(
$this
->
driverName
);
$this
->
connection
->
evictTables
();
$this
->
dbh
=
$this
->
adapter
=
$this
->
connection
->
getDbh
();
$this
->
listener
=
$this
->
manager
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
);
...
...
@@ -91,12 +92,12 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_LISTENER
,
$this
->
listener
);
}
catch
(
Doctrine_Manager_Exception
$e
)
{
if
(
$this
->
driverName
==
'main'
)
{
$this
->
dbh
=
Doctrine_Db
::
getConnection
(
"sqlite::memory:"
);
$this
->
dbh
=
Doctrine_Db
::
getConnection
(
'sqlite::memory:'
);
}
else
{
$this
->
dbh
=
$this
->
adapter
=
new
AdapterMock
(
$this
->
driverName
);
}
$this
->
conn
ection
=
$this
->
manager
->
openConnection
(
$this
->
dbh
,
$this
->
driverName
);
$this
->
conn
=
$this
->
connection
=
$this
->
manager
->
openConnection
(
$this
->
dbh
,
$this
->
driverName
);
if
(
$this
->
driverName
!==
'main'
)
{
$exc
=
'Doctrine_Connection_'
.
ucwords
(
$this
->
driverName
)
.
'_Exception'
;
...
...
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