-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAsStringTest.php
More file actions
61 lines (50 loc) · 1.5 KB
/
AsStringTest.php
File metadata and controls
61 lines (50 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
namespace Plook\Tests\TypeGuard;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\CoversFunction;
use PHPUnit\Framework\TestCase;
use Plook\Tests\TypeGuard\Helper\StringableInt;
use Plook\TypeGuard\NotConvertable;
use Plook\TypeGuard\TypeGuard;
use function basename;
use function Plook\TypeGuard\asString;
use function sprintf;
#[CoversClass(TypeGuard::class)]
#[CoversClass(NotConvertable::class)]
#[CoversFunction('Plook\TypeGuard\asString')]
final class AsStringTest extends TestCase
{
public function testDoesNotTouchStrings(): void
{
self::assertSame('1000', asString('1000'));
}
public function testConvertsStrings(): void
{
self::assertSame('1000', asString(1000));
}
public function testConvertsStringables(): void
{
self::assertSame('1000', asString(new StringableInt(1000)));
}
public function testConvertsFloats(): void
{
self::assertSame('1000.1', asString(1000.1));
}
public function testDoesNotTouchNull(): void
{
self::assertNull(asString(null));
}
public function testOnlyScalarsAreConvertable(): void
{
$this->expectException(NotConvertable::class);
$this->expectExceptionMessageMatches(
sprintf(
'/Closure is not convertable to string in %s:%s/',
basename(__FILE__),
__LINE__ + 4,
),
);
asSTring(static fn (): null => null);
}
}