-
Notifications
You must be signed in to change notification settings - Fork 529
Issue 1362 #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 1362 #354
Conversation
@@ -148,4 +148,9 @@ public function testGeneralize(): void | |||
$this->assertSame('class-string', (new ConstantStringType('NonexistentClass', true))->generalize()->describe(VerbosityLevel::precise())); | |||
} | |||
|
|||
public function testInvalidEncoding(): void | |||
{ | |||
$this->assertIsString((new ConstantStringType(file_get_contents('invalidUtf8Characters.txt', true)))->describe(VerbosityLevel::value())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertSame with the exact string produced in the test
@@ -148,4 +148,9 @@ public function testGeneralize(): void | |||
$this->assertSame('class-string', (new ConstantStringType('NonexistentClass', true))->generalize()->describe(VerbosityLevel::precise())); | |||
} | |||
|
|||
public function testInvalidEncoding(): void | |||
{ | |||
$this->assertIsString((new ConstantStringType(file_get_contents('invalidUtf8Characters.txt', true)))->describe(VerbosityLevel::value())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please produce invalid UTF-8 by using \x00
etc. characters in the source code directly.
@@ -148,4 +148,9 @@ public function testGeneralize(): void | |||
$this->assertSame('class-string', (new ConstantStringType('NonexistentClass', true))->generalize()->describe(VerbosityLevel::precise())); | |||
} | |||
|
|||
public function testInvalidEncoding(): void | |||
{ | |||
$this->assertIsString((new ConstantStringType(file_get_contents('invalidUtf8Characters.txt', true)))->describe(VerbosityLevel::value())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertSame with the exact string produced in the test
@@ -148,4 +148,9 @@ public function testGeneralize(): void | |||
$this->assertSame('class-string', (new ConstantStringType('NonexistentClass', true))->generalize()->describe(VerbosityLevel::precise())); | |||
} | |||
|
|||
public function testInvalidEncoding(): void | |||
{ | |||
$this->assertIsString((new ConstantStringType(file_get_contents('invalidUtf8Characters.txt', true)))->describe(VerbosityLevel::value())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're also missing the ellipsis …
here in case the string is longer than self::DESCRIBE_LIMIT
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test that short invalid UTF-8 is not truncated and ellipsis not added.
Thank you! |
#1362