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
0686b53c
Unverified
Commit
0686b53c
authored
Apr 17, 2020
by
Sergei Morozov
Committed by
GitHub
Apr 17, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3957 from morozov/logging-test
Reworked LoggingTest to be able to test Statement::executeUpdate()
parents
95ab0201
59aa258e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
55 deletions
+65
-55
LoggingTest.php
tests/Doctrine/Tests/DBAL/Connection/LoggingTest.php
+65
-0
LoggingTest.php
tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php
+0
-55
No files found.
tests/Doctrine/Tests/DBAL/Connection/LoggingTest.php
0 → 100644
View file @
0686b53c
<?php
namespace
Doctrine\Tests\DBAL\Connection
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\Connection
as
DriverConnection
;
use
Doctrine\DBAL\Driver\Statement
;
use
Doctrine\DBAL\Logging\SQLLogger
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
PHPUnit\Framework\TestCase
;
final
class
LoggingTest
extends
TestCase
{
public
function
testLogExecuteQuery
()
:
void
{
$driverConnection
=
$this
->
createStub
(
DriverConnection
::
class
);
$driverConnection
->
method
(
'query'
)
->
willReturn
(
$this
->
createStub
(
Statement
::
class
));
$this
->
createConnection
(
$driverConnection
,
'SELECT * FROM table'
)
->
executeQuery
(
'SELECT * FROM table'
);
}
public
function
testLogExecuteUpdate
()
:
void
{
$this
->
createConnection
(
$this
->
createStub
(
DriverConnection
::
class
),
'UPDATE table SET foo = ?'
)
->
executeUpdate
(
'UPDATE table SET foo = ?'
);
}
public
function
testLogPrepareExecute
()
:
void
{
$driverConnection
=
$this
->
createStub
(
DriverConnection
::
class
);
$driverConnection
->
method
(
'prepare'
)
->
willReturn
(
$this
->
createStub
(
Statement
::
class
));
$this
->
createConnection
(
$driverConnection
,
'UPDATE table SET foo = ?'
)
->
prepare
(
'UPDATE table SET foo = ?'
)
->
execute
();
}
private
function
createConnection
(
DriverConnection
$driverConnection
,
string
$expectedSQL
)
:
Connection
{
$driver
=
$this
->
createStub
(
Driver
::
class
);
$driver
->
method
(
'connect'
)
->
willReturn
(
$driverConnection
);
$driver
->
method
(
'getDatabasePlatform'
)
->
willReturn
(
$this
->
createMock
(
AbstractPlatform
::
class
));
$logger
=
$this
->
createMock
(
SQLLogger
::
class
);
$logger
->
expects
(
$this
->
once
())
->
method
(
'startQuery'
)
->
with
(
$this
->
equalTo
(
$expectedSQL
),
$this
->
equalTo
([]));
$logger
->
expects
(
$this
->
at
(
1
))
->
method
(
'stopQuery'
);
$connection
=
new
Connection
([],
$driver
);
$connection
->
getConfiguration
()
->
setSQLLogger
(
$logger
);
return
$connection
;
}
}
tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php
deleted
100644 → 0
View file @
95ab0201
<?php
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\Logging\SQLLogger
;
use
Doctrine\Tests\DbalFunctionalTestCase
;
class
LoggingTest
extends
DbalFunctionalTestCase
{
public
function
testLogExecuteQuery
()
:
void
{
$sql
=
$this
->
connection
->
getDatabasePlatform
()
->
getDummySelectSQL
();
$logMock
=
$this
->
createMock
(
SQLLogger
::
class
);
$logMock
->
expects
(
$this
->
at
(
0
))
->
method
(
'startQuery'
)
->
with
(
$this
->
equalTo
(
$sql
),
$this
->
equalTo
([]),
$this
->
equalTo
([]));
$logMock
->
expects
(
$this
->
at
(
1
))
->
method
(
'stopQuery'
);
$this
->
connection
->
getConfiguration
()
->
setSQLLogger
(
$logMock
);
$this
->
connection
->
executeQuery
(
$sql
,
[]);
}
public
function
testLogExecuteUpdate
()
:
void
{
$this
->
markTestSkipped
(
'Test breaks MySQL but works on all other platforms (Unbuffered Queries stuff).'
);
$sql
=
$this
->
connection
->
getDatabasePlatform
()
->
getDummySelectSQL
();
$logMock
=
$this
->
createMock
(
SQLLogger
::
class
);
$logMock
->
expects
(
$this
->
at
(
0
))
->
method
(
'startQuery'
)
->
with
(
$this
->
equalTo
(
$sql
),
$this
->
equalTo
([]),
$this
->
equalTo
([]));
$logMock
->
expects
(
$this
->
at
(
1
))
->
method
(
'stopQuery'
);
$this
->
connection
->
getConfiguration
()
->
setSQLLogger
(
$logMock
);
$this
->
connection
->
executeUpdate
(
$sql
,
[]);
}
public
function
testLogPrepareExecute
()
:
void
{
$sql
=
$this
->
connection
->
getDatabasePlatform
()
->
getDummySelectSQL
();
$logMock
=
$this
->
createMock
(
SQLLogger
::
class
);
$logMock
->
expects
(
$this
->
once
())
->
method
(
'startQuery'
)
->
with
(
$this
->
equalTo
(
$sql
),
$this
->
equalTo
([]));
$logMock
->
expects
(
$this
->
at
(
1
))
->
method
(
'stopQuery'
);
$this
->
connection
->
getConfiguration
()
->
setSQLLogger
(
$logMock
);
$stmt
=
$this
->
connection
->
prepare
(
$sql
);
$stmt
->
execute
();
}
}
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