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
22b2b6b6
Commit
22b2b6b6
authored
Sep 12, 2017
by
Ian Jenkins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring tests
parent
385cbb7d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
71 deletions
+50
-71
OCI8Connection.php
lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php
+3
-2
DataAccessTest.php
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
+47
-69
No files found.
lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php
View file @
22b2b6b6
...
...
@@ -21,7 +21,6 @@ namespace Doctrine\DBAL\Driver\OCI8;
use
Doctrine\DBAL\Driver\Connection
;
use
Doctrine\DBAL\Driver\ServerInfoAwareConnection
;
use
Doctrine\DBAL\Platforms\OraclePlatform
;
/**
* OCI8 implementation of the Connection interface.
...
...
@@ -38,7 +37,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
/**
* @var integer
*/
protected
$executeMode
=
OCI_COMMIT_ON_SUCCESS
;
protected
$executeMode
;
/**
* Creates a Connection to an Oracle Database using oci8 extension.
...
...
@@ -58,6 +57,8 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
define
(
'OCI_NO_AUTO_COMMIT'
,
0
);
}
$this
->
executeMode
=
OCI_COMMIT_ON_SUCCESS
;
$this
->
dbh
=
$persistent
?
@
oci_pconnect
(
$username
,
$password
,
$db
,
$charset
,
$sessionMode
)
:
@
oci_connect
(
$username
,
$password
,
$db
,
$charset
,
$sessionMode
);
...
...
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
View file @
22b2b6b6
...
...
@@ -3,9 +3,19 @@
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver\Statement
;
use
Doctrine\DBAL\Driver\IBMDB2\DB2Connection
;
use
Doctrine\DBAL\Driver\IBMDB2\DB2Statement
;
use
Doctrine\DBAL\Driver\Mysqli\MysqliConnection
;
use
Doctrine\DBAL\Driver\Mysqli\MysqliStatement
;
use
Doctrine\DBAL\Driver\OCI8\OCI8Connection
;
use
Doctrine\DBAL\Driver\OCI8\OCI8Statement
;
use
Doctrine\DBAL\Driver\SQLAnywhere\SQLAnywhereConnection
;
use
Doctrine\DBAL\Driver\SQLAnywhere\SQLAnywhereStatement
;
use
Doctrine\DBAL\Driver\SQLSrv\SQLSrvConnection
;
use
Doctrine\DBAL\Driver\SQLSrv\SQLSrvStatement
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Types\Type
;
use
IteratorIterator
;
use
PDO
;
class
DataAccessTest
extends
\Doctrine\Tests\DbalFunctionalTestCase
...
...
@@ -868,86 +878,54 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
}
public
function
testIteratorCallsFetchTheExpectedNumberOfTime
s
()
public
function
getConnection
s
()
{
$sql
=
'SELECT test_int, test_string FROM fetch_table'
;
$originalStmt
=
$this
->
_conn
->
prepare
(
$sql
);
// Mock the connection
$connectionMock
=
$this
->
getMockBuilder
(
'Doctrine\\DBAL\\Driver\\Connection'
)
->
setMethods
([
'prepare'
,
'query'
])
->
getMockForAbstractClass
();
$stmtSpy
=
new
StatementSpy
(
$originalStmt
);
// Return our mocked statement from the query
$connectionMock
->
expects
(
$this
->
any
())
->
method
(
'prepare'
)
->
will
(
$this
->
returnValue
(
$stmtSpy
));
$connectionMock
->
expects
(
$this
->
any
())
->
method
(
'query'
)
->
will
(
$this
->
returnCallback
(
function
()
use
(
$stmtSpy
)
{
$stmtSpy
->
execute
();
return
$stmtSpy
;
}));
$stmt
=
$connectionMock
->
query
(
$sql
);
$stmt
->
setFetchMode
(
\PDO
::
FETCH_ASSOC
);
// Assert no fetch calls thus far
self
::
assertEquals
(
0
,
$stmtSpy
->
getFetchCalls
());
$i
=
0
;
foreach
(
$stmt
as
$row
)
{
$i
++
;
return
[
[
MysqliConnection
::
class
,
MysqliStatement
::
class
],
[
OCI8Connection
::
class
,
OCI8Statement
::
class
],
[
DB2Connection
::
class
,
DB2Statement
::
class
],
[
SQLAnywhereConnection
::
class
,
SQLAnywhereStatement
::
class
],
[
SQLSrvConnection
::
class
,
SQLSrvStatement
::
class
],
];
}
// Assert expected number of fetches
$this
->
assertGreaterThan
(
0
,
$stmtSpy
->
getFetchCalls
());
$this
->
assertEquals
(
$i
,
$stmtSpy
->
getFetchCalls
());
}
}
class
StatementSpy
implements
\IteratorAggregate
{
/**
* @
var Statement|\Doctrine\DBAL\Statement
* @
dataProvider getConnections
*/
private
$stmt
;
public
function
testGettingIteratorDoesNotCallFetch
(
$connection
,
$statement
)
{
$stmt
=
$this
->
createPartialMock
(
$statement
,
[
'fetch'
]);
$stmt
->
expects
(
$this
->
never
())
->
method
(
'fetch'
);
private
$fetchCalls
=
0
;
$conn
=
$this
->
createMock
(
$connection
);
$conn
->
expects
(
$this
->
any
())
->
method
(
'prepare'
)
->
willReturn
(
$stmt
);
public
function
__construct
(
Statement
$stmt
)
{
$this
->
stmt
=
$stmt
;
$ii
=
new
IteratorIterator
(
$stmt
);
$ii
->
getInnerIterator
();
}
public
function
setFetchMode
(
$fetchMode
,
$arg2
=
null
,
$arg3
=
null
)
/**
* @dataProvider getConnections
*/
public
function
testIterationCallsFetchOncePerStep
(
$connection
,
$statement
)
{
return
$this
->
stmt
->
setFetchMode
(
$fetchMode
,
$arg2
,
$arg3
)
;
}
$values
=
[
'foo'
,
''
,
'bar'
,
'0'
,
'baz'
,
0
,
'qux'
,
null
,
'quz'
,
false
]
;
$calls
=
0
;
public
function
execute
(
$params
=
null
)
{
return
$this
->
stmt
->
execute
(
$params
);
}
$stmt
=
$this
->
createPartialMock
(
$statement
,
[
'fetch'
]);
$stmt
->
expects
(
$this
->
exactly
(
10
))
->
method
(
'fetch'
)
->
willReturnCallback
(
function
()
use
(
$values
,
&
$calls
)
{
$calls
++
;
yield
from
$values
;
});
public
function
getIterator
()
{
foreach
(
$this
->
stmt
as
$item
)
{
$this
->
fetchCalls
++
;
yield
$item
;
}
}
$conn
=
$this
->
createMock
(
$connection
);
$conn
->
expects
(
$this
->
any
())
->
method
(
'prepare'
)
->
willReturn
(
$stmt
);
public
function
getFetchCalls
()
{
return
$this
->
fetchCalls
;
foreach
(
$stmt
as
$i
=>
$_
)
{
$_
->
next
();
$this
->
assertEquals
(
$i
+
1
,
$calls
);
}
}
}
class
MyFetchClass
{
public
$test_int
,
$test_string
,
$test_datetime
;
}
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