-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathZeroAsNullTest.php
More file actions
67 lines (53 loc) · 1.5 KB
/
ZeroAsNullTest.php
File metadata and controls
67 lines (53 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
62
63
64
65
66
67
<?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\NotConvertable;
use Plook\TypeGuard\TypeGuard;
use stdClass;
use function Plook\TypeGuard\zeroAsNull;
#[CoversClass(TypeGuard::class)]
#[CoversClass(NotConvertable::class)]
#[CoversFunction('Plook\TypeGuard\zeroAsNull')]
final class ZeroAsNullTest extends TestCase
{
public function testConvertsZeroIntToNull(): void
{
self::assertNull(zeroAsNull(0));
}
public function testConvertsZeroFloatToNull(): void
{
self::assertNull(zeroAsNull(0.0));
}
public function testDoesNotTouchInts(): void
{
self::assertSame(1000, zeroAsNull(1000));
}
public function testDoesNotTouchFloats(): void
{
self::assertSame(1234.567, zeroAsNull(1234.567));
}
public function testDoesNotTouchStrings(): void
{
self::assertSame('String', zeroAsNull('String'));
}
public function testDoesNotTouchBlanks(): void
{
self::assertSame('', zeroAsNull(''));
}
public function testDoesTouchTrue(): void
{
self::assertTrue(zeroAsNull(true));
}
public function testDoesTouchFalse(): void
{
self::assertFalse(zeroAsNull(false));
}
public function testDoesNotTouchObjects(): void
{
$object = new stdClass();
self::assertSame($object, zeroAsNull($object));
}
}