-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAsFloatTest.php
More file actions
61 lines (50 loc) · 1.49 KB
/
Copy pathAsFloatTest.php
File metadata and controls
61 lines (50 loc) · 1.49 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\StringableFloat;
use Plook\TypeGuard\NotConvertable;
use Plook\TypeGuard\TypeGuard;
use function basename;
use function Plook\TypeGuard\asFloat;
use function sprintf;
#[CoversClass(TypeGuard::class)]
#[CoversClass(NotConvertable::class)]
#[CoversFunction('Plook\TypeGuard\asFloat')]
final class AsFloatTest extends TestCase
{
public function testDoesNotTouchFloats(): void
{
self::assertSame(1000.9, asFloat(1000.9));
}
public function testConvertsStrings(): void
{
self::assertSame(1000.9, asFloat('1000.9'));
}
public function testConvertsStringables(): void
{
self::assertSame(1000.9, asFloat(new StringableFloat(1000.9)));
}
public function testConvertsInts(): void
{
self::assertSame(1000.0, asFloat(1000));
}
public function testDoesNotTouchNull(): void
{
self::assertNull(asFloat(null));
}
public function testOnlyScalarsAreConvertable(): void
{
$this->expectException(NotConvertable::class);
$this->expectExceptionMessageMatches(
sprintf(
'/Closure is not convertable to float in %s:%s/',
basename(__FILE__),
__LINE__ + 4,
),
);
asFloat(static fn (): null => null);
}
}