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
aaf0f4de
Commit
aaf0f4de
authored
Dec 23, 2013
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests to avoid regression
parent
803a9046
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
204 additions
and
0 deletions
+204
-0
StatementTest.php
tests/Doctrine/Tests/DBAL/Portability/StatementTest.php
+195
-0
DriverStatementMock.php
tests/Doctrine/Tests/Mocks/DriverStatementMock.php
+9
-0
No files found.
tests/Doctrine/Tests/DBAL/Portability/StatementTest.php
0 → 100644
View file @
aaf0f4de
<?php
namespace
Doctrine\Tests\DBAL\Portability
;
use
Doctrine\DBAL\Portability\Connection
;
use
Doctrine\DBAL\Portability\Statement
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
StatementTest
extends
\Doctrine\Tests\DbalTestCase
{
/**
* @var \Doctrine\DBAL\Portability\Connection|\PHPUnit_Framework_MockObject_MockObject
*/
protected
$conn
;
/**
* @var \Doctrine\DBAL\Portability\Statement
*/
protected
$stmt
;
/**
* @var \Doctrine\DBAL\Driver\Statement|\PHPUnit_Framework_MockObject_MockObject
*/
protected
$wrappedStmt
;
/**
* {@inheritdoc}
*/
public
function
setUp
()
{
$this
->
wrappedStmt
=
$this
->
createWrappedStatement
();
$this
->
conn
=
$this
->
createConnection
();
$this
->
stmt
=
$this
->
createStatement
(
$this
->
wrappedStmt
,
$this
->
conn
);
}
/**
* @group DBAL-726
*/
public
function
testBindParam
()
{
$column
=
'mycolumn'
;
$variable
=
'myvalue'
;
$type
=
\PDO
::
PARAM_STR
;
$length
=
666
;
$this
->
wrappedStmt
->
expects
(
$this
->
once
())
->
method
(
'bindParam'
)
->
with
(
$column
,
$variable
,
$type
,
$length
)
->
will
(
$this
->
returnValue
(
true
));
$this
->
assertTrue
(
$this
->
stmt
->
bindParam
(
$column
,
$variable
,
$type
,
$length
));
}
public
function
testBindValue
()
{
$param
=
'myparam'
;
$value
=
'myvalue'
;
$type
=
\PDO
::
PARAM_STR
;
$this
->
wrappedStmt
->
expects
(
$this
->
once
())
->
method
(
'bindValue'
)
->
with
(
$param
,
$value
,
$type
)
->
will
(
$this
->
returnValue
(
true
));
$this
->
assertTrue
(
$this
->
stmt
->
bindValue
(
$param
,
$value
,
$type
));
}
public
function
testCloseCursor
()
{
$this
->
wrappedStmt
->
expects
(
$this
->
once
())
->
method
(
'closeCursor'
)
->
will
(
$this
->
returnValue
(
true
));
$this
->
assertTrue
(
$this
->
stmt
->
closeCursor
());
}
public
function
testColumnCount
()
{
$columnCount
=
666
;
$this
->
wrappedStmt
->
expects
(
$this
->
once
())
->
method
(
'columnCount'
)
->
will
(
$this
->
returnValue
(
$columnCount
));
$this
->
assertSame
(
$columnCount
,
$this
->
stmt
->
columnCount
());
}
public
function
testErrorCode
()
{
$errorCode
=
'666'
;
$this
->
wrappedStmt
->
expects
(
$this
->
once
())
->
method
(
'errorCode'
)
->
will
(
$this
->
returnValue
(
$errorCode
));
$this
->
assertSame
(
$errorCode
,
$this
->
stmt
->
errorCode
());
}
public
function
testErrorInfo
()
{
$errorInfo
=
array
(
'666'
,
'Evil error.'
);
$this
->
wrappedStmt
->
expects
(
$this
->
once
())
->
method
(
'errorInfo'
)
->
will
(
$this
->
returnValue
(
$errorInfo
));
$this
->
assertSame
(
$errorInfo
,
$this
->
stmt
->
errorInfo
());
}
public
function
testExecute
()
{
$params
=
array
(
'foo'
,
'bar'
);
$this
->
wrappedStmt
->
expects
(
$this
->
once
())
->
method
(
'execute'
)
->
with
(
$params
)
->
will
(
$this
->
returnValue
(
true
));
$this
->
assertTrue
(
$this
->
stmt
->
execute
(
$params
));
}
public
function
testSetFetchMode
()
{
$fetchMode
=
\PDO
::
FETCH_CLASS
;
$arg1
=
'MyClass'
;
$arg2
=
array
(
1
,
2
);
$this
->
wrappedStmt
->
expects
(
$this
->
once
())
->
method
(
'setFetchMode'
)
->
with
(
$fetchMode
,
$arg1
,
$arg2
)
->
will
(
$this
->
returnValue
(
true
));
$this
->
assertAttributeSame
(
\PDO
::
FETCH_BOTH
,
'defaultFetchMode'
,
$this
->
stmt
);
$this
->
assertTrue
(
$this
->
stmt
->
setFetchMode
(
$fetchMode
,
$arg1
,
$arg2
));
$this
->
assertAttributeSame
(
$fetchMode
,
'defaultFetchMode'
,
$this
->
stmt
);
}
public
function
testGetIterator
()
{
$data
=
array
(
'foo'
=>
'bar'
,
'bar'
=>
'foo'
);
$this
->
wrappedStmt
->
expects
(
$this
->
once
())
->
method
(
'fetchAll'
)
->
will
(
$this
->
returnValue
(
$data
));
$this
->
assertEquals
(
new
\ArrayIterator
(
$data
),
$this
->
stmt
->
getIterator
());
}
public
function
testRowCount
()
{
$rowCount
=
666
;
$this
->
wrappedStmt
->
expects
(
$this
->
once
())
->
method
(
'rowCount'
)
->
will
(
$this
->
returnValue
(
$rowCount
));
$this
->
assertSame
(
$rowCount
,
$this
->
stmt
->
rowCount
());
}
/**
* @return \Doctrine\DBAL\Portability\Connection|\PHPUnit_Framework_MockObject_MockObject
*/
protected
function
createConnection
()
{
return
$this
->
getMockBuilder
(
'Doctrine\DBAL\Portability\Connection'
)
->
disableOriginalConstructor
()
->
getMock
();
}
/**
* @param \Doctrine\DBAL\Driver\Statement $wrappedStatement
* @param \Doctrine\DBAL\Portability\Connection $connection
*
* @return \Doctrine\DBAL\Portability\Statement
*/
protected
function
createStatement
(
\Doctrine\DBAL\Driver\Statement
$wrappedStatement
,
Connection
$connection
)
{
return
new
Statement
(
$wrappedStatement
,
$connection
);
}
/**
* @return \Doctrine\DBAL\Driver\Statement|\PHPUnit_Framework_MockObject_MockObject
*/
protected
function
createWrappedStatement
()
{
return
$this
->
getMock
(
'Doctrine\Tests\Mocks\DriverStatementMock'
);
}
}
tests/Doctrine/Tests/Mocks/DriverStatementMock.php
0 → 100644
View file @
aaf0f4de
<?php
namespace
Doctrine\Tests\Mocks
;
use
Doctrine\DBAL\Driver\Statement
;
interface
DriverStatementMock
extends
Statement
,
\IteratorAggregate
{
}
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