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

SplStringTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 17
dl 0
loc 58
rs 10
c 2
b 1
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testConcatenate() 0 9 1
A test() 0 7 1
A testStringCast() 0 4 1
A testSerialization() 0 8 1
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