| Total Complexity | 4 |
| Total Lines | 99 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class PackDataUnitTest extends TestCase |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Testing data provider |
||
| 17 | * |
||
| 18 | * @return array testing data |
||
| 19 | */ |
||
| 20 | public function packDataDataProvider(): array |
||
| 21 | { |
||
| 22 | return [ |
||
| 23 | // #0, list of scalars |
||
| 24 | [ |
||
| 25 | [ |
||
| 26 | 'a' => 1, |
||
| 27 | 'b' => 2 |
||
| 28 | ], |
||
| 29 | 'a=1&b=2' |
||
| 30 | ], |
||
| 31 | // #1, nested array |
||
| 32 | [ |
||
| 33 | [ |
||
| 34 | 'arr' => [ |
||
| 35 | 'key' => 'value' |
||
| 36 | ] |
||
| 37 | ], |
||
| 38 | 'arr[key]=value' |
||
| 39 | ], |
||
| 40 | // #2, deeper nested arrays |
||
| 41 | [ |
||
| 42 | [ |
||
| 43 | 'field' => [ |
||
| 44 | [ |
||
| 45 | 'key' => 'value' |
||
| 46 | ] |
||
| 47 | ] |
||
| 48 | ], |
||
| 49 | 'field[0][key]=value' |
||
| 50 | ] |
||
| 51 | ]; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Testing method packData |
||
| 56 | * |
||
| 57 | * @param array $data |
||
| 58 | * data to be packed |
||
| 59 | * @param string $expected |
||
| 60 | * expected result |
||
| 61 | * @dataProvider packDataDataProvider |
||
| 62 | */ |
||
| 63 | public function testPackData(array $data, string $expected): void |
||
| 64 | { |
||
| 65 | // test body |
||
| 66 | $result = CurlWrapper::packData($data); |
||
| 67 | |||
| 68 | // assertions |
||
| 69 | $this->assertEquals($expected, $result); |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Data provider |
||
| 74 | * |
||
| 75 | * @return array Testing data |
||
| 76 | */ |
||
| 77 | public function packDataExceptionDataProvider(): array |
||
| 91 | ] |
||
| 92 | ] |
||
| 93 | ] |
||
| 94 | ]; |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Testing exception throwing |
||
| 99 | * |
||
| 100 | * @param array $data |
||
| 101 | * test data |
||
| 102 | * @dataProvider packDataExceptionDataProvider |
||
| 103 | */ |
||
| 104 | public function testExceptionWhilePackingData(array $data): void |
||
| 113 |