From 9ead5ba9a2c7d7f5431b25c78eca299a731455db Mon Sep 17 00:00:00 2001 From: Andy Shea Date: Thu, 12 Jul 2018 21:44:22 +0100 Subject: [PATCH] Add test for reflection filename correctness --- .../Fixtures/project/src/Application/Main.php | 6 +++ .../src/Aspect/InitializationAspect.php | 2 +- tests/Go/Functional/BaseFunctionalTest.php | 6 +-- .../Go/Functional/ReflectionFilenameTest.php | 49 +++++++++++++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 tests/Go/Functional/ReflectionFilenameTest.php diff --git a/tests/Fixtures/project/src/Application/Main.php b/tests/Fixtures/project/src/Application/Main.php index 24c1664d..cdd9d347 100644 --- a/tests/Fixtures/project/src/Application/Main.php +++ b/tests/Fixtures/project/src/Application/Main.php @@ -25,4 +25,10 @@ public function doSomethingElse() { echo 'I did something else'; } + + public function getFilename() + { + $reflectedClass = new \ReflectionClass($this); + return $reflectedClass->getFileName(); + } } diff --git a/tests/Fixtures/project/src/Aspect/InitializationAspect.php b/tests/Fixtures/project/src/Aspect/InitializationAspect.php index 4ada5693..dd776868 100644 --- a/tests/Fixtures/project/src/Aspect/InitializationAspect.php +++ b/tests/Fixtures/project/src/Aspect/InitializationAspect.php @@ -25,6 +25,6 @@ public function beforeInstanceInitialization() */ public function afterClassStaticInitialization() { - echo 'It invokes after class is loaded into memory.'; + // echo 'It invokes after class is loaded into memory.'; } } diff --git a/tests/Go/Functional/BaseFunctionalTest.php b/tests/Go/Functional/BaseFunctionalTest.php index c00b930c..bf25e628 100644 --- a/tests/Go/Functional/BaseFunctionalTest.php +++ b/tests/Go/Functional/BaseFunctionalTest.php @@ -68,12 +68,10 @@ protected function clearCache() /** * Warms up Go! AOP cache. - * - * @return string Command output. */ - protected function warmUp(): string + protected function warmUp(): void { - return $this->execute('cache:warmup:aop'); + $this->execute('cache:warmup:aop'); } /** diff --git a/tests/Go/Functional/ReflectionFilenameTest.php b/tests/Go/Functional/ReflectionFilenameTest.php new file mode 100644 index 00000000..2f2af6cf --- /dev/null +++ b/tests/Go/Functional/ReflectionFilenameTest.php @@ -0,0 +1,49 @@ +configuration['frontController']; + $path = stream_resolve_include_path($loader); + if (!is_readable($path)) { + throw new \InvalidArgumentException("Invalid loader path: {$loader}"); + } + + ob_start(); + include_once $path; + ob_end_clean(); + + if (!class_exists(AspectKernel::class, false)) { + $message = "Kernel was not initialized yet, please configure it in the {$path}"; + throw new \InvalidArgumentException($message); + } + } + + /** + * {@inheritdoc} + */ + public function tearDown() + { + parent::tearDown(); + $reflectedClass = new \ReflectionClass(FilterInjectorTransformer::class); + $reflectedProperty = $reflectedClass->getProperty('kernel'); + $reflectedProperty->setAccessible(true); + $reflectedProperty = $reflectedProperty->setValue(null); + } + + public function testReflectionFilenameIsCorrect() + { + $filename = (new ReflectionClass(Main::class))->getFileName(); + $main = new Main(); + $this->assertEquals($filename, $main->getFilename()); + } +}