@@ -212,6 +212,61 @@ class SimpleXMLElement
212212}
213213" ;
214214
215+ // ─── Exception class stubs ──────────────────────────────────────────────────
216+
217+ static EXCEPTION_CLASS_STUB : & str = "\
218+ <?php
219+ class Exception implements Throwable
220+ {
221+ public function __construct(string $message = \" \" , int $code = 0, ?Throwable $previous = null) {}
222+
223+ /**
224+ * @return string
225+ */
226+ final public function getMessage(): string {}
227+
228+ /**
229+ * @return int
230+ */
231+ final public function getCode(): int {}
232+
233+ /**
234+ * @return string
235+ */
236+ final public function getFile(): string {}
237+
238+ /**
239+ * @return int
240+ */
241+ final public function getLine(): int {}
242+
243+ /**
244+ * @return array
245+ */
246+ final public function getTrace(): array {}
247+
248+ /**
249+ * @return string
250+ */
251+ final public function getTraceAsString(): string {}
252+
253+ /**
254+ * @return ?Throwable
255+ */
256+ final public function getPrevious(): ?Throwable {}
257+
258+ /**
259+ * @return string
260+ */
261+ public function __toString(): string {}
262+ }
263+ " ;
264+
265+ static RUNTIME_EXCEPTION_CLASS_STUB : & str = "\
266+ <?php
267+ class RuntimeException extends Exception {}
268+ " ;
269+
215270// ─── Constant stubs ─────────────────────────────────────────────────────────
216271
217272static CONSTANTS_STUB : & str = "\
@@ -224,6 +279,16 @@ define('SORT_ASC', 4);
224279define('SORT_DESC', 3);
225280" ;
226281
282+ /// Create a test backend whose `stub_index` contains minimal `Exception`
283+ /// and `RuntimeException` stubs. This makes catch-variable tests fully
284+ /// self-contained — they work without phpstorm-stubs installed.
285+ pub fn create_test_backend_with_exception_stubs ( ) -> Backend {
286+ let mut stubs: HashMap < & ' static str , & ' static str > = HashMap :: new ( ) ;
287+ stubs. insert ( "Exception" , EXCEPTION_CLASS_STUB ) ;
288+ stubs. insert ( "RuntimeException" , RUNTIME_EXCEPTION_CLASS_STUB ) ;
289+ Backend :: new_test_with_stubs ( stubs)
290+ }
291+
227292/// Create a test backend whose `stub_index` contains minimal `UnitEnum`
228293/// and `BackedEnum` stubs. This makes "embedded stub" tests fully
229294/// self-contained — they no longer require a prior `composer install`.
0 commit comments