Last active
December 14, 2025 15:58
-
-
Save mcsee/4cf6f48f5466d7b38be12af08ca7d2a4 to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use PHPUnit\Framework\TestCase; | |
| final class McpMessageParserTest extends TestCase { | |
| private function invokePrivateMethod( | |
| $object, | |
| $methodName, | |
| array $parameters = [] | |
| ) { | |
| $reflection = new ReflectionClass(get_class($object)); | |
| // This is metaprogramming. | |
| // That generates fragile and hidden dependencies | |
| // You need to avoid it | |
| $method = $reflection->getMethod($methodName); | |
| $method->setAccessible(true); | |
| return $method->invokeArgs($object, $parameters); | |
| } | |
| public function testStripStrangeCharactersRemovesSpecialChars() { | |
| $parser = new McpMessageParser(); | |
| $result = $this->invokePrivateMethod( | |
| $parser, | |
| 'stripStrangeCharacters', | |
| ['hello@world#test'] | |
| ); | |
| $this->assertEquals('helloworldtest', $result); | |
| } | |
| public function testStripStrangeCharactersKeepsValidCharacters() { | |
| $parser = new McpMessageParser(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment