|
11 | 11 |
|
12 | 12 | class DimensionTest extends TestCase |
13 | 13 | { |
14 | | - public function constructorDataProvider() |
| 14 | + public function constructorDataProvider(): iterable |
15 | 15 | { |
16 | | - return [ |
17 | | - [1, 1], |
18 | | - [5, 5], |
19 | | - [ |
20 | | - 0, |
21 | | - 1, |
22 | | - InvalidArgumentException::class, |
23 | | - 'Length of either side cannot be 0 or negative, current size is 0x1', |
24 | | - ], |
25 | | - [ |
26 | | - 1, |
27 | | - 0, |
28 | | - InvalidArgumentException::class, |
29 | | - 'Length of either side cannot be 0 or negative, current size is 1x0', |
30 | | - ], |
31 | | - [ |
32 | | - 0, |
33 | | - 0, |
34 | | - InvalidArgumentException::class, |
35 | | - 'Length of either side cannot be 0 or negative, current size is 0x0', |
36 | | - ], |
37 | | - [ |
38 | | - -1, |
39 | | - 1, |
40 | | - InvalidArgumentException::class, |
41 | | - 'Length of either side cannot be 0 or negative, current size is -1x1', |
42 | | - ], |
43 | | - [ |
44 | | - 1, |
45 | | - -1, |
46 | | - InvalidArgumentException::class, |
47 | | - 'Length of either side cannot be 0 or negative, current size is 1x-1', |
48 | | - ], |
49 | | - [ |
50 | | - -1, |
51 | | - -1, |
52 | | - InvalidArgumentException::class, |
53 | | - 'Length of either side cannot be 0 or negative, current size is -1x-1', |
54 | | - ], |
55 | | - [null, 1, TypeError::class], |
56 | | - [1, null, TypeError::class], |
57 | | - ]; |
| 16 | + yield [1, 1]; |
| 17 | + yield [5, 5]; |
58 | 18 | } |
59 | 19 |
|
60 | 20 | /** |
61 | 21 | * @dataProvider constructorDataProvider |
62 | 22 | */ |
63 | | - public function testConstructor( |
| 23 | + public function testConstructor(int $width, int $height): void |
| 24 | + { |
| 25 | + $this->expectNotToPerformAssertions(); |
| 26 | + new Dimension($width, $height); |
| 27 | + } |
| 28 | + |
| 29 | + public function constructorExceptionsDataProvider(): iterable |
| 30 | + { |
| 31 | + yield [ |
| 32 | + 0, |
| 33 | + 1, |
| 34 | + InvalidArgumentException::class, |
| 35 | + 'Length of either side cannot be 0 or negative, current size is 0x1', |
| 36 | + ]; |
| 37 | + yield [ |
| 38 | + 1, |
| 39 | + 0, |
| 40 | + InvalidArgumentException::class, |
| 41 | + 'Length of either side cannot be 0 or negative, current size is 1x0', |
| 42 | + ]; |
| 43 | + yield [ |
| 44 | + 0, |
| 45 | + 0, |
| 46 | + InvalidArgumentException::class, |
| 47 | + 'Length of either side cannot be 0 or negative, current size is 0x0', |
| 48 | + ]; |
| 49 | + yield [ |
| 50 | + -1, |
| 51 | + 1, |
| 52 | + InvalidArgumentException::class, |
| 53 | + 'Length of either side cannot be 0 or negative, current size is -1x1', |
| 54 | + ]; |
| 55 | + yield [ |
| 56 | + 1, |
| 57 | + -1, |
| 58 | + InvalidArgumentException::class, |
| 59 | + 'Length of either side cannot be 0 or negative, current size is 1x-1', |
| 60 | + ]; |
| 61 | + yield [ |
| 62 | + -1, |
| 63 | + -1, |
| 64 | + InvalidArgumentException::class, |
| 65 | + 'Length of either side cannot be 0 or negative, current size is -1x-1', |
| 66 | + ]; |
| 67 | + yield [null, 1, TypeError::class]; |
| 68 | + yield [1, null, TypeError::class]; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @dataProvider constructorExceptionsDataProvider |
| 73 | + */ |
| 74 | + public function testConstructorExceptions( |
64 | 75 | ?int $width, |
65 | 76 | ?int $height, |
66 | | - ?string $expectException = null, |
| 77 | + string $expectException, |
67 | 78 | ?string $expectExceptionMessage = null |
68 | 79 | ): void { |
69 | | - if ($expectException !== null) { |
70 | | - $this->expectException($expectException); |
71 | | - $this->expectExceptionMessage($expectExceptionMessage); |
72 | | - } else { |
73 | | - $this->expectNotToPerformAssertions(); |
74 | | - } |
| 80 | + $this->expectException($expectException); |
| 81 | + $this->expectExceptionMessage($expectExceptionMessage); |
75 | 82 |
|
76 | 83 | new Dimension($width, $height); |
77 | 84 | } |
|
0 commit comments