-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNotNullTest.php
More file actions
58 lines (47 loc) · 1.31 KB
/
NotNullTest.php
File metadata and controls
58 lines (47 loc) · 1.31 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
<?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\TypeGuard\InvalidValue;
use Plook\TypeGuard\TypeGuard;
use stdClass;
use function basename;
use function Plook\TypeGuard\notNull;
use function sprintf;
#[CoversClass(TypeGuard::class)]
#[CoversClass(InvalidValue::class)]
#[CoversFunction('Plook\TypeGuard\notNull')]
final class NotNullTest extends TestCase
{
public function testDoesNotTouchInts(): void
{
self::assertSame(1000, notNull(1000));
}
public function testDoesNotTouchStrings(): void
{
self::assertSame('1000', notNull('1000'));
}
public function testDoesNotTouchFloats(): void
{
self::assertSame(1000.1, notNull(1000.1));
}
public function testDoesNotTouchObjects(): void
{
$object = new stdClass();
self::assertSame($object, notNull($object));
}
public function testDetectsNulls(): void
{
$this->expectException(InvalidValue::class);
$this->expectExceptionMessageMatches(
sprintf(
'/null.* %s:%s/',
basename(__FILE__),
__LINE__ + 4,
),
);
notNull(null);
}
}