Conversation
|
|
||
| public function testInvalidEncoding(): void | ||
| { | ||
| $this->assertIsString((new ConstantStringType(file_get_contents('invalidUtf8Characters.txt', true)))->describe(VerbosityLevel::value())); |
There was a problem hiding this comment.
I cannot use assertEquals or assertSame due I don't have the same string. Which assert would you use in this situation?
There was a problem hiding this comment.
assertSame with the exact string produced in the test
|
|
||
| public function testInvalidEncoding(): void | ||
| { | ||
| $this->assertIsString((new ConstantStringType(file_get_contents('invalidUtf8Characters.txt', true)))->describe(VerbosityLevel::value())); |
There was a problem hiding this comment.
Is it ok to use file_get_contents in this test or I should move it to a different test?
There was a problem hiding this comment.
Please produce invalid UTF-8 by using \x00 etc. characters in the source code directly.
|
|
||
| public function testInvalidEncoding(): void | ||
| { | ||
| $this->assertIsString((new ConstantStringType(file_get_contents('invalidUtf8Characters.txt', true)))->describe(VerbosityLevel::value())); |
There was a problem hiding this comment.
assertSame with the exact string produced in the test
|
|
||
| public function testInvalidEncoding(): void | ||
| { | ||
| $this->assertIsString((new ConstantStringType(file_get_contents('invalidUtf8Characters.txt', true)))->describe(VerbosityLevel::value())); |
There was a problem hiding this comment.
Please produce invalid UTF-8 by using \x00 etc. characters in the source code directly.
| try { | ||
| $truncatedValue = \Nette\Utils\Strings::truncate($this->value, self::DESCRIBE_LIMIT); | ||
| } catch (\Nette\Utils\RegexpException $e) { | ||
| $truncatedValue = substr($this->value, 0, self::DESCRIBE_LIMIT); |
There was a problem hiding this comment.
We're also missing the ellipsis … here in case the string is longer than self::DESCRIBE_LIMIT.
There was a problem hiding this comment.
I added the ellipsis always because the exception is not thrown when the string is shorter than self::DESCRIBE_LIMIT.
There was a problem hiding this comment.
Please add a test that short invalid UTF-8 is not truncated and ellipsis not added.
|
Thank you! |
#1362