Passed
Push — 7.x ( 31511a...24122e )
by Adrien
02:40
created

SplFloatTest::testSerialization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Part of SplTypes package.
5
 *
6
 * (c) Adrien Loyant <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Ducks\Component\SplTypes\Tests\phpunit;
15
16
use Ducks\Component\SplTypes\SplFloat as DuckFloat;
17
use PHPUnit\Framework\TestCase;
18
19
class SplFloatTest extends TestCase
20
{
21
    /**
22
     * Unit test.
23
     *
24
     * @return void
25
     */
26
    public function test(): void
27
    {
28
        $instance = new DuckFloat();
29
        $this->assertSame(0.0, $instance());
30
31
        $instance = new DuckFloat(10.1);
32
        $this->assertSame(10.1, $instance());
33
    }
34
35
    /**
36
     * Unit test.
37
     *
38
     * @return void
39
     *
40
     * @psalm-suppress UnsupportedReferenceUsage
41
     */
42
    public function testMath(): void
43
    {
44
        $instance = new DuckFloat(10.1);
45
46
        $value = &$instance();
47
        $value++;
48
49
        $this->assertSame(11.1, $value);
50
        $this->assertSame(11.1, $instance());
51
    }
52
53
    /**
54
     * Unit test.
55
     *
56
     * @return void
57
     */
58
    public function testSerialization(): void
59
    {
60
        $instance = new DuckFloat(22.9);
61
        $serialized = \serialize($instance);
62
        $unserialized = \unserialize($serialized);
63
64
        $this->assertEquals($instance, $unserialized);
65
        $this->assertEquals(22.9, $instance());
66
    }
67
}
68