daikon-cqrs /
value-object
| 1 | <?php declare(strict_types=1); |
||
| 2 | /** |
||
| 3 | * This file is part of the daikon-cqrs/value-object project. |
||
| 4 | * |
||
| 5 | * For the full copyright and license information, please view the LICENSE |
||
| 6 | * file that was distributed with this source code. |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace Daikon\Tests\ValueObject; |
||
| 10 | |||
| 11 | use Daikon\ValueObject\Text; |
||
| 12 | use PHPUnit\Framework\TestCase; |
||
| 13 | |||
| 14 | final class TextTest extends TestCase |
||
| 15 | { |
||
| 16 | private const FIXED_TEXT = 'hello world!'; |
||
| 17 | |||
| 18 | private Text $text; |
||
| 19 | |||
| 20 | 1 | public function testToNative(): void |
|
| 21 | { |
||
| 22 | 1 | $this->assertEquals(self::FIXED_TEXT, $this->text->toNative()); |
|
| 23 | 1 | $this->assertEquals('', Text::fromNative(null)->toNative()); |
|
| 24 | 1 | } |
|
| 25 | |||
| 26 | 1 | public function testEquals(): void |
|
| 27 | { |
||
| 28 | 1 | $sameText = Text::fromNative(self::FIXED_TEXT); |
|
| 29 | 1 | $this->assertTrue($this->text->equals($sameText)); |
|
| 30 | 1 | $differentText = Text::fromNative('hello universe!'); |
|
| 31 | 1 | $this->assertFalse($this->text->equals($differentText)); |
|
| 32 | 1 | } |
|
| 33 | |||
| 34 | 1 | public function testIsEmpty(): void |
|
| 35 | { |
||
| 36 | 1 | $this->assertTrue(Text::fromNative('')->isEmpty()); |
|
| 37 | 1 | $this->assertTrue(Text::fromNative(null)->isEmpty()); |
|
| 38 | 1 | $this->assertFalse(Text::fromNative('0')->isEmpty()); |
|
| 39 | 1 | $this->assertFalse($this->text->isEmpty()); |
|
| 40 | 1 | } |
|
| 41 | |||
| 42 | 1 | public function testToString(): void |
|
| 43 | { |
||
| 44 | 1 | $this->assertEquals(self::FIXED_TEXT, (string)$this->text); |
|
| 45 | 1 | } |
|
| 46 | |||
| 47 | 1 | public function testGetLength(): void |
|
| 48 | { |
||
| 49 | 1 | $this->assertEquals(12, $this->text->getLength()); |
|
| 50 | 1 | $detectOrder = mb_detect_order(); |
|
| 51 | 1 | mb_detect_order(['SJIS']); |
|
| 52 | 1 | $intlText = Text::fromNative('ぁあぃいぅうぇえぉおかがきぎく'); |
|
| 53 | 1 | $this->assertEquals(23, $intlText->getLength()); |
|
| 54 | 1 | $this->assertEquals('ぁあぃいぅうぇえぉおかがきぎく', $intlText->toNative()); |
|
| 55 | 1 | mb_detect_order($detectOrder); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 56 | 1 | } |
|
| 57 | |||
| 58 | 1 | public function testMakeEmpty(): void |
|
| 59 | { |
||
| 60 | 1 | $this->assertEquals('', Text::makeEmpty()->toNative()); |
|
| 61 | 1 | $this->assertEquals('', (string)Text::makeEmpty()); |
|
| 62 | 1 | $this->assertTrue(Text::makeEmpty()->isEmpty()); |
|
| 63 | 1 | $this->assertEquals(0, Text::makeEmpty()->getLength()); |
|
| 64 | 1 | } |
|
| 65 | |||
| 66 | 6 | protected function setUp(): void |
|
| 67 | { |
||
| 68 | 6 | $this->text = Text::fromNative(self::FIXED_TEXT); |
|
| 69 | 6 | } |
|
| 70 | } |
||
| 71 |