1+ <?php declare (strict_types=1 );
2+
3+ namespace XBase \Tests \DataConverter \Field \DBase ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use XBase \Column \ColumnInterface ;
7+ use XBase \DataConverter \Field \DBase \NumberConverter ;
8+ use XBase \Table ;
9+
10+ /**
11+ * @author Alexander Strizhak <[email protected] > 12+ *
13+ * @coversDefaultClass \XBase\DataConverter\Field\DBase\NumberConverter
14+ */
15+ class NumberConverterTest extends TestCase
16+ {
17+ /**
18+ * Issue #99
19+ * @covers ::toBinaryString
20+ * @dataProvider dataRightDecimalCount
21+ *
22+ * @param int|float $in
23+ */
24+ public function testRightDecimalCount (int $ length , int $ decimalCount , $ in , string $ out )
25+ {
26+ $ table = $ this ->createMock (Table::class);
27+ $ column = $ this ->createMock (ColumnInterface::class);
28+ $ column
29+ ->method ('getLength ' )
30+ ->willReturn ($ length );
31+ $ column
32+ ->method ('getDecimalCount ' )
33+ ->willReturn ($ decimalCount );
34+
35+ $ fieldConverter = new NumberConverter ($ table , $ column );
36+ self ::assertSame ($ out , $ fieldConverter ->toBinaryString ($ in ));
37+ }
38+
39+ public function dataRightDecimalCount ()
40+ {
41+ yield [10 , 3 , null , str_repeat (chr (0x00 ), 10 )];
42+ yield [10 , 0 , 10 , ' 10 ' ];
43+ yield [10 , 3 , 10.123 , ' 10.123 ' ];
44+ yield [10 , 3 , 10 , ' 10.000 ' ];
45+ yield [10 , 3 , 1 , ' 1.000 ' ];
46+ }
47+ }
0 commit comments