\documentclass{article}
\let\testenv\document
\let\endtestenv\enddocument
\AddToHook{env/testenv/begin}{\def\foorbar{1}}
\AddToHook{env/testenv/end}{The End}
\let\testenvB\document
\let\endtestenvB\enddocument
\AddToHook{env/testenvB/begin}{\def\foorbar{2}}
\AddToHook{env/testenvB/end}{The End B}
\begin{testenvB}
Test\foorbar Test
\end{testenvB}