44
55namespace OpenClassrooms \ServiceProxy \Tests ;
66
7- use OpenClassrooms \ServiceProxy \Interceptor \Config \CacheInterceptorConfig ;
87use OpenClassrooms \ServiceProxy \Interceptor \Contract \PrefixInterceptor ;
98use OpenClassrooms \ServiceProxy \Interceptor \Contract \SuffixInterceptor ;
109use OpenClassrooms \ServiceProxy \Interceptor \Impl \CacheInterceptor ;
1110use OpenClassrooms \ServiceProxy \Interceptor \Impl \EventInterceptor ;
1211use OpenClassrooms \ServiceProxy \Interceptor \Impl \InvalidateCacheInterceptor ;
12+ use OpenClassrooms \ServiceProxy \Interceptor \Impl \LegacyCacheInterceptor ;
13+ use OpenClassrooms \ServiceProxy \Interceptor \Impl \LockInterceptor ;
1314use OpenClassrooms \ServiceProxy \Interceptor \Impl \SecurityInterceptor ;
1415use OpenClassrooms \ServiceProxy \Interceptor \Impl \TransactionInterceptor ;
1516use OpenClassrooms \ServiceProxy \ProxyFactory ;
16- use OpenClassrooms \ServiceProxy \Tests \Double \Mock \Cache \CacheHandlerMock ;
17- use OpenClassrooms \ServiceProxy \Tests \Double \Mock \Event \EventHandlerMock ;
18- use OpenClassrooms \ServiceProxy \Tests \Double \Mock \Security \SecurityHandlerMock ;
19- use OpenClassrooms \ServiceProxy \Tests \Double \Mock \Transaction \TransactionHandlerMock ;
2017use OpenClassrooms \ServiceProxy \Tests \Double \Stub \Cache \ClassWithCacheAttributes ;
2118use OpenClassrooms \ServiceProxy \Tests \Double \Stub \WithConstructorAnnotationClass ;
2219use OpenClassrooms \ServiceProxy \Tests \Double \Stub \WithoutAnnotationClass ;
@@ -30,15 +27,22 @@ final class ProxyFactoryTest extends TestCase
3027
3128 protected function setUp (): void
3229 {
33- $ this ->factory = $ this ->getProxyFactory (
34- [
35- new CacheInterceptor (new CacheInterceptorConfig (), [new CacheHandlerMock ()]),
36- new EventInterceptor ([new EventHandlerMock ()]),
37- new TransactionInterceptor ([new TransactionHandlerMock ()]),
38- new SecurityInterceptor ([new SecurityHandlerMock ()]),
39- new InvalidateCacheInterceptor (),
40- ]
41- );
30+ //auto load all interceptors using glob from folder
31+ $ interceptorsFiles = glob (__DIR__ . '/../src/Interceptor/Impl/*Interceptor.php ' );
32+ $ interceptors = [];
33+ foreach ($ interceptorsFiles as $ interceptorFile ) {
34+ require_once $ interceptorFile ;
35+ }
36+
37+ $ classes = get_declared_classes ();
38+
39+ foreach ($ classes as $ class ) {
40+ if (is_subclass_of ($ class , PrefixInterceptor::class) || is_subclass_of ($ class , SuffixInterceptor::class)) {
41+ $ interceptors [] = new $ class ();
42+ }
43+ }
44+
45+ $ this ->factory = $ this ->getProxyFactory ($ interceptors );
4246 }
4347
4448 public function testWithoutAnnotationReturnServiceProxyInterface (): void
@@ -88,15 +92,19 @@ public function testCheckInterceptorsOrders(): void
8892 SecurityInterceptor::class,
8993 EventInterceptor::class,
9094 CacheInterceptor::class,
95+ LegacyCacheInterceptor::class,
96+ LockInterceptor::class,
9197 TransactionInterceptor::class,
9298 ],
9399 $ prefixInterceptorsClasses
94100 );
95101 $ this ->assertEquals (
96102 [
97103 TransactionInterceptor::class,
104+ LockInterceptor::class,
98105 InvalidateCacheInterceptor::class,
99106 CacheInterceptor::class,
107+ LegacyCacheInterceptor::class,
100108 EventInterceptor::class,
101109 ],
102110 $ suffixInterceptorsClasses
0 commit comments