44
55namespace Serendipity \Hyperf \Testing \Extension ;
66
7+ use ArrayObject ;
78use FastRoute \Dispatcher ;
89use Hyperf \Context \Context ;
10+ use Hyperf \Contract \ValidatorInterface ;
911use Hyperf \HttpMessage \Server \Request ;
1012use Hyperf \HttpServer \Router \Dispatched ;
1113use Hyperf \HttpServer \Router \Handler ;
1214use Hyperf \Validation \ValidationException ;
1315use Psr \Http \Message \ServerRequestInterface ;
1416use Serendipity \Presentation \Input ;
1517
18+ use function array_keys ;
19+ use function spl_object_hash ;
20+ use function sprintf ;
21+ use function str_contains ;
22+ use function str_ends_with ;
23+
1624/**
1725 * @phpstan-ignore trait.unused
1826 */
@@ -39,6 +47,17 @@ protected function tearDownInput(bool $isRequestSetUp): void
3947 $ this ->isRequestSetUp = $ isRequestSetUp ;
4048 Context::destroy (ServerRequestInterface::class);
4149 Context::destroy ('http.request.parsedData ' );
50+
51+ $ context = Context::getContainer ();
52+ if ($ context instanceof ArrayObject) {
53+ $ keys = array_keys ($ context ->getArrayCopy ());
54+ foreach ($ keys as $ key ) {
55+ if (str_contains ($ key , ValidatorInterface::class)
56+ || str_ends_with ($ key , ':scene ' )) {
57+ Context::destroy ($ key );
58+ }
59+ }
60+ }
4261 }
4362
4463 /**
@@ -58,7 +77,13 @@ final protected function input(
5877 ): mixed {
5978 if ($ this ->isRequestSetUp ) {
6079 $ this ->setUpRequestContext ($ parsedBody , $ queryParams , $ params , $ headers );
61- return $ this ->make ($ class , $ args );
80+ $ input = $ this ->make ($ class , $ args );
81+
82+ $ hash = spl_object_hash ($ input );
83+ Context::destroy (sprintf ('%s:%s ' , $ hash , ValidatorInterface::class));
84+ Context::destroy (sprintf ('%s:%s ' , $ hash , 'scene ' ));
85+
86+ return $ input ;
6287 }
6388 static ::fail ('Request is not set up. ' );
6489 }
0 commit comments