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
ec662f3e
Commit
ec662f3e
authored
Nov 22, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added new driver tests
parent
9200d127
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
267 additions
and
9 deletions
+267
-9
DriverTestCase.php
tests/DriverTestCase.php
+98
-0
ExportMysqlTestCase.php
tests/ExportMysqlTestCase.php
+20
-1
ExportOracleTestCase.php
tests/ExportOracleTestCase.php
+26
-0
ExportTestCase.php
tests/ExportTestCase.php
+5
-8
TransactionMysqlTestCase.php
tests/TransactionMysqlTestCase.php
+39
-0
TransactionTestCase.php
tests/TransactionTestCase.php
+79
-0
No files found.
tests/DriverTestCase.php
0 → 100644
View file @
ec662f3e
<?php
class
AdapterMock
implements
Doctrine_Adapter_Interface
{
private
$name
;
private
$queries
=
array
();
public
function
__construct
(
$name
)
{
$this
->
name
=
$name
;
}
public
function
getName
()
{
return
$this
->
name
;
}
public
function
pop
()
{
return
array_pop
(
$this
->
queries
);
}
public
function
prepare
(
$prepareString
){
return
new
AdapterStatementMock
;
}
public
function
query
(
$queryString
)
{
$this
->
queries
[]
=
$queryString
;
return
new
AdapterStatementMock
;
}
public
function
quote
(
$input
){
}
public
function
exec
(
$statement
)
{
$this
->
queries
[]
=
$statement
;
return
0
;
}
public
function
lastInsertId
(){
}
public
function
beginTransaction
(){
$this
->
queries
[]
=
'BEGIN TRANSACTION'
;
}
public
function
commit
(){
$this
->
queries
[]
=
'COMMIT'
;
}
public
function
rollBack
(){
}
public
function
errorCode
(){
}
public
function
errorInfo
(){
}
public
function
getAttribute
(
$attribute
)
{
if
(
$attribute
==
PDO
::
ATTR_DRIVER_NAME
)
return
$this
->
name
;
}
public
function
setAttribute
(
$attribute
,
$value
)
{
}
}
class
AdapterStatementMock
{
public
function
fetch
(
$fetchMode
)
{
return
array
();
}
public
function
fetchAll
(
$fetchMode
)
{
return
array
();
}
}
class
Doctrine_Driver_UnitTestCase
extends
UnitTestCase
{
protected
$driverName
=
false
;
protected
$generic
=
false
;
protected
$manager
;
protected
$conn
;
protected
$adapter
;
protected
$export
;
protected
$dataDict
;
protected
$transaction
;
public
function
__construct
(
$driverName
,
$generic
=
false
)
{
$this
->
driverName
=
$driverName
;
$this
->
generic
=
$generic
;
}
public
function
init
()
{
$this
->
adapter
=
new
AdapterMock
(
$this
->
driverName
);
$this
->
manager
=
Doctrine_Manager
::
getInstance
();
$this
->
manager
->
setDefaultAttributes
();
$this
->
conn
=
$this
->
manager
->
openConnection
(
$this
->
adapter
);
if
(
!
$this
->
generic
)
{
$this
->
export
=
$this
->
conn
->
export
;
$tx
=
'Doctrine_Transaction_'
.
ucwords
(
$this
->
adapter
->
getName
());
if
(
class_exists
(
$tx
))
$this
->
transaction
=
new
$tx
(
$this
->
conn
);
//$this->dataDict = $this->conn->dataDict;
}
else
{
$this
->
export
=
new
Doctrine_Export
(
$this
->
conn
);
$this
->
transaction
=
new
Doctrine_Transaction
(
$this
->
conn
);
}
}
public
function
setUp
()
{
static
$init
=
false
;
if
(
!
$init
)
{
$this
->
init
();
$init
=
true
;
}
}
}
?>
tests/ExportMysqlTestCase.php
View file @
ec662f3e
...
...
@@ -3,6 +3,25 @@ class Doctrine_Export_Mysql_TestCase extends Doctrine_Export_TestCase {
public
function
__construct
()
{
parent
::
__construct
(
'mysql'
);
}
public
function
testAlterTableThrowsExceptionWithoutValidTableName
()
{
try
{
$this
->
export
->
alterTable
(
0
,
0
,
array
());
$this
->
fail
();
}
catch
(
Doctrine_Export_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testCreateTableExecutesSql
()
{
$name
=
'mytable'
;
$fields
=
array
(
'id'
=>
array
(
'type'
=>
'integer'
,
'unsigned'
=>
1
));
$options
=
array
(
'type'
=>
'foo'
);
//$this->export->createTable($name, $fields, $options);
}
public
function
testCreateDatabaseExecutesSql
()
{
$this
->
export
->
createDatabase
(
'db'
);
...
...
tests/ExportOracleTestCase.php
0 → 100644
View file @
ec662f3e
<?php
class
Doctrine_Export_Oracle_TestCase
extends
Doctrine_Export_TestCase
{
public
function
__construct
()
{
parent
::
__construct
(
'oci'
);
}
public
function
testCreateSequenceExecutesSql
()
{
$sequenceName
=
'sequence'
;
$start
=
1
;
$query
=
'CREATE SEQUENCE '
.
$sequenceName
.
' START WITH '
.
$start
.
' INCREMENT BY 1 NOCACHE'
;
$this
->
export
->
createSequence
(
$sequenceName
,
$start
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
$query
);
}
public
function
testDropSequenceExecutesSql
()
{
$sequenceName
=
'sequence'
;
$query
=
'DROP SEQUENCE '
.
$sequenceName
;;
$this
->
export
->
dropSequence
(
$sequenceName
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
$query
);
}
}
?>
tests/ExportTestCase.php
View file @
ec662f3e
<?php
class
Doctrine_Export_TestCase
extends
Doctrine_Driver_UnitTestCase
{
public
function
testAlterTableThrowsExceptionWithoutValidTableName
()
{
try
{
$this
->
export
->
alterTable
(
0
,
0
,
array
());
$this
->
fail
();
}
catch
(
Doctrine_Export_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testCreateTableThrowsExceptionWithoutValidTableName
()
{
try
{
$this
->
export
->
createTable
(
0
,
array
(),
array
());
...
...
@@ -28,6 +20,11 @@ class Doctrine_Export_TestCase extends Doctrine_Driver_UnitTestCase {
$this
->
pass
();
}
}
public
function
testDropConstraintExecutesSql
()
{
$this
->
export
->
dropConstraint
(
'sometable'
,
'relevancy'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'ALTER TABLE sometable DROP CONSTRAINT relevancy'
);
}
public
function
testCreateIndexExecutesSql
()
{
$this
->
export
->
createIndex
(
'sometable'
,
'relevancy'
,
array
(
'fields'
=>
array
(
'title'
=>
array
(),
'content'
=>
array
())));
...
...
tests/TransactionMysqlTestCase.php
0 → 100644
View file @
ec662f3e
<?php
class
Doctrine_Transaction_Mysql_TestCase
extends
Doctrine_Driver_UnitTestCase
{
public
function
__construct
()
{
parent
::
__construct
(
'mysql'
);
}
public
function
testCreateSavePointExecutesSql
()
{
$this
->
transaction
->
createSavePoint
(
'mypoint'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'SAVEPOINT mypoint'
);
}
public
function
testReleaseSavePointExecutesSql
()
{
$this
->
transaction
->
releaseSavePoint
(
'mypoint'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'RELEASE SAVEPOINT mypoint'
);
}
public
function
testRollbackSavePointExecutesSql
()
{
$this
->
transaction
->
rollbackSavePoint
(
'mypoint'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'ROLLBACK TO SAVEPOINT mypoint'
);
}
public
function
testGetIsolationExecutesSql
()
{
$this
->
transaction
->
getIsolation
();
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'SELECT @@tx_isolation'
);
}
public
function
testSetIsolationThrowsExceptionOnUnknownIsolationMode
()
{
try
{
$this
->
transaction
->
setIsolation
(
'unknown'
);
$this
->
fail
();
}
catch
(
Doctrine_Transaction_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testSetIsolationExecutesSql
()
{
$this
->
transaction
->
setIsolation
(
'READ UNCOMMITTED'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED'
);
}
}
tests/TransactionTestCase.php
0 → 100644
View file @
ec662f3e
<?php
class
Doctrine_Transaction_TestCase
extends
Doctrine_Driver_UnitTestCase
{
public
function
__construct
()
{
parent
::
__construct
(
'sqlite'
,
true
);
}
public
function
testCreateSavepointIsOnlyImplementedAtDriverLevel
()
{
try
{
$this
->
transaction
->
createSavePoint
(
'point'
);
$this
->
fail
();
}
catch
(
Doctrine_Transaction_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testReleaseSavepointIsOnlyImplementedAtDriverLevel
()
{
try
{
$this
->
transaction
->
releaseSavePoint
(
'point'
);
$this
->
fail
();
}
catch
(
Doctrine_Transaction_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testRollbackSavepointIsOnlyImplementedAtDriverLevel
()
{
try
{
$this
->
transaction
->
rollbackSavePoint
(
'point'
);
$this
->
fail
();
}
catch
(
Doctrine_Transaction_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testSetIsolationIsOnlyImplementedAtDriverLevel
()
{
try
{
$this
->
transaction
->
setIsolation
(
'READ UNCOMMITTED'
);
$this
->
fail
();
}
catch
(
Doctrine_Transaction_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testGetIsolationIsOnlyImplementedAtDriverLevel
()
{
try
{
$this
->
transaction
->
GetIsolation
(
'READ UNCOMMITTED'
);
$this
->
fail
();
}
catch
(
Doctrine_Transaction_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testTransactionLevelIsInitiallyZero
()
{
$this
->
assertEqual
(
$this
->
transaction
->
getTransactionLevel
(),
0
);
}
public
function
testGetStateReturnsStateConstant
()
{
$this
->
assertEqual
(
$this
->
transaction
->
getState
(),
Doctrine_Transaction
::
STATE_SLEEP
);
}
public
function
testExceptionIsThrownWhenCommittingNotActiveTransaction
()
{
try
{
$this
->
transaction
->
commit
();
$this
->
fail
();
}
catch
(
Doctrine_Transaction_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testExceptionIsThrownWhenUsingRollbackOnNotActiveTransaction
()
{
try
{
$this
->
transaction
->
rollback
();
$this
->
fail
();
}
catch
(
Doctrine_Transaction_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testBeginTransactionStartsNewTransaction
()
{
$this
->
transaction
->
beginTransaction
();
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'BEGIN TRANSACTION'
);
}
public
function
testCommitMethodCommitsCurrentTransaction
()
{
$this
->
transaction
->
commit
();
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'COMMIT'
);
}
}
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