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

SplBoolTest::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\SplBool as DuckBool;
17
use PHPUnit\Framework\TestCase;
18
19
class SplBoolTest extends TestCase
20
{
21
    /**
22
     * Unit test.
23
     *
24
     * @return void
25
     */
26
    public function test(): void
27
    {
28
        $instance = new DuckBool();
29
        $this->assertFalse($instance());
30
31
        $instance = new DuckBool(true);
32
        $this->assertTrue($instance());
33
    }
34
35
    /**
36
     * Unit test.
37
     *
38
     * @return void
39
     */
40
    public function testGetConstList(): void
41
    {
42
        $list = [
43
            '__default' => false,
44
            'false' => false,
45
            'true' => true,
46
        ];
47
        $instance = new DuckBool();
48
49
        $test = $instance->getConstList(true);
50
        $this->assertSame($list, $test);
51
52
        $test = $instance->getConstList();
53
        unset($list['__default']);
54
        $this->assertSame($list, $test);
55
    }
56
57
    /**
58
     * Unit test.
59
     *
60
     * @return void
61
     */
62
    public function testSerialization(): void
63
    {
64
        $instance = new DuckBool();
65
        $serialized = \serialize($instance);
66
        $unserialized = \unserialize($serialized);
67
68
        $this->assertEquals($instance, $unserialized);
69
        $this->assertFalse($instance());
70
    }
71
}
72