1616
1717/**
1818 * Reads {@see Interceptable} attributes and integrates them into the pipeline.
19+ * Also maps the found attributes into the info DTO attributes.
1920 */
2021final class AttributesInterceptor implements TestRunInterceptor, TestCaseRunInterceptor
2122{
@@ -46,17 +47,19 @@ function: $info->testDefinition->reflection,
4647 return $ next ($ info );
4748 }
4849
49- # Merge and instantiate attributes
50- $ interceptors = $ this ->interceptorProvider ->fromAttributes (TestRunInterceptor::class, ...\array_map (
50+ $ attrs = \array_map (
5151 static fn (\ReflectionAttribute $ a ): Interceptable => $ a ->newInstance (),
5252 $ attrs ,
53- ));
53+ );
54+
55+ # Merge and instantiate attributes
56+ $ interceptors = $ this ->interceptorProvider ->fromAttributes (TestRunInterceptor::class, ...$ attrs );
5457
5558 return Pipeline::prepare (...$ interceptors )->with (
5659 $ next ,
5760 /** @see TestRunInterceptor::runTest() */
5861 'runTest ' ,
59- )($ info );
62+ )($ info-> withAttributes ( self :: attributes ( $ attrs )) );
6063 }
6164
6265 public function runTestCase (CaseInfo $ info , callable $ next ): CaseResult
@@ -74,16 +77,34 @@ class: $info->definition->reflection,
7477 return $ next ($ info );
7578 }
7679
77- # Merge and instantiate attributes
78- $ interceptors = $ this ->interceptorProvider ->fromAttributes (TestCaseRunInterceptor::class, ...\array_map (
80+ $ attrs = \array_map (
7981 static fn (\ReflectionAttribute $ a ): Interceptable => $ a ->newInstance (),
8082 $ attrs ,
81- ));
83+ );
84+
85+ # Merge and instantiate attributes
86+ $ interceptors = $ this ->interceptorProvider ->fromAttributes (TestCaseRunInterceptor::class, ...$ attrs );
8287
8388 return Pipeline::prepare (...$ interceptors )->with (
8489 $ next ,
8590 /** @see TestCaseRunInterceptor::runTestCase() */
8691 'runTestCase ' ,
87- )($ info );
92+ )($ info ->withAttributes (self ::attributes ($ attrs )));
93+ }
94+
95+ /**
96+ * Converts array of attributes to associative array of attributed lists
97+ *
98+ * @param list<Interceptable> $attrs
99+ * @return array<class-string, list<Interceptable>>
100+ */
101+ private static function attributes (array $ attrs ): array
102+ {
103+ $ result = [];
104+ foreach ($ attrs as $ attr ) {
105+ $ result [$ attr ::class][] = $ attr ;
106+ }
107+
108+ return $ result ;
88109 }
89110}
0 commit comments