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
03d69eea
Commit
03d69eea
authored
Jan 09, 2010
by
guilhermeblanco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Added some tests for CLI
parent
d2b59d7a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
223 additions
and
4 deletions
+223
-4
Option.php
lib/Doctrine/Common/Cli/Option.php
+7
-3
OptionGroup.php
lib/Doctrine/Common/Cli/OptionGroup.php
+1
-1
AllTests.php
tests/Doctrine/Tests/Common/AllTests.php
+1
-0
AllTests.php
tests/Doctrine/Tests/Common/Cli/AllTests.php
+32
-0
OptionGroupTest.php
tests/Doctrine/Tests/Common/Cli/OptionGroupTest.php
+123
-0
OptionTest.php
tests/Doctrine/Tests/Common/Cli/OptionTest.php
+40
-0
StyleTest.php
tests/Doctrine/Tests/Common/Cli/StyleTest.php
+19
-0
No files found.
lib/Doctrine/Common/Cli/Option.php
View file @
03d69eea
...
...
@@ -38,6 +38,7 @@ class Option
private
$_name
;
/** @var string Option default value */
private
$_defaultValue
;
/** @var string Option description */
private
$description
;
...
...
@@ -69,7 +70,7 @@ class Option
/**
* Retrieves the CLI Option default value
*
* @return
string|null
Option default value
* @return
mixed
Option default value
*/
public
function
getDefaultValue
()
{
...
...
@@ -93,7 +94,10 @@ class Option
*/
public
function
__toString
()
{
return
'--'
.
$this
->
_name
.
((
!
is_null
(
$this
->
_defaultValue
))
?
'='
.
$this
->
_defaultValue
:
''
);
$defaultValue
=
(
!
is_null
(
$this
->
_defaultValue
))
?
'='
.
(
is_array
(
$this
->
_defaultValue
)
?
implode
(
','
,
$this
->
_defaultValue
)
:
$this
->
_defaultValue
)
:
''
;
return
'--'
.
$this
->
_name
.
$defaultValue
;
}
}
\ No newline at end of file
lib/Doctrine/Common/Cli/OptionGroup.php
View file @
03d69eea
...
...
@@ -467,7 +467,7 @@ class OptionGroup
$optionStr
=
(
string
)
$option
;
// Format Option string
$str
.
=
$printer
->
format
(
$optionStr
,
$style
);
$str
=
$printer
->
format
(
$optionStr
,
$style
);
// Include missing spaces
$str
.=
str_repeat
(
' '
,
$maxOptionLength
-
strlen
(
$optionStr
));
...
...
tests/Doctrine/Tests/Common/AllTests.php
View file @
03d69eea
...
...
@@ -30,6 +30,7 @@ class AllTests
$suite
->
addTest
(
Collections\AllTests
::
suite
());
$suite
->
addTest
(
Annotations\AllTests
::
suite
());
$suite
->
addTest
(
Cache\AllTests
::
suite
());
$suite
->
addTest
(
Cli\AllTests
::
suite
());
return
$suite
;
}
...
...
tests/Doctrine/Tests/Common/Cli/AllTests.php
0 → 100644
View file @
03d69eea
<?php
namespace
Doctrine\Tests\Common\Cli
;
if
(
!
defined
(
'PHPUnit_MAIN_METHOD'
))
{
define
(
'PHPUnit_MAIN_METHOD'
,
'Common_Cli_AllTests::main'
);
}
require_once
__DIR__
.
'/../../TestInit.php'
;
class
AllTests
{
public
static
function
main
()
{
\PHPUnit_TextUI_TestRunner
::
run
(
self
::
suite
());
}
public
static
function
suite
()
{
$suite
=
new
\Doctrine\Tests\DoctrineTestSuite
(
'Doctrine Common CLI Tests'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\Common\Cli\OptionTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\Common\Cli\OptionGroupTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\Common\Cli\StyleTest'
);
return
$suite
;
}
}
if
(
PHPUnit_MAIN_METHOD
==
'Common_Cli_AllTests::main'
)
{
AllTests
::
main
();
}
\ No newline at end of file
tests/Doctrine/Tests/Common/Cli/OptionGroupTest.php
0 → 100644
View file @
03d69eea
<?php
namespace
Doctrine\Tests\Common\Cli
;
use
Doctrine\Common\Cli\Printers\NormalPrinter
,
Doctrine\Common\Cli\OptionGroup
,
Doctrine\Common\Cli\Option
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
OptionGroupTest
extends
\Doctrine\Tests\DoctrineTestCase
{
private
$_options
=
array
();
public
function
setUp
()
{
$this
->
_printer
=
new
NormalPrinter
();
$this
->
_options
[
0
]
=
new
Option
(
'name'
,
null
,
'First option description'
);
$this
->
_options
[
1
]
=
new
Option
(
'another-name'
,
'value'
,
'Second option description'
);
$this
->
_options
[
2
]
=
new
Option
(
'third-name'
,
array
(
'value1'
,
'value2'
),
'Third option description'
);
}
public
function
testCommonFunctionality
()
{
$optionGroup
=
new
OptionGroup
(
OptionGroup
::
CARDINALITY_0_N
,
$this
->
_options
);
$this
->
assertEquals
(
3
,
count
(
$optionGroup
->
getOptions
()));
$this
->
assertEquals
(
'--name First option description'
.
PHP_EOL
.
PHP_EOL
.
'--another-name=value Second option description'
.
PHP_EOL
.
PHP_EOL
.
'--third-name=value1,value2 Third option description'
.
PHP_EOL
.
PHP_EOL
,
$optionGroup
->
formatWithDescription
(
$this
->
_printer
)
);
$optionGroup
->
clear
();
$this
->
assertEquals
(
0
,
count
(
$optionGroup
->
getOptions
()));
$this
->
assertEquals
(
''
,
$optionGroup
->
formatPlain
(
$this
->
_printer
));
$this
->
assertEquals
(
'No available options'
.
PHP_EOL
.
PHP_EOL
,
$optionGroup
->
formatWithDescription
(
$this
->
_printer
)
);
$optionGroup
->
addOption
(
$this
->
_options
[
0
]);
$optionGroup
->
addOption
(
$this
->
_options
[
1
]);
$this
->
assertEquals
(
2
,
count
(
$optionGroup
->
getOptions
()));
}
public
function
testCardinality0toN
()
{
$optionGroup
=
new
OptionGroup
(
OptionGroup
::
CARDINALITY_0_N
,
$this
->
_options
);
$this
->
assertEquals
(
OptionGroup
::
CARDINALITY_0_N
,
$optionGroup
->
getCardinality
());
$this
->
assertEquals
(
'[--name] [--another-name=value] [--third-name=value1,value2]'
,
$optionGroup
->
formatPlain
(
$this
->
_printer
)
);
}
public
function
testCardinality0to1
()
{
$optionGroup
=
new
OptionGroup
(
OptionGroup
::
CARDINALITY_0_1
,
$this
->
_options
);
$this
->
assertEquals
(
OptionGroup
::
CARDINALITY_0_1
,
$optionGroup
->
getCardinality
());
$this
->
assertEquals
(
'[--name | --another-name=value | --third-name=value1,value2]'
,
$optionGroup
->
formatPlain
(
$this
->
_printer
)
);
}
public
function
testCardinality1to1
()
{
$optionGroup
=
new
OptionGroup
(
OptionGroup
::
CARDINALITY_1_1
,
$this
->
_options
);
$this
->
assertEquals
(
OptionGroup
::
CARDINALITY_1_1
,
$optionGroup
->
getCardinality
());
$this
->
assertEquals
(
'(--name | --another-name=value | --third-name=value1,value2)'
,
$optionGroup
->
formatPlain
(
$this
->
_printer
)
);
}
public
function
testCardinality1toN
()
{
$optionGroup
=
new
OptionGroup
(
OptionGroup
::
CARDINALITY_1_N
,
$this
->
_options
);
$this
->
assertEquals
(
OptionGroup
::
CARDINALITY_1_N
,
$optionGroup
->
getCardinality
());
$this
->
assertEquals
(
'(--name --another-name=value --third-name=value1,value2)'
,
$optionGroup
->
formatPlain
(
$this
->
_printer
)
);
}
public
function
testCardinalityNtoN
()
{
$optionGroup
=
new
OptionGroup
(
OptionGroup
::
CARDINALITY_N_N
,
$this
->
_options
);
$this
->
assertEquals
(
OptionGroup
::
CARDINALITY_N_N
,
$optionGroup
->
getCardinality
());
$this
->
assertEquals
(
'--name --another-name=value --third-name=value1,value2'
,
$optionGroup
->
formatPlain
(
$this
->
_printer
)
);
}
public
function
testCardinalityMtoN
()
{
$optionGroup
=
new
OptionGroup
(
OptionGroup
::
CARDINALITY_M_N
,
$this
->
_options
);
$this
->
assertEquals
(
OptionGroup
::
CARDINALITY_M_N
,
$optionGroup
->
getCardinality
());
$this
->
assertEquals
(
'--name --another-name=value --third-name=value1,value2'
,
$optionGroup
->
formatPlain
(
$this
->
_printer
)
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/Common/Cli/OptionTest.php
0 → 100644
View file @
03d69eea
<?php
namespace
Doctrine\Tests\Common\Cli
;
use
Doctrine\Common\Cli\Option
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
OptionTest
extends
\Doctrine\Tests\DoctrineTestCase
{
public
function
testGetMethods
()
{
$option
=
new
Option
(
'name'
,
'value'
,
'Description'
);
$this
->
assertEquals
(
'name'
,
$option
->
getName
());
$this
->
assertEquals
(
'value'
,
$option
->
getDefaultValue
());
$this
->
assertEquals
(
'Description'
,
$option
->
getDescription
());
}
public
function
testStringCastWithDefaultValue
()
{
$option
=
new
Option
(
'name'
,
'value'
,
'Description'
);
$this
->
assertEquals
(
'--name=value'
,
(
string
)
$option
);
}
public
function
testStringCastWithoutDefaultValue
()
{
$option
=
new
Option
(
'name'
,
null
,
'Description'
);
$this
->
assertEquals
(
'--name'
,
(
string
)
$option
);
}
public
function
testStringCastWithArrayDefaultValue
()
{
$option
=
new
Option
(
'name'
,
array
(
'value1'
,
'value2'
),
'Description'
);
$this
->
assertEquals
(
'--name=value1,value2'
,
(
string
)
$option
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/Common/Cli/StyleTest.php
0 → 100644
View file @
03d69eea
<?php
namespace
Doctrine\Tests\Common\Cli
;
use
Doctrine\Common\Cli\Style
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
StyleTest
extends
\Doctrine\Tests\DoctrineTestCase
{
public
function
testGetMethods
()
{
$style
=
new
Style
(
'BLACK'
,
'WHITE'
,
array
(
'BOLD'
=>
true
));
$this
->
assertEquals
(
'BLACK'
,
$style
->
getForeground
());
$this
->
assertEquals
(
'WHITE'
,
$style
->
getBackground
());
$this
->
assertEquals
(
array
(
'BOLD'
=>
true
),
$style
->
getOptions
());
}
}
\ No newline at end of file
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