1616use Mcp \Capability \Registry \ResourceReference ;
1717use Mcp \Capability \Registry \ResourceTemplateReference ;
1818use Mcp \Capability \Registry \ToolReference ;
19+ use Mcp \Exception \PromptNotFoundException ;
20+ use Mcp \Exception \ResourceNotFoundException ;
21+ use Mcp \Exception \ToolNotFoundException ;
1922use Mcp \Schema \Prompt ;
2023use Mcp \Schema \Resource ;
2124use Mcp \Schema \ResourceTemplate ;
@@ -45,10 +48,12 @@ public function testGetToolReturnsRegisteredTool(): void
4548 $ this ->assertFalse ($ toolRef ->isManual );
4649 }
4750
48- public function testGetToolReturnsNullForUnregisteredTool (): void
51+ public function testGetToolThrowsExceptionForUnregisteredTool (): void
4952 {
50- $ toolRef = $ this ->registry ->getTool ('non_existent_tool ' );
51- $ this ->assertNull ($ toolRef );
53+ $ this ->expectException (ToolNotFoundException::class);
54+ $ this ->expectExceptionMessage ('Tool not found: "non_existent_tool". ' );
55+
56+ $ this ->registry ->getTool ('non_existent_tool ' );
5257 }
5358
5459 public function testGetResourceReturnsRegisteredResource (): void
@@ -65,10 +70,12 @@ public function testGetResourceReturnsRegisteredResource(): void
6570 $ this ->assertFalse ($ resourceRef ->isManual );
6671 }
6772
68- public function testGetResourceReturnsNullForUnregisteredResource (): void
73+ public function testGetResourceThrowsExceptionForUnregisteredResource (): void
6974 {
70- $ resourceRef = $ this ->registry ->getResource ('test://non_existent ' );
71- $ this ->assertNull ($ resourceRef );
75+ $ this ->expectException (ResourceNotFoundException::class);
76+ $ this ->expectExceptionMessage ('Resource not found for uri: "test://non_existent". ' );
77+
78+ $ this ->registry ->getResource ('test://non_existent ' );
7279 }
7380
7481 public function testGetResourceMatchesResourceTemplate (): void
@@ -84,15 +91,17 @@ public function testGetResourceMatchesResourceTemplate(): void
8491 $ this ->assertEquals ($ handler , $ resourceRef ->handler );
8592 }
8693
87- public function testGetResourceWithIncludeTemplatesFalse (): void
94+ public function testGetResourceWithIncludeTemplatesFalseThrowsException (): void
8895 {
8996 $ template = $ this ->createValidResourceTemplate ('test://{id} ' );
9097 $ handler = fn (string $ id ) => "content for {$ id }" ;
9198
9299 $ this ->registry ->registerResourceTemplate ($ template , $ handler );
93100
94- $ resourceRef = $ this ->registry ->getResource ('test://123 ' , false );
95- $ this ->assertNull ($ resourceRef );
101+ $ this ->expectException (ResourceNotFoundException::class);
102+ $ this ->expectExceptionMessage ('Resource not found for uri: "test://123". ' );
103+
104+ $ this ->registry ->getResource ('test://123 ' , false );
96105 }
97106
98107 public function testGetResourcePrefersDirectResourceOverTemplate (): void
@@ -125,10 +134,12 @@ public function testGetResourceTemplateReturnsRegisteredTemplate(): void
125134 $ this ->assertFalse ($ templateRef ->isManual );
126135 }
127136
128- public function testGetResourceTemplateReturnsNullForUnregisteredTemplate (): void
137+ public function testGetResourceTemplateThrowsExceptionForUnregisteredTemplate (): void
129138 {
130- $ templateRef = $ this ->registry ->getResourceTemplate ('test://{non_existent} ' );
131- $ this ->assertNull ($ templateRef );
139+ $ this ->expectException (ResourceNotFoundException::class);
140+ $ this ->expectExceptionMessage ('Resource not found for uri: "test://{non_existent}". ' );
141+
142+ $ this ->registry ->getResourceTemplate ('test://{non_existent} ' );
132143 }
133144
134145 public function testGetPromptReturnsRegisteredPrompt (): void
@@ -145,10 +156,12 @@ public function testGetPromptReturnsRegisteredPrompt(): void
145156 $ this ->assertFalse ($ promptRef ->isManual );
146157 }
147158
148- public function testGetPromptReturnsNullForUnregisteredPrompt (): void
159+ public function testGetPromptThrowsExceptionForUnregisteredPrompt (): void
149160 {
150- $ promptRef = $ this ->registry ->getPrompt ('non_existent_prompt ' );
151- $ this ->assertNull ($ promptRef );
161+ $ this ->expectException (PromptNotFoundException::class);
162+ $ this ->expectExceptionMessage ('Prompt not found: "non_existent_prompt". ' );
163+
164+ $ this ->registry ->getPrompt ('non_existent_prompt ' );
152165 }
153166
154167 public function testGetToolsReturnsAllRegisteredTools (): void
0 commit comments