Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1949543
formatterTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Oct 29, 6:37 AM
Size
2 KB
Mime Type
text/x-php
Expires
Sat, Oct 31, 6:37 AM (8 h, 54 m)
Engine
blob
Format
Raw Data
Handle
963459
Attached To
rINP In-Portal
formatterTest.php
View Options
<?php
/**
* The class name must match the file name for Phabricator-invoked PHPUnit to run this test.
*
* TODO: Once "formatter.php" file is renamed we can rename this class/filename as well.
*/
final
class
formatterTest
extends
AbstractTestCase
// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
{
/**
* @dataProvider cutZerosDataProvider
*/
public
function
testCutZeros
(
$raw_number
,
$formatted_number
,
array
$field_options
)
{
$formatter
=
new
kFormatter
();
$item_prophecy
=
$this
->
prophesize
(
'kDBItem'
);
$item_prophecy
->
GetFieldOptions
(
'FieldName'
)->
willReturn
(
array
(
'type'
=>
'float'
,
'format'
=>
'%01.6f'
,
)
+
$field_options
);
$item
=
$item_prophecy
->
reveal
();
$this
->
assertSame
(
$formatted_number
,
$formatter
->
Format
(
$raw_number
,
'FieldName'
,
$item
));
}
public
function
cutZerosDataProvider
()
{
return
array
(
'long'
=>
array
(
'12.345000'
,
'12.345'
,
array
(
'cut_zeros'
=>
1
)),
'short'
=>
array
(
'12.300000'
,
'12.3'
,
array
(
'cut_zeros'
=>
1
)),
'exact+leading_zero'
=>
array
(
'12.030000'
,
'12.03'
,
array
(
'cut_zeros'
=>
1
)),
'very_long'
=>
array
(
'12.030050'
,
'12.03005'
,
array
(
'cut_zeros'
=>
1
)),
'no_decimals'
=>
array
(
'12.000000'
,
'12'
,
array
(
'cut_zeros'
=>
1
)),
);
}
/**
* @dataProvider keepCentsDataProvider
*/
public
function
testKeepCents
(
$raw_number
,
$formatted_number
,
array
$field_options
)
{
$formatter
=
new
kFormatter
();
$item_prophecy
=
$this
->
prophesize
(
'kDBItem'
);
$item_prophecy
->
GetFieldOptions
(
'FieldName'
)->
willReturn
(
array
(
'type'
=>
'float'
,
'format'
=>
'%01.6f'
,
)
+
$field_options
);
$item
=
$item_prophecy
->
reveal
();
$this
->
assertSame
(
$formatted_number
,
$formatter
->
Format
(
$raw_number
,
'FieldName'
,
$item
));
}
public
function
keepCentsDataProvider
()
{
return
array
(
'long'
=>
array
(
'12.345000'
,
'12.345'
,
array
(
'keep_cents'
=>
2
)),
'short'
=>
array
(
'12.300000'
,
'12.30'
,
array
(
'keep_cents'
=>
2
)),
'exact+leading_zero'
=>
array
(
'12.030000'
,
'12.03'
,
array
(
'keep_cents'
=>
2
)),
'very_long'
=>
array
(
'12.030050'
,
'12.03005'
,
array
(
'keep_cents'
=>
2
)),
'no_decimals'
=>
array
(
'12.000000'
,
'12.00'
,
array
(
'keep_cents'
=>
2
)),
);
}
}
Event Timeline
Log In to Comment