diff --git a/lib/src/Interceptor.php b/lib/src/Interceptor.php new file mode 100644 index 0000000..2d6cc0d --- /dev/null +++ b/lib/src/Interceptor.php @@ -0,0 +1,23 @@ +interceptors = $interceptors; + } + + /** + * {@inheritdoc} + */ + public function intercept(Method $method): Method + { + foreach ($this->interceptors as $interceptor) { + $method = $interceptor->intercept($method); + } + + return $method; + } +} diff --git a/lib/src/Method.php b/lib/src/Method.php new file mode 100644 index 0000000..cc24a5d --- /dev/null +++ b/lib/src/Method.php @@ -0,0 +1,20 @@ +interceptor1 = $this->prophesize(Interceptor::class); + $this->interceptor2 = $this->prophesize(Interceptor::class); + + $this->interceptor = new InterceptorChain($this->interceptor1->reveal(), $this->interceptor2->reveal()); + } + + /** + * @test + */ + public function it_intercepts_a_method(): void + { + $method1 = $this->prophesize(Method::class)->reveal(); + $method2 = $this->prophesize(Method::class)->reveal(); + + $this->interceptor1->intercept($method1)->willReturn($method2); + $this->interceptor2->intercept($method2)->willReturn($method2); + + self::assertSame($method2, $this->interceptor->intercept($method1)); + } +}