| Total Complexity | 25 |
| Total Lines | 313 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 47 | #[CoversClass(Strings::class)] |
||
| 48 | class StringsTest extends TestCase |
||
| 49 | { |
||
| 50 | /** |
||
| 51 | * Test Strings::getEncoding(). |
||
| 52 | */ |
||
| 53 | public function testGetEncoding(): void |
||
| 54 | { |
||
| 55 | self::assertSame('UTF-8', Strings::getEncoding()); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Test Strings::setEncoding(). |
||
| 60 | */ |
||
| 61 | public function testSetEncoding(): void |
||
| 62 | { |
||
| 63 | // With no ini update. |
||
| 64 | Strings::setEncoding('UCS-2'); |
||
| 65 | |||
| 66 | self::assertSame('UCS-2', Strings::getEncoding()); |
||
| 67 | |||
| 68 | Strings::setEncoding('UTF-8'); |
||
| 69 | |||
| 70 | // With ini update. |
||
| 71 | Strings::setEncoding('UCS-2', true); |
||
| 72 | |||
| 73 | self::assertSame('UCS-2', Strings::getEncoding()); |
||
| 74 | self::assertSame('UCS-2', Environment::iniGet('default_charset')); |
||
| 75 | self::assertSame('UCS-2', Environment::iniGet('internal_encoding')); |
||
| 76 | |||
| 77 | Strings::setEncoding('UTF-8', true); |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Test Strings::title(). |
||
| 82 | */ |
||
| 83 | public function testTitle(): void |
||
| 84 | { |
||
| 85 | $title = Strings::title('Mary had A little lamb and She Loved it so'); |
||
| 86 | self::assertSame('Mary Had A Little Lamb And She Loved It So', $title); |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Test Strings::lower(). |
||
| 91 | */ |
||
| 92 | public function testLower(): void |
||
| 93 | { |
||
| 94 | self::assertSame('test', Strings::lower('tESt')); |
||
| 95 | self::assertSame('test', Strings::lower('TEST')); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Test Strings::upper(). |
||
| 100 | */ |
||
| 101 | public function testUpper(): void |
||
| 102 | { |
||
| 103 | self::assertSame('TEST', Strings::upper('teSt')); |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Test Strings::substr(). |
||
| 108 | */ |
||
| 109 | public function testSubstr(): void |
||
| 110 | { |
||
| 111 | self::assertSame('f', Strings::substr('abcdef', -1)); |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Test Strings::lcfirst(). |
||
| 116 | */ |
||
| 117 | public function testLcfirst(): void |
||
| 118 | { |
||
| 119 | self::assertSame('test', Strings::lcfirst('Test')); |
||
| 120 | self::assertSame('tEST', Strings::lcfirst('TEST')); |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Test Strings::ucfirst(). |
||
| 125 | */ |
||
| 126 | public function testUcfirst(): void |
||
| 127 | { |
||
| 128 | self::assertSame('Test', Strings::ucfirst('test')); |
||
| 129 | self::assertSame('TEsT', Strings::ucfirst('tEsT')); |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Test Strings::strcasecmp(). |
||
| 134 | */ |
||
| 135 | public function testStrcasecmp(): void |
||
| 136 | { |
||
| 137 | // Returns -1 if string1 is less than string2; 1 if string1 is greater than string2, and 0 if they are equal. |
||
| 138 | $str1 = 'test'; |
||
| 139 | $str2 = 'Test'; |
||
| 140 | |||
| 141 | self::assertSame(0, Strings::strcasecmp($str1, $str2)); |
||
| 142 | |||
| 143 | $str1 = 'tes'; |
||
| 144 | |||
| 145 | self::assertSame(-1, Strings::strcasecmp($str1, $str2)); |
||
| 146 | |||
| 147 | $str1 = 'testing'; |
||
| 148 | |||
| 149 | self::assertSame(1, Strings::strcasecmp($str1, $str2)); |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Test Strings::beginsWith(). |
||
| 154 | */ |
||
| 155 | public function testBeginsWith(): void |
||
| 156 | { |
||
| 157 | self::assertTrue(Strings::beginsWith('this is a test', 'this')); |
||
| 158 | self::assertFalse(Strings::beginsWith('this is a test', 'test')); |
||
| 159 | |||
| 160 | self::assertTrue(Strings::beginsWith('THIS IS A TEST', 'this', true)); |
||
| 161 | self::assertFalse(Strings::beginsWith('THIS IS A TEST', 'test', true)); |
||
| 162 | |||
| 163 | self::assertTrue(Strings::beginsWith('THIS IS A TEST', 'this', true, true)); |
||
| 164 | self::assertFalse(Strings::beginsWith('THIS IS A TEST', 'test', true, true)); |
||
| 165 | } |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Test Strings::endsWith(). |
||
| 169 | */ |
||
| 170 | public function testEndsWith(): void |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Test Strings::doesContain(). |
||
| 184 | */ |
||
| 185 | public function testDoesContain(): void |
||
| 186 | { |
||
| 187 | self::assertTrue(Strings::doesContain('start a string', 'a string')); |
||
| 188 | self::assertFalse(Strings::doesContain('start a string', 'starting')); |
||
| 189 | |||
| 190 | self::assertTrue(Strings::doesContain('START A STRING', 'a string', true)); |
||
| 191 | self::assertFalse(Strings::doesContain('START A STRING', 'starting', true)); |
||
| 192 | |||
| 193 | self::assertTrue(Strings::doesContain('START A STRING', 'a string', true, true)); |
||
| 194 | self::assertFalse(Strings::doesContain('START A STRING', 'starting', true, true)); |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Test Strings::doesNotContain(). |
||
| 199 | */ |
||
| 200 | public function testDoesNotContain(): void |
||
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Provides data for testCamelCase(). |
||
| 214 | * |
||
| 215 | * Shoutout to Daniel St. Jules (https://github.com/danielstjules/Stringy/) for |
||
| 216 | * inspiration for this function. This function is based on Stringy/Test/camelizeProvider(). |
||
| 217 | * |
||
| 218 | * @return array<int, array<int, string>> |
||
| 219 | */ |
||
| 220 | public static function camelCaseProvider(): array |
||
| 221 | { |
||
| 222 | return [ |
||
| 223 | ['camelCase', 'CamelCase'], |
||
| 224 | ['camelCase', 'Camel-Case'], |
||
| 225 | ['camelCase', 'camel case'], |
||
| 226 | ['camelCase', 'camel -case'], |
||
| 227 | ['camelCase', 'camel - case'], |
||
| 228 | ['camelCase', 'camel_case'], |
||
| 229 | ['camelCTest', 'camel c test'], |
||
| 230 | ['stringWith1Number', 'string_with1number'], |
||
| 231 | ['stringWith22Numbers', 'string-with-2-2 numbers'], |
||
| 232 | ['dataRate', 'data_rate'], |
||
| 233 | ['backgroundColor', 'background-color'], |
||
| 234 | ['yesWeCan', 'yes_we_can'], |
||
| 235 | ['mozSomething', '-moz-something'], |
||
| 236 | ['carSpeed', '_car_speed_'], |
||
| 237 | ['serveHTTP', 'ServeHTTP'], |
||
| 238 | ['1Camel2Case', '1camel2case'], |
||
| 239 | ['camelΣase', 'camel σase', 'UTF-8'], |
||
| 240 | ['στανιλCase', 'Στανιλ case', 'UTF-8'], |
||
| 241 | ['σamelCase', 'σamel Case', 'UTF-8'], |
||
| 242 | ]; |
||
| 243 | } |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Test Strings::camelCase(). |
||
| 247 | */ |
||
| 248 | #[DataProvider('camelCaseProvider')] |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Test Strings::ascii(). |
||
| 262 | */ |
||
| 263 | public function testAscii(): void |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Test Strings::ascii(). |
||
| 270 | */ |
||
| 271 | public function testAsciiWithLanguage(): void |
||
| 272 | { |
||
| 273 | self::assertSame('aaistAAIST', Strings::ascii('ăâîșțĂÂÎȘȚ', 'ro')); |
||
| 274 | } |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Test Strings::slugify(). |
||
| 278 | */ |
||
| 279 | public function testSlugify(): void |
||
| 280 | { |
||
| 281 | self::assertSame('a-simple-title', Strings::slugify('A simple title')); |
||
| 282 | self::assertSame('this-post-it-has-a-dash', Strings::slugify('This post -- it has a dash')); |
||
| 283 | self::assertSame('123-1251251', Strings::slugify('123----1251251')); |
||
| 284 | |||
| 285 | self::assertSame('a_simple_title', Strings::slugify('A simple title', '_')); |
||
| 286 | self::assertSame('this_post_it_has_a_dash', Strings::slugify('This post -- it has a dash', '_')); |
||
| 287 | self::assertSame('123_1251251', Strings::slugify('123----1251251', '_')); |
||
| 288 | |||
| 289 | self::assertSame('a-simple-title', Strings::slugify('a-simple-title')); |
||
| 290 | self::assertSame('', Strings::slugify(' ')); |
||
| 291 | |||
| 292 | self::assertSame('this-is-a-simple-title', Strings::slugify('Țhîș îș ă șîmple țîțle', '-', 'ro')); |
||
| 293 | } |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Test Strings::randomBytes(). |
||
| 297 | */ |
||
| 298 | public function testRandomBytes(): void |
||
| 305 | } |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Test Strings::randomString(). |
||
| 309 | */ |
||
| 310 | public function testRandomString(): void |
||
| 311 | { |
||
| 312 | $str = Strings::randomString(16); |
||
| 313 | self::assertTrue(Strings::length($str) === 16); |
||
| 314 | |||
| 315 | self::expectException(RandomException::class); |
||
|
1 ignored issue
–
show
|
|||
| 316 | $str = Strings::randomString(-10); |
||
| 317 | } |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Test Strings::validEmail(). |
||
| 321 | */ |
||
| 322 | public function testValidEmail(): void |
||
| 323 | { |
||
| 324 | self::assertTrue(Strings::validEmail('[email protected]')); |
||
| 325 | self::assertTrue(Strings::validEmail('[email protected]')); |
||
| 326 | self::assertTrue(Strings::validEmail('[email protected]')); |
||
| 327 | self::assertFalse(Strings::validEmail('j@')); |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Test Strings::validJson(). |
||
| 332 | */ |
||
| 333 | public function testValidJson(): void |
||
| 334 | { |
||
| 335 | self::assertTrue(Strings::validJson('{ "test": { "foo": "bar" } }')); |
||
|
1 ignored issue
–
show
|
|||
| 336 | self::assertFalse(Strings::validJson('{ "": "": "" } }')); |
||
|
1 ignored issue
–
show
|
|||
| 337 | } |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Test Strings::obscureEmail(). |
||
| 341 | */ |
||
| 342 | public function testObscureEmail(): void |
||
| 343 | { |
||
| 344 | self::assertSame( |
||
| 345 | 'admin@secondversion.com', |
||
| 346 | Strings::obscureEmail('[email protected]') |
||
| 347 | ); |
||
| 348 | |||
| 349 | self::expectException(InvalidArgumentException::class); |
||
|
1 ignored issue
–
show
|
|||
| 350 | $email = Strings::obscureEmail('thisisnotvalid&!--'); |
||
| 351 | } |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Test Strings::guid(). |
||
| 355 | */ |
||
| 356 | public function testGuid(): void |
||
| 360 | } |
||
| 361 | } |
||
| 362 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths