|
14 | 14 | use function fclose;
|
15 | 15 | use function fopen;
|
16 | 16 | use PHPUnit\Framework\Attributes\CoversClass;
|
| 17 | +use PHPUnit\Framework\Attributes\DataProvider; |
17 | 18 | use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
|
18 | 19 | use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations;
|
19 | 20 | use PHPUnit\Framework\Attributes\Small;
|
|
27 | 28 | #[Small]
|
28 | 29 | final class assertThatTest extends TestCase
|
29 | 30 | {
|
| 31 | + /** |
| 32 | + * @return non-empty-list<array{0: non-empty-string, 1: mixed}> |
| 33 | + */ |
| 34 | + public static function typeProvider(): array |
| 35 | + { |
| 36 | + $closedResource = fopen(__FILE__, 'r'); |
| 37 | + |
| 38 | + fclose($closedResource); |
| 39 | + |
| 40 | + return [ |
| 41 | + ['array', []], |
| 42 | + ['bool', false], |
| 43 | + ['boolean', false], |
| 44 | + ['callable', static function (): void |
| 45 | + {}], |
| 46 | + ['double', 0.1], |
| 47 | + ['float', 0.1], |
| 48 | + ['int', 0], |
| 49 | + ['integer', 0], |
| 50 | + ['iterable', []], |
| 51 | + ['null', null], |
| 52 | + ['numeric', '0.0'], |
| 53 | + ['object', new stdClass], |
| 54 | + ['real', 0.1], |
| 55 | + ['resource', fopen(__FILE__, 'r')], |
| 56 | + ['resource (closed)', $closedResource], |
| 57 | + ['scalar', 'string'], |
| 58 | + ['string', 'string'], |
| 59 | + ]; |
| 60 | + } |
| 61 | + |
30 | 62 | #[DoesNotPerformAssertions]
|
31 | 63 | public function testAssertThatAnything(): void
|
32 | 64 | {
|
@@ -246,10 +278,18 @@ public function testAssertThatIsInstanceOf(): void
|
246 | 278 | $this->assertThat(new stdClass, $this->isInstanceOf(stdClass::class));
|
247 | 279 | }
|
248 | 280 |
|
| 281 | + #[DataProvider('typeProvider')] |
249 | 282 | #[IgnorePhpunitDeprecations]
|
250 |
| - public function testAssertThatIsType(): void |
| 283 | + public function testAssertThatIsType(string $type, mixed $value): void |
| 284 | + { |
| 285 | + $this->assertThat($value, $this->isType($type)); |
| 286 | + } |
| 287 | + |
| 288 | + public function testUnknownNativeTypeCannotBeMapped(): void |
251 | 289 | {
|
252 |
| - $this->assertThat('string', $this->isType('string')); |
| 290 | + $this->expectException(UnknownNativeTypeException::class); |
| 291 | + |
| 292 | + $this->isType('unknown'); |
253 | 293 | }
|
254 | 294 |
|
255 | 295 | public function testAssertThatIsArray(): void
|
|
0 commit comments