ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
DataSizeTest Class Reference

Testing the DataSize object. More...

+ Inheritance diagram for DataSizeTest:
+ Collaboration diagram for DataSizeTest:

Public Member Functions

 provideDataSizes ()
 
 testDifferentDataSizes (int $bytes, string $expected_representation)
 @dataProvider provideDataSizes More...
 
 test_normal ($a, $b, $expected, $expected_in_bytes)
 @dataProvider tDataProvider More...
 
 test_division_by_zero ()
 
 tDataProvider ()
 

Detailed Description

Member Function Documentation

◆ provideDataSizes()

DataSizeTest::provideDataSizes ( )

Definition at line 33 of file DataSizeTest.php.

33 : array
34 {
35 return [
36 [1000, '1000 B'],
37 [1001, '1 KB'],
38 [1023, '1.02 KB'],
39 [1024, '1.02 KB'],
40 [1025, '1.03 KB'],
41 [10000, '10 KB'],
42 [11000, '11 KB'],
43 [28_566_695, '28.57 MB'],
44 [48_521_625, '48.52 MB'],
45 [58_777_412_654, '58.78 GB'],
46 [46_546_544_654_545, '46.55 TB'],
47 [125_862_151_563_255_622, '125862.15 TB'],
48 ];
49 }

◆ tDataProvider()

DataSizeTest::tDataProvider ( )

Definition at line 85 of file DataSizeTest.php.

85 : array
86 {
87 return [
88 [122, 1000, "122 B", 122],
89 [-122, 1000, "-122 B", -122],
90 [122, 1_000_000, "122 B", 122],
91 [-122, 1_000_000, "-122 B", -122],
92 [122, 1_000_000_000, "122 B", 122],
93 [-122, 1_000_000_000, "-122 B", -122],
94 [122, 1_000_000_000_000, "122 B", null], // There is a float rounding error here
95 [-122, 1_000_000_000_000, "-122 B", null], // There is a float rounding error here
96 [122, 1024, "122 B", 122],
97 [-122, 1024, "-122 B", -122],
98 [122, 1_048_576, "122 B", 122],
99 [-122, 1_048_576, "-122 B", -122],
100 [122, 1_073_741_824, "122 B", 122],
101 [-122, 1_073_741_824, "-122 B", -122],
102 [122, 1_099_511_627_776, "122 B", 122],
103 [-122, 1_099_511_627_776, "-122 B", -122],
104 [10 * DataSize::KiB, DataSize::KiB, "10.24 KB", 10 * DataSize::KiB],
105 ];
106 }

◆ test_division_by_zero()

DataSizeTest::test_division_by_zero ( )

Definition at line 75 of file DataSizeTest.php.

75 : void
76 {
77 try {
78 $ds = new DataSize(4533, 0);
79 $this->assertFalse("This should not happen");
80 } catch (Exception | DivisionByZeroError $e) {
81 $this->assertTrue(true);
82 }
83 }
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:31

References Vendor\Package\$e.

◆ test_normal()

DataSizeTest::test_normal (   $a,
  $b,
  $expected,
  $expected_in_bytes 
)

@dataProvider tDataProvider

Definition at line 64 of file DataSizeTest.php.

64 : void
65 {
66 $ds = new DataSize($a, $b);
67 $this->assertEquals($a / $b, $ds->getSize());
68 $this->assertEquals($b, $ds->getUnit());
69 $this->assertEquals($expected, $ds->__toString());
70 if ($expected_in_bytes) {
71 $this->assertEquals($expected_in_bytes, (int) $ds->inBytes());
72 }
73 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, and Vendor\Package\$b.

◆ testDifferentDataSizes()

DataSizeTest::testDifferentDataSizes ( int  $bytes,
string  $expected_representation 
)

@dataProvider provideDataSizes

Definition at line 54 of file DataSizeTest.php.

54 : void
55 {
56 $datasize = new DataSize($bytes, DataSize::Byte);
57
58 $this->assertEquals($expected_representation, $datasize->__toString());
59 }

The documentation for this class was generated from the following file: