Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active December 14, 2025 15:58
Show Gist options
  • Select an option

  • Save mcsee/4cf6f48f5466d7b38be12af08ca7d2a4 to your computer and use it in GitHub Desktop.

Select an option

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
<?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