assertEquals('foo', StringsUtils::unquote("'foo")); } /** * @see StringsUtils::camelToSnake() */ public function testCamelToSnake(): void { $this->assertEquals('foo_bar', StringsUtils::camelToSnake('FooBar')); $this->assertEquals('foo-bar', StringsUtils::camelToSnake('FooBar', '-')); $this->assertEquals('foo_bar', StringsUtils::camelToSnake('fooBar')); } /** * @see StringsUtils::convertHtmlToText() */ public function testConvertHtmlToText(): void { $this->assertEquals('Test contenu', (new StringsUtils())->convertHtmlToText('
Test

contenu

')); } /** * @see StringsUtils::elide() */ public function testElide(): void { // Test normal truncation case - string longer than length $this->assertEquals('Hello...', StringsUtils::elide('Hello World!', 8)); // Test case where string is shorter than length - no truncation $this->assertEquals('Hello', StringsUtils::elide('Hello', 10)); // Test edge case with exact length $this->assertEquals('Hello', StringsUtils::elide('Hello', 6)); // Test with empty string $this->assertEquals('', StringsUtils::elide('', 10)); } /** * @see StringsUtils::elide() */ public function testElideWithMultibyteCharacters(): void { // Test with UTF-8 multibyte characters $this->assertEquals('Héllo...', StringsUtils::elide('Héllo Wörld!', 8)); $this->assertEquals('测试中...', StringsUtils::elide('测试中文字符串', 6)); $this->assertEquals('🎉🎊🎈🎆🎇', StringsUtils::elide('🎉🎊🎈🎆🎇', 6)); } /** * @see StringsUtils::elide() */ public function testElideWithInvalidLength(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Length must be greater than 5'); StringsUtils::elide('Hello World!', 1); } /** * @see StringsUtils::elide() */ public function testElideWithLongString(): void { $longString = str_repeat('A', 1000); $result = StringsUtils::elide($longString, 50); $this->assertEquals(50, mb_strlen($result)); // 47 + 3 dots $this->assertTrue(str_ends_with($result, '...')); $this->assertEquals(str_repeat('A', 47).'...', $result); } }