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
4a9119b8
Commit
4a9119b8
authored
Jul 02, 2015
by
Martin Prebio
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding test cases for RunSqlCommand
parent
4ec16d06
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
0 deletions
+109
-0
RunSqlCommandTest.php
...s/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php
+109
-0
No files found.
tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php
0 → 100644
View file @
4a9119b8
<?php
namespace
Doctrine\Tests\DBAL\Tools\Console
;
use
Doctrine\DBAL\Tools\Console\Command\RunSqlCommand
;
use
Doctrine\DBAL\Tools\Console\ConsoleRunner
;
use
Symfony\Component\Console\Application
;
use
Symfony\Component\Console\Tester\CommandTester
;
class
RunSqlCommandTest
extends
\PHPUnit_Framework_TestCase
{
/** @var CommandTester */
private
$commandTester
;
/** @var RunSqlCommand */
private
$command
;
private
$connectionMock
;
protected
function
setUp
()
{
$application
=
new
Application
();
$application
->
add
(
new
RunSqlCommand
());
$this
->
command
=
$application
->
find
(
'dbal:run-sql'
);
$this
->
commandTester
=
new
CommandTester
(
$this
->
command
);
$this
->
connectionMock
=
$this
->
getMock
(
'\Doctrine\DBAL\Connection'
,
array
(),
array
(),
''
,
false
);
$this
->
connectionMock
->
method
(
'fetchAll'
)
->
willReturn
(
array
(
array
(
1
)));
$this
->
connectionMock
->
method
(
'executeUpdate'
)
->
willReturn
(
42
);
$helperSet
=
ConsoleRunner
::
createHelperSet
(
$this
->
connectionMock
);
$this
->
command
->
setHelperSet
(
$helperSet
);
}
public
function
testMissingSqlArgument
()
{
try
{
$this
->
commandTester
->
execute
(
array
(
'command'
=>
$this
->
command
->
getName
(),
'sql'
=>
null
,
));
$this
->
fail
(
'Expected a runtime exception when omitting sql argument'
);
}
catch
(
\RuntimeException
$e
)
{
$this
->
assertContains
(
"Argument 'SQL"
,
$e
->
getMessage
());
}
}
public
function
testIncorrectDepthOption
()
{
try
{
$this
->
commandTester
->
execute
(
array
(
'command'
=>
$this
->
command
->
getName
(),
'sql'
=>
'SELECT 1'
,
'--depth'
=>
'string'
,
));
$this
->
fail
(
'Expected a logic exception when executing with a stringy depth'
);
}
catch
(
\LogicException
$e
)
{
$this
->
assertContains
(
"Option 'depth'"
,
$e
->
getMessage
());
}
}
public
function
testSelectStatementsPrintsResult
()
{
$this
->
expectConnectionFetchAll
();
$this
->
commandTester
->
execute
(
array
(
'command'
=>
$this
->
command
->
getName
(),
'sql'
=>
'SELECT 1'
,
));
$this
->
assertRegExp
(
'@int.*1.*@'
,
$this
->
commandTester
->
getDisplay
());
$this
->
assertRegExp
(
'@array.*1.*@'
,
$this
->
commandTester
->
getDisplay
());
}
public
function
testUpdateStatementsPrintsAffectedLines
()
{
$this
->
expectConnectionExecuteUpdate
();
$this
->
commandTester
->
execute
(
array
(
'command'
=>
$this
->
command
->
getName
(),
'sql'
=>
'UPDATE foo SET bar = 42'
,
));
$this
->
assertRegExp
(
'@int.*42.*@'
,
$this
->
commandTester
->
getDisplay
());
$this
->
assertNotRegExp
(
'@array.*1.*@'
,
$this
->
commandTester
->
getDisplay
());
}
private
function
expectConnectionExecuteUpdate
()
{
$this
->
connectionMock
->
expects
(
$this
->
exactly
(
1
))
->
method
(
'executeUpdate'
);
$this
->
connectionMock
->
expects
(
$this
->
exactly
(
0
))
->
method
(
'fetchAll'
);
}
private
function
expectConnectionFetchAll
()
{
$this
->
connectionMock
->
expects
(
$this
->
exactly
(
0
))
->
method
(
'executeUpdate'
);
$this
->
connectionMock
->
expects
(
$this
->
exactly
(
1
))
->
method
(
'fetchAll'
);
}
}
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