Skip to content

Commit

Permalink
Add test for reflection filename correctness
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-shea committed Jul 12, 2018
1 parent efe2568 commit 9ead5ba
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
6 changes: 6 additions & 0 deletions tests/Fixtures/project/src/Application/Main.php
Expand Up @@ -25,4 +25,10 @@ public function doSomethingElse()
{
echo 'I did something else';
}

public function getFilename()
{
$reflectedClass = new \ReflectionClass($this);
return $reflectedClass->getFileName();
}
}
2 changes: 1 addition & 1 deletion tests/Fixtures/project/src/Aspect/InitializationAspect.php
Expand Up @@ -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.';
}
}
6 changes: 2 additions & 4 deletions tests/Go/Functional/BaseFunctionalTest.php
Expand Up @@ -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');
}

/**
Expand Down
49 changes: 49 additions & 0 deletions tests/Go/Functional/ReflectionFilenameTest.php
@@ -0,0 +1,49 @@
<?php
declare(strict_types = 1);

namespace Go\Functional;

use Go\Core\AspectKernel;
use Go\ParserReflection\ReflectionClass;
use Go\Tests\TestProject\Application\Main;
use Go\Instrument\Transformer\FilterInjectorTransformer;

class ReflectionFilenameTest extends BaseFunctionalTest
{
protected function warmUp(): void
{
$loader = $this->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());
}
}

0 comments on commit 9ead5ba

Please sign in to comment.