|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Plook\Tests\TypeGuard; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 8 | +use PHPUnit\Framework\Attributes\CoversFunction; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use Plook\TypeGuard\NotConvertable; |
| 11 | +use Plook\TypeGuard\TypeGuard; |
| 12 | +use stdClass; |
| 13 | + |
| 14 | +use function Plook\TypeGuard\zeroAsNull; |
| 15 | + |
| 16 | +#[CoversClass(TypeGuard::class)] |
| 17 | +#[CoversClass(NotConvertable::class)] |
| 18 | +#[CoversFunction('\Plook\TypeGuard\zeroAsNull')] |
| 19 | +final class ZeroAsNullTest extends TestCase |
| 20 | +{ |
| 21 | + public function testConvertsZeroIntToNull(): void |
| 22 | + { |
| 23 | + self::assertNull(zeroAsNull(0)); |
| 24 | + } |
| 25 | + |
| 26 | + public function testConvertsZeroFloatToNull(): void |
| 27 | + { |
| 28 | + self::assertNull(zeroAsNull(0.0)); |
| 29 | + } |
| 30 | + |
| 31 | + public function testDoesNotTouchInts(): void |
| 32 | + { |
| 33 | + self::assertSame(1000, zeroAsNull(1000)); |
| 34 | + } |
| 35 | + |
| 36 | + public function testDoesNotTouchFloats(): void |
| 37 | + { |
| 38 | + self::assertSame(1234.567, zeroAsNull(1234.567)); |
| 39 | + } |
| 40 | + |
| 41 | + public function testDoesNotTouchStrings(): void |
| 42 | + { |
| 43 | + self::assertSame('String', zeroAsNull('String')); |
| 44 | + } |
| 45 | + |
| 46 | + public function testDoesNotTouchBlanks(): void |
| 47 | + { |
| 48 | + self::assertSame('', zeroAsNull('')); |
| 49 | + } |
| 50 | + |
| 51 | + public function testDoesTouchTrue(): void |
| 52 | + { |
| 53 | + self::assertTrue(zeroAsNull(true)); |
| 54 | + } |
| 55 | + |
| 56 | + public function testDoesTouchFalse(): void |
| 57 | + { |
| 58 | + self::assertFalse(zeroAsNull(false)); |
| 59 | + } |
| 60 | + |
| 61 | + public function testDoesNotTouchObjects(): void |
| 62 | + { |
| 63 | + $object = new stdClass(); |
| 64 | + |
| 65 | + self::assertSame($object, zeroAsNull($object)); |
| 66 | + } |
| 67 | +} |
0 commit comments