|
11 | 11 | */ |
12 | 12 | class ArrayReaderTest extends TestCase |
13 | 13 | { |
| 14 | + /** |
| 15 | + * Test. |
| 16 | + * |
| 17 | + * @dataProvider providerGetInt |
| 18 | + * |
| 19 | + * @param mixed $data The data |
| 20 | + * @param string $key The lookup key |
| 21 | + * @param mixed $default The default value |
| 22 | + * @param mixed $expected The expected value |
| 23 | + * |
| 24 | + * @return void |
| 25 | + */ |
| 26 | + public function testGetInt($data, string $key, $default, $expected) |
| 27 | + { |
| 28 | + $reader = new ArrayReader($data); |
| 29 | + static::assertSame($expected, $reader->getInt($key, $default)); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Test. |
| 34 | + * |
| 35 | + * @dataProvider providerGetIntError |
| 36 | + * |
| 37 | + * @param mixed $data The data |
| 38 | + * @param string $key The lookup key |
| 39 | + * @param mixed $default The default value |
| 40 | + * |
| 41 | + * @return void |
| 42 | + */ |
| 43 | + public function testGetIntError($data, string $key, $default) |
| 44 | + { |
| 45 | + $reader = new ArrayReader($data); |
| 46 | + |
| 47 | + $this->expectException(InvalidArgumentException::class); |
| 48 | + |
| 49 | + $reader->getInt($key, $default); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Test. |
| 54 | + * |
| 55 | + * @dataProvider providerFindInt |
| 56 | + * |
| 57 | + * @param mixed $data The data |
| 58 | + * @param string $key The lookup key |
| 59 | + * @param mixed $default The default value |
| 60 | + * @param mixed $expected The expected value |
| 61 | + * |
| 62 | + * @return void |
| 63 | + */ |
| 64 | + public function testFindInt($data, string $key, $default, $expected) |
| 65 | + { |
| 66 | + $reader = new ArrayReader($data); |
| 67 | + static::assertSame($expected, $reader->findInt($key, $default)); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Provider. |
| 72 | + * |
| 73 | + * @return array[] The test data |
| 74 | + */ |
| 75 | + public function providerGetInt(): array |
| 76 | + { |
| 77 | + return [ |
| 78 | + [[0, 1, 2, 3], 0, null, 0], |
| 79 | + [[0, 1, 2, 3], 1, null, 1], |
| 80 | + [[0, 1, 2, 3], 2, null, 2], |
| 81 | + [[0, 1, 2, 3], 3, null, 3], |
| 82 | + ]; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Provider. |
| 87 | + * |
| 88 | + * @return array[] The test data |
| 89 | + */ |
| 90 | + public function providerGetIntError(): array |
| 91 | + { |
| 92 | + return [ |
| 93 | + [[0, 1, 2, 3], 4, null], |
| 94 | + [[0, 1, 2, 3, null], 4, null], |
| 95 | + [[0, 1, 2, null, 4], 3, null], |
| 96 | + ]; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Provider. |
| 101 | + * |
| 102 | + * @return array[] The test data |
| 103 | + */ |
| 104 | + public function providerFindInt(): array |
| 105 | + { |
| 106 | + return [ |
| 107 | + [[0, 1, 2, 3], 0, null, 0], |
| 108 | + [[0, 1, 2, 3], 1, null, 1], |
| 109 | + [[0, 1, 2, 3], 2, null, 2], |
| 110 | + [[0, 1, 2, 3], 3, null, 3], |
| 111 | + [[0, 1, 2, 3], 4, null, null], |
| 112 | + [[0, 1, 2, 3, null], 4, null, null], |
| 113 | + [[0, 1, 2, null, 4], 3, null, null], |
| 114 | + ]; |
| 115 | + } |
| 116 | + |
14 | 117 | /** |
15 | 118 | * Test. |
16 | 119 | * |
|
0 commit comments