forked from goaop/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for goaop#332. Tests for console commands. Cleanup and tests upgr…
…ade. (goaop#333) Upgraded PHPUnit, migrated tests. Added tests for console commands. Cache warmer moved to separate class, fixing goaop#332.
- Loading branch information
1 parent
6e2a0fe
commit b6d6881
Showing
29 changed files
with
465 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
vendor/ | ||
composer.lock | ||
phpunit.xml | ||
tests/Fixtures/project/var/cache/* | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/* | ||
* Go! AOP framework | ||
* | ||
* @copyright Copyright 2013, Lisachenko Alexander <[email protected]> | ||
* | ||
* This source file is subject to the license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Go\Instrument\ClassLoading; | ||
|
||
use Go\Core\AspectKernel; | ||
use Go\Instrument\FileSystem\Enumerator; | ||
use Go\Instrument\Transformer\FilterInjectorTransformer; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Warms up the cache | ||
*/ | ||
class CacheWarmer | ||
{ | ||
/** | ||
* @var AspectKernel | ||
*/ | ||
protected $aspectKernel; | ||
|
||
/** | ||
* @var OutputInterface | ||
*/ | ||
protected $output; | ||
|
||
/** | ||
* CacheWarmer constructor. | ||
* | ||
* @param AspectKernel $aspectKernel A kernel | ||
* @param OutputInterface $output Optional output to log current status. | ||
*/ | ||
public function __construct(AspectKernel $aspectKernel, OutputInterface $output = null) | ||
{ | ||
$this->aspectKernel = $aspectKernel; | ||
$this->output = $output !== null ? $output : new NullOutput(); | ||
} | ||
|
||
/** | ||
* Warms up cache | ||
*/ | ||
public function warmUp() | ||
{ | ||
$options = $this->aspectKernel->getOptions(); | ||
|
||
if (empty($options['cacheDir'])) { | ||
throw new \InvalidArgumentException('Cache warmer require the `cacheDir` options to be configured'); | ||
} | ||
|
||
$enumerator = new Enumerator($options['appDir'], $options['includePaths'], $options['excludePaths']); | ||
$iterator = $enumerator->enumerate(); | ||
$total = iterator_count($iterator); | ||
|
||
$this->output->writeln(sprintf('Total <info>%s</info> files to process.', $total)); | ||
$this->output->writeln(''); | ||
$iterator->rewind(); | ||
|
||
set_error_handler(function ($errno, $errstr, $errfile, $errline) { | ||
throw new \ErrorException($errstr, $errno, 0, $errfile, $errline); | ||
}); | ||
|
||
$errors = []; | ||
$displayException = \Closure::bind(function ($exception, $path) use (&$errors) { | ||
$this->output->writeln(sprintf('<fg=white;bg=red;options=bold>[ERR]</>: %s', $path)); | ||
$errors[$path] = $exception->getMessage(); | ||
}, $this); | ||
|
||
foreach ($iterator as $file) { | ||
$path = $file->getRealPath(); | ||
|
||
try { | ||
// This will trigger creation of cache | ||
file_get_contents(FilterInjectorTransformer::PHP_FILTER_READ . | ||
SourceTransformingLoader::FILTER_IDENTIFIER . | ||
'/resource=' . $path | ||
); | ||
|
||
$this->output->writeln(sprintf('<fg=green;options=bold>[OK]</>: <comment>%s</comment>', $path)); | ||
} catch (\Throwable $e) { | ||
$displayException($e, $path); | ||
} catch (\Exception $e) { | ||
$displayException($e, $path); | ||
} | ||
} | ||
|
||
restore_error_handler(); | ||
|
||
if ($this->output->isVerbose()) { | ||
foreach ($errors as $path => $error) { | ||
$this->output->writeln(sprintf('<fg=white;bg=red;options=bold>[ERR]</>: File "%s" is not processed correctly due to exception: "%s".', $path, $error)); | ||
} | ||
} | ||
|
||
$this->output->writeln(''); | ||
$this->output->writeln(sprintf('<fg=green;>[DONE]</>: Total processed %s, %s errors.', $total, count($errors))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
include_once __DIR__ . '/../../../../vendor/autoload.php'; | ||
|
||
use Symfony\Component\Console\Application; | ||
use Go\Console\Command\CacheWarmupCommand; | ||
use Go\Console\Command\DebugAdvisorCommand; | ||
use Go\Console\Command\DebugAspectCommand; | ||
|
||
$application = new Application(); | ||
|
||
$application->addCommands([ | ||
new CacheWarmupCommand(), | ||
new DebugAdvisorCommand(), | ||
new DebugAspectCommand(), | ||
]); | ||
|
||
$application->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Go\Tests\TestProject\Annotation; | ||
|
||
/** | ||
* @Annotation | ||
*/ | ||
class Loggable | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Go\Tests\TestProject\Application; | ||
|
||
use Go\Tests\TestProject\Annotation as Aop; | ||
|
||
class Main | ||
{ | ||
/** | ||
* @Aop\Loggable() | ||
*/ | ||
public function doSomething() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Go\Tests\TestProject; | ||
|
||
use Go\Core\AspectContainer; | ||
use Go\Core\AspectKernel; | ||
use Go\Tests\TestProject\Aspect\LoggingAspect; | ||
use Psr\Log\NullLogger; | ||
|
||
class ApplicationAspectKernel extends AspectKernel | ||
{ | ||
/** | ||
* Configure an AspectContainer with advisors, aspects and pointcuts | ||
* | ||
* @param AspectContainer $container | ||
* | ||
* @return void | ||
*/ | ||
protected function configureAop(AspectContainer $container) | ||
{ | ||
$container->registerAspect(new LoggingAspect(new NullLogger())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Go\Tests\TestProject\Aspect; | ||
|
||
use Go\Aop\Aspect; | ||
use Go\Aop\Intercept\MethodInvocation; | ||
use Go\Lang\Annotation\Before; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* Application logging aspect | ||
*/ | ||
class LoggingAspect implements Aspect | ||
{ | ||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
public function __construct(LoggerInterface $logger) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* Writes a log info before method execution | ||
* | ||
* @param MethodInvocation $invocation | ||
* @Before("@execution(Go\Tests\TestProject\Annotation\Loggable)") | ||
*/ | ||
public function beforeMethod(MethodInvocation $invocation) | ||
{ | ||
$this->logger->info($invocation, $invocation->getArguments()); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
include_once __DIR__ . '/../../../../vendor/autoload.php'; | ||
|
||
use Go\Tests\TestProject\ApplicationAspectKernel; | ||
|
||
$applicationAspectKernel = ApplicationAspectKernel::getInstance(); | ||
$applicationAspectKernel->init(array( | ||
'appDir' => __DIR__ . '/../', | ||
'debug' => true, | ||
'cacheDir' => __DIR__ . '/../var/cache/aspect', | ||
'includePaths' => array( | ||
__DIR__ . '/../src/' | ||
) | ||
)); |
Oops, something went wrong.