@@ -365,6 +365,55 @@ public function test_injection_of_router_by_type()
365365 $ this ->assertEquals ('home ' , $ this ->extract ($ router ));
366366 }
367367
368+ /**
369+ * @throws Throwable
370+ */
371+ public function test_injection_of_default_value ()
372+ {
373+ $ router = $ this ->router ()
374+ ->get ('/ ' , function ($ default = "Default " ) {
375+ return $ default ;
376+ })
377+ ->dispatch ();
378+
379+ $ this ->assertEquals ('Default ' , $ this ->extract ($ router ));
380+ }
381+
382+ /**
383+ * @throws Throwable
384+ */
385+ public function test_set_and_get_request ()
386+ {
387+ $ router = $ this ->router ();
388+
389+ $ router ->get ('/ ' , function () use ($ router ) {
390+ $ newRequest = $ router ->getRequest ()->withMethod ('CUSTOM ' );
391+ $ router ->setRequest ($ newRequest );
392+
393+ return $ router ->getRequest ()->getMethod ();
394+ })->dispatch ();
395+
396+ $ this ->assertEquals ('CUSTOM ' , $ this ->extract ($ router ));
397+ }
398+
399+ /**
400+ * @throws Throwable
401+ */
402+ public function test_default_publisher ()
403+ {
404+ ob_start ();
405+
406+ $ router = new Router ();
407+
408+ $ router ->get ('/ ' , function () {
409+ return 'home ' ;
410+ })->dispatch ();
411+
412+ $ this ->assertEquals ('home ' , ob_get_contents ());
413+
414+ ob_end_clean ();
415+ }
416+
368417 /**
369418 * @throws Throwable
370419 */
@@ -408,10 +457,33 @@ public function test_not_found_error()
408457 /**
409458 * @throws Throwable
410459 */
411- public function test_with_invalid_controller ()
460+ public function test_with_class_method_but_invalid_controller_class ()
412461 {
413462 $ this ->expectException (InvalidControllerException::class);
414463
415464 $ this ->router ()->get ('/ ' , 'UnknownController@method ' )->dispatch ();
416465 }
466+
467+ /**
468+ * @throws Throwable
469+ */
470+ public function test_with_invalid_controller_class ()
471+ {
472+ $ this ->expectException (InvalidControllerException::class);
473+
474+ $ this ->router ()->get ('/ ' , 666 )->dispatch ();
475+ }
476+
477+ /**
478+ * @throws Throwable
479+ */
480+ public function test_with_invalid_controller_method ()
481+ {
482+ $ this ->expectException (InvalidControllerException::class);
483+
484+ $ namespace = 'MiladRahimi\PhpRouter\Tests\Classes ' ;
485+ $ this ->router ('' , $ namespace )
486+ ->get ('/ ' , 'SampleController@invalidMethod ' )
487+ ->dispatch ();
488+ }
417489}
0 commit comments