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
|
|
|
|