Skip to content

Commit 2166b33

Browse files
Add missing tests
1 parent 71f7c9a commit 2166b33

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

tests/unit/Framework/Assert/assertThatTest.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use function fclose;
1515
use function fopen;
1616
use PHPUnit\Framework\Attributes\CoversClass;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1718
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
1819
use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations;
1920
use PHPUnit\Framework\Attributes\Small;
@@ -27,6 +28,37 @@
2728
#[Small]
2829
final class assertThatTest extends TestCase
2930
{
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+
3062
#[DoesNotPerformAssertions]
3163
public function testAssertThatAnything(): void
3264
{
@@ -246,10 +278,18 @@ public function testAssertThatIsInstanceOf(): void
246278
$this->assertThat(new stdClass, $this->isInstanceOf(stdClass::class));
247279
}
248280

281+
#[DataProvider('typeProvider')]
249282
#[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
251289
{
252-
$this->assertThat('string', $this->isType('string'));
290+
$this->expectException(UnknownNativeTypeException::class);
291+
292+
$this->isType('unknown');
253293
}
254294

255295
public function testAssertThatIsArray(): void

0 commit comments

Comments
 (0)