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
b6ffa045
Commit
b6ffa045
authored
Nov 06, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
1d5bdee6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
74 deletions
+73
-74
DBTestCase.php
tests/DBTestCase.php
+73
-74
No files found.
tests/DBTestCase.php
View file @
b6ffa045
<?php
require_once
(
"../draft/DB.php"
);
class
Doctrine_D
B
_TestLogger
implements
Doctrine_Overloadable
{
class
Doctrine_D
b
_TestLogger
implements
Doctrine_Overloadable
{
private
$messages
=
array
();
public
function
__call
(
$m
,
$a
)
{
...
...
@@ -14,16 +14,16 @@ class Doctrine_DB_TestLogger implements Doctrine_Overloadable {
return
$this
->
messages
;
}
}
class
Doctrine_D
B_TestValidListener
extends
Doctrine_DB
_EventListener
{
}
class
Doctrine_D
B
_TestInvalidListener
{
}
class
Doctrine_D
b_TestValidListener
extends
Doctrine_Db
_EventListener
{
}
class
Doctrine_D
b
_TestInvalidListener
{
}
class
Doctrine_D
B
_TestCase
extends
Doctrine_UnitTestCase
{
class
Doctrine_D
b
_TestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareData
()
{
}
public
function
prepareTables
()
{
}
public
function
init
()
{
}
public
function
testFetchAll
()
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
->
connect
();
...
...
@@ -49,7 +49,7 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
));
}
public
function
testFetchOne
()
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'sqlite::memory:'
);
$c
=
$dbh
->
fetchOne
(
'SELECT COUNT(1) FROM entity'
);
...
...
@@ -64,7 +64,7 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
}
public
function
testFetchColumn
()
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'sqlite::memory:'
);
$a
=
$dbh
->
fetchColumn
(
'SELECT * FROM entity'
);
...
...
@@ -80,7 +80,7 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
));
}
public
function
testFetchArray
()
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'sqlite::memory:'
);
$a
=
$dbh
->
fetchArray
(
'SELECT * FROM entity'
);
...
...
@@ -97,7 +97,7 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
));
}
public
function
testFetchRow
()
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'sqlite::memory:'
);
$c
=
$dbh
->
fetchRow
(
'SELECT * FROM entity'
);
...
...
@@ -117,60 +117,60 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
}
public
function
testAddValidEventListener
()
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'sqlite::memory:'
);
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
B
_EventListener
);
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
b
_EventListener
);
try
{
$ret
=
$dbh
->
addListener
(
new
Doctrine_D
B
_TestLogger
());
$ret
=
$dbh
->
addListener
(
new
Doctrine_D
b
_TestLogger
());
$this
->
pass
();
$this
->
assertTrue
(
$ret
instanceof
Doctrine_D
B
2
);
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
$this
->
assertTrue
(
$ret
instanceof
Doctrine_D
b
2
);
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
fail
();
}
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
B
_EventListener_Chain
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
0
)
instanceof
Doctrine_D
B
_TestLogger
);
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
b
_EventListener_Chain
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
0
)
instanceof
Doctrine_D
b
_TestLogger
);
try
{
$ret
=
$dbh
->
addListener
(
new
Doctrine_D
B
_TestValidListener
());
$ret
=
$dbh
->
addListener
(
new
Doctrine_D
b
_TestValidListener
());
$this
->
pass
();
$this
->
assertTrue
(
$ret
instanceof
Doctrine_D
B
2
);
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
$this
->
assertTrue
(
$ret
instanceof
Doctrine_D
b
2
);
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
fail
();
}
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
B
_EventListener_Chain
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
0
)
instanceof
Doctrine_D
B
_TestLogger
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
1
)
instanceof
Doctrine_D
B
_TestValidListener
);
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
b
_EventListener_Chain
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
0
)
instanceof
Doctrine_D
b
_TestLogger
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
1
)
instanceof
Doctrine_D
b
_TestValidListener
);
try
{
$ret
=
$dbh
->
addListener
(
new
Doctrine_D
B
_EventListener_Chain
(),
'chain'
);
$ret
=
$dbh
->
addListener
(
new
Doctrine_D
b
_EventListener_Chain
(),
'chain'
);
$this
->
pass
();
$this
->
assertTrue
(
$ret
instanceof
Doctrine_D
B
2
);
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
$this
->
assertTrue
(
$ret
instanceof
Doctrine_D
b
2
);
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
fail
();
}
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
B
_EventListener_Chain
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
0
)
instanceof
Doctrine_D
B
_TestLogger
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
1
)
instanceof
Doctrine_D
B
_TestValidListener
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
'chain'
)
instanceof
Doctrine_D
B
_EventListener_Chain
);
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
b
_EventListener_Chain
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
0
)
instanceof
Doctrine_D
b
_TestLogger
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
1
)
instanceof
Doctrine_D
b
_TestValidListener
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
'chain'
)
instanceof
Doctrine_D
b
_EventListener_Chain
);
// replacing
try
{
$ret
=
$dbh
->
addListener
(
new
Doctrine_D
B
_EventListener_Chain
(),
'chain'
);
$ret
=
$dbh
->
addListener
(
new
Doctrine_D
b
_EventListener_Chain
(),
'chain'
);
$this
->
pass
();
$this
->
assertTrue
(
$ret
instanceof
Doctrine_D
B
2
);
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
$this
->
assertTrue
(
$ret
instanceof
Doctrine_D
b
2
);
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
fail
();
}
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
B
_EventListener_Chain
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
0
)
instanceof
Doctrine_D
B
_TestLogger
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
1
)
instanceof
Doctrine_D
B
_TestValidListener
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
'chain'
)
instanceof
Doctrine_D
B
_EventListener_Chain
);
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
b
_EventListener_Chain
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
0
)
instanceof
Doctrine_D
b
_TestLogger
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
1
)
instanceof
Doctrine_D
b
_TestValidListener
);
$this
->
assertTrue
(
$dbh
->
getListener
()
->
get
(
'chain'
)
instanceof
Doctrine_D
b
_EventListener_Chain
);
}
public
function
testListeningEventsWithSingleListener
()
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
->
connect
();
$dbh
->
setListener
(
new
Doctrine_D
B
_TestLogger
());
$dbh
->
setListener
(
new
Doctrine_D
b
_TestLogger
());
$listener
=
$dbh
->
getListener
();
$stmt
=
$dbh
->
prepare
(
'INSERT INTO entity (id) VALUES(?)'
);
...
...
@@ -205,10 +205,10 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
$dbh
->
query
(
'DROP TABLE entity'
);
}
public
function
testListeningEventsWithListenerChain
()
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
->
connect
();
$dbh
->
addListener
(
new
Doctrine_D
B
_TestLogger
());
$dbh
->
addListener
(
new
Doctrine_D
B
_TestLogger
());
$dbh
->
addListener
(
new
Doctrine_D
b
_TestLogger
());
$dbh
->
addListener
(
new
Doctrine_D
b
_TestLogger
());
$dbh
->
query
(
'CREATE TABLE entity (id INT)'
);
...
...
@@ -266,98 +266,98 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
$dbh
->
query
(
'DROP TABLE entity'
);
}
public
function
testSetValidEventListener
()
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'sqlite::memory:'
);
try
{
$dbh
->
setListener
(
new
Doctrine_D
B
_TestLogger
());
$dbh
->
setListener
(
new
Doctrine_D
b
_TestLogger
());
$this
->
pass
();
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
fail
();
}
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
B
_TestLogger
);
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
b
_TestLogger
);
try
{
$dbh
->
setListener
(
new
Doctrine_D
B
_TestValidListener
());
$dbh
->
setListener
(
new
Doctrine_D
b
_TestValidListener
());
$this
->
pass
();
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
fail
();
}
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
B
_TestValidListener
);
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
b
_TestValidListener
);
try
{
$dbh
->
setListener
(
new
Doctrine_D
B
_EventListener_Chain
());
$dbh
->
setListener
(
new
Doctrine_D
b
_EventListener_Chain
());
$this
->
pass
();
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
fail
();
}
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
B
_EventListener_Chain
);
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
b
_EventListener_Chain
);
try
{
$dbh
->
setListener
(
new
Doctrine_D
B
_EventListener
());
$dbh
->
setListener
(
new
Doctrine_D
b
_EventListener
());
$this
->
pass
();
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
fail
();
}
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
B
_EventListener
);
$this
->
assertTrue
(
$dbh
->
getListener
()
instanceof
Doctrine_D
b
_EventListener
);
}
public
function
testSetInvalidEventListener
()
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'sqlite::memory:'
);
try
{
$dbh
->
setListener
(
new
Doctrine_D
B
_TestInvalidListener
());
$dbh
->
setListener
(
new
Doctrine_D
b
_TestInvalidListener
());
$this
->
fail
();
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testInvalidDSN
()
{
try
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
''
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
''
);
$this
->
fail
();
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
pass
();
}
try
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'unknown'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'unknown'
);
$this
->
fail
();
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
pass
();
}
try
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
0
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
0
);
$this
->
fail
();
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testInvalidScheme
()
{
try
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'unknown://:memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'unknown://:memory:'
);
$this
->
fail
();
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testInvalidHost
()
{
try
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'mysql://user:password@'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'mysql://user:password@'
);
$this
->
fail
();
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testInvalidDatabase
()
{
try
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'mysql://user:password@host/'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'mysql://user:password@host/'
);
$this
->
fail
();
}
catch
(
Doctrine_D
B
_Exception
$e
)
{
}
catch
(
Doctrine_D
b
_Exception
$e
)
{
$this
->
pass
();
}
}
public
function
testGetConnectionPdoLikeDSN
()
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'mysql:host=localhost;dbname=test'
,
'root'
,
'password'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'mysql:host=localhost;dbname=test'
,
'root'
,
'password'
);
$this
->
assertEqual
(
$dbh
->
getDSN
(),
'mysql:host=localhost;dbname=test'
);
$this
->
assertEqual
(
$dbh
->
getUsername
(),
'root'
);
$this
->
assertEqual
(
$dbh
->
getPassword
(),
'password'
);
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'sqlite::memory:'
);
$this
->
assertEqual
(
$dbh
->
getDSN
(),
'sqlite::memory:'
);
$this
->
assertEqual
(
$dbh
->
getUsername
(),
null
);
...
...
@@ -368,13 +368,13 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
}
public
function
testGetConnectionWithPearLikeDSN
()
{
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'mysql://zYne:password@localhost/test'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'mysql://zYne:password@localhost/test'
);
$this
->
assertEqual
(
$dbh
->
getDSN
(),
'mysql:host=localhost;dbname=test'
);
$this
->
assertEqual
(
$dbh
->
getUsername
(),
'zYne'
);
$this
->
assertEqual
(
$dbh
->
getPassword
(),
'password'
);
$dbh
=
Doctrine_D
B
2
::
getConnection
(
'sqlite://:memory:'
);
$dbh
=
Doctrine_D
b
2
::
getConnection
(
'sqlite://:memory:'
);
$this
->
assertEqual
(
$dbh
->
getDSN
(),
'sqlite::memory:'
);
$this
->
assertEqual
(
$dbh
->
getUsername
(),
null
);
...
...
@@ -382,4 +382,3 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
}
}
?>
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