Passed
Push — 7.x ( af8963...debb41 )
by Adrien
02:47
created

SplStringTest::testStringCast()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
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\SplString as DuckString;
17
use PHPUnit\Framework\TestCase;
18
19
class SplStringTest extends TestCase
20
{
21
    /**
22
     * Unit test.
23
     *
24
     * @return void
25
     */
26
    public function test(): void
27
    {
28
        $instance = new DuckString();
29
        $this->assertSame('', $instance());
30
31
        $instance = new DuckString('hello world');
32
        $this->assertSame('hello world', $instance());
33
    }
34
35
    /**
36
     * Unit test.
37
     *
38
     * @return void
39
     *
40
     * @psalm-suppress UnsupportedReferenceUsage
41
     */
42
    public function testConcatenate(): void
43
    {
44
        $instance = new DuckString('hello ');
45
46
        $value = &$instance();
47
        $value .= 'world';
48
49
        $this->assertSame('hello world', $value);
50
        $this->assertSame('hello world', $instance());
51
    }
52
53
    /**
54
     * Unit test.
55
     *
56
     * @return void
57
     */
58
    public function testStringCast(): void
59
    {
60
        $instance = new DuckString('hello world');
61
        $this->assertSame('hello world', (string) $instance);
62
    }
63
64
    /**
65
     * Unit test.
66
     *
67
     * @return void
68
     */
69
    public function testSerialization(): void
70
    {
71
        $instance = new DuckString('hello world');
72
        $serialized = \serialize($instance);
73
        $unserialized = \unserialize($serialized);
74
75
        $this->assertEquals($instance, $unserialized);
76
        $this->assertSame('hello world', $instance());
77
    }
78
}
79