Skip to content

Commit 615cfa0

Browse files
Namespace change (#11)
* Move namespace Change namespace according to new specification. \Go\Zend\Framework * Remove ZF2 specifics and add more tests This will remove zf2 specific namings. These would mitmatch zend framework if you want to use this with ZF3. This will also add another functional test for goaop-warmup. Also add requirement for symfony/console since this is needed for warmup. * Remove visibility from constant to match <7.1 * Add symfony/console as composer suggestion * Add symfony/console to dev requirement This is needed to actually run the functional warmup test
1 parent f99e056 commit 615cfa0

20 files changed

+138
-51
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
/vendor/
22
composer.lock
3+
4+
# Test specific ignores
5+
tests/resources/cache

bin/goaop-zf2-warmup

100644100755
+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?php
33

44
use Go\Core\AspectKernel;
5-
use Go\ZF2\GoAopModule\Console\Warmup\Zf2WarmupCommand;
5+
use Go\Zend\Framework\Console\Command\WarmupCommand;
66
use Symfony\Component\Console\Application;
77

88

@@ -26,7 +26,8 @@ if (!class_exists('Symfony\Component\Console\Application')) {
2626
);
2727
}
2828

29+
2930
$app = new Application('Go! AOP', AspectKernel::VERSION);
30-
$app->add(new Zf2WarmupCommand());
31+
$app->add(new WarmupCommand());
3132
$app->run();
3233

composer.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "MIT",
77
"require": {
88
"goaop/framework": "^1.0|^2.0",
9-
"zendframework/zend-modulemanager": "^2.0 | ^3.0"
9+
"zendframework/zend-modulemanager": "^2.0"
1010
},
1111
"require-dev": {
1212
"phpunit/phpunit": "^5.0 | ^6.0",
@@ -15,7 +15,11 @@
1515
"zendframework/zend-serializer": "^2.0",
1616
"zendframework/zend-log": "^2.0",
1717
"zendframework/zend-i18n": "^2.0",
18-
"zendframework/zend-console": "^2.0"
18+
"zendframework/zend-console": "^2.0",
19+
"symfony/console": "^3.0 | ^4.0"
20+
},
21+
"suggest": {
22+
"symfony/console": "Required to use goaop console warmup"
1923
},
2024
"authors": [
2125
{
@@ -30,12 +34,12 @@
3034
"bin": ["bin/goaop-zf2-warmup"],
3135
"autoload": {
3236
"psr-4": {
33-
"Go\\ZF2\\GoAopModule\\" : "src/"
37+
"Go\\Zend\\Framework\\" : "src/"
3438
}
3539
},
3640
"autoload-dev": {
3741
"psr-4": {
38-
"Go\\ZF2\\GoAopModule\\Tests\\" : "tests/"
42+
"Go\\Zend\\Framework\\Tests\\" : "tests/"
3943
}
4044
}
4145
}

config/module.config.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Go\Core\AspectContainer;
1010
use Go\Core\AspectKernel;
1111
use Go\Core\GoAspectContainer;
12-
use Go\ZF2\GoAopModule\Factory\AspectContainerFactory;
13-
use Go\ZF2\GoAopModule\Factory\AspectKernelFactory;
12+
use Go\Zend\Framework\Factory\AspectContainerFactory;
13+
use Go\Zend\Framework\Factory\AspectKernelFactory;
1414

1515
$basicDirectory = defined('APPLICATION_PATH') ? APPLICATION_PATH : __DIR__ . '/../../../..';
1616

@@ -94,12 +94,14 @@
9494
];
9595

9696
return [
97-
'goaop_module' => $moduleConfig,
97+
\Go\Zend\Framework\Module::CONFIG_KEY => $moduleConfig,
98+
9899
'service_manager' => [
99100
'factories' => [
100101
AspectKernel::class => AspectKernelFactory::class,
101102
AspectContainer::class => AspectContainerFactory::class,
102103
]
103104
],
104-
'goaop_aspect' => []
105+
106+
\Go\Zend\Framework\Module::ASPECT_CONFIG_KEY => []
105107
];

phpunit.xml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<testsuite name="Go! AOP ZF Module Test Suite">
1414
<directory>./tests/Integration/</directory>
1515
<directory>./tests/Unit/</directory>
16+
<directory>./tests/Functional/</directory>
1617
</testsuite>
1718
</testsuites>
1819
<filter>

src/Console/Warmup/Zf2WarmupCommand.php renamed to src/Console/Command/WarmupCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Go\ZF2\GoAopModule\Console\Warmup;
3+
namespace Go\Zend\Framework\Console\Command;
44

55
use Go\Core\AspectKernel;
66
use Go\Instrument\ClassLoading\SourceTransformingLoader;
@@ -11,7 +11,7 @@
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Output\OutputInterface;
1313

14-
class Zf2WarmupCommand extends Command
14+
class WarmupCommand extends Command
1515
{
1616
/**
1717
* {@inheritDoc}

src/Factory/AspectContainerFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* with this source code in the file LICENSE.
99
*/
1010

11-
namespace Go\ZF2\GoAopModule\Factory;
11+
namespace Go\Zend\Framework\Factory;
1212

1313
use Go\Core\AspectKernel;
1414
use Interop\Container\ContainerInterface;

src/Factory/AspectKernelFactory.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
* with this source code in the file LICENSE.
99
*/
1010

11-
namespace Go\ZF2\GoAopModule\Factory;
11+
namespace Go\Zend\Framework\Factory;
1212

13-
use Go\ZF2\GoAopModule\Kernel\AspectZf2Kernel;
13+
use Go\Zend\Framework\Kernel\AspectKernel;
14+
use Go\Zend\Framework\Module;
1415
use Interop\Container\ContainerInterface;
1516
use Zend\ServiceManager\FactoryInterface;
1617
use Zend\ServiceManager\ServiceLocatorInterface;
@@ -43,8 +44,8 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
4344
*/
4445
public function createService(ServiceLocatorInterface $serviceLocator)
4546
{
46-
$aspectKernel = AspectZf2Kernel::getInstance();
47-
$aspectKernel->init($serviceLocator->get('config')['goaop_module']);
47+
$aspectKernel = AspectKernel::getInstance();
48+
$aspectKernel->init($serviceLocator->get('config')[Module::CONFIG_KEY]);
4849

4950
return $aspectKernel;
5051
}

src/Kernel/AspectZf2Kernel.php renamed to src/Kernel/AspectKernel.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
* with this source code in the file LICENSE.
99
*/
1010

11-
namespace Go\ZF2\GoAopModule\Kernel;
11+
namespace Go\Zend\Framework\Kernel;
1212

1313

1414
use Go\Core\AspectContainer;
15-
use Go\Core\AspectKernel;
1615

1716
/**
18-
* ZF2 aspect kernel class
17+
* Aspect kernel class
1918
*/
20-
class AspectZf2Kernel extends AspectKernel
19+
class AspectKernel extends \Go\Core\AspectKernel
2120
{
2221

2322
/**

src/Module.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* with this source code in the file LICENSE.
99
*/
1010

11-
namespace Go\ZF2\GoAopModule;
11+
namespace Go\Zend\Framework;
1212

1313
use Go\Core\AspectContainer;
1414
use Zend\ModuleManager\Feature\ConfigProviderInterface;
@@ -17,10 +17,13 @@
1717
use Zend\ModuleManager\ModuleManagerInterface;
1818

1919
/**
20-
* ZF2 Module for registration of Go! AOP Framework
20+
* Module for registration of Go! AOP Framework
2121
*/
2222
class Module implements ConfigProviderInterface, InitProviderInterface
2323
{
24+
const CONFIG_KEY = 'goaop_module';
25+
const ASPECT_CONFIG_KEY = 'goaop_aspect';
26+
2427
/**
2528
* @inheritDoc
2629
*/
@@ -44,7 +47,8 @@ public function initializeAspects(ModuleEvent $e)
4447
/** @var AspectContainer $aspectContainer */
4548
$aspectContainer = $serviceManager->get(AspectContainer::class);
4649
$config = $serviceManager->get('config');
47-
$listOfAspects = $config['goaop_aspect'];
50+
$listOfAspects = $config[self::ASPECT_CONFIG_KEY];
51+
4852
foreach ($listOfAspects as $aspectService) {
4953
$aspect = $serviceManager->get($aspectService);
5054
$aspectContainer->registerAspect($aspect);

tests/Advice/TestAdvice.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Go\Zend\Framework\Tests\Advice;
4+
5+
/**
6+
* @package Go\Zend\Framework\Tests\Advice
7+
*/
8+
class TestAdvice
9+
{
10+
public function getTest($parameter)
11+
{
12+
}
13+
}

tests/Aspect/TestAspect.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
<?php
22

3-
namespace Go\ZF2\GoAopModule\Tests\Aspect;
3+
namespace Go\Zend\Framework\Tests\Aspect;
44

55
use Go\Aop\Aspect;
6+
use Go\Aop\Intercept\MethodInvocation;
7+
use Go\Lang\Annotation\Around;
68

79
/**
8-
* @package Go\ZF2\GoAopModule\Tests\Aspect
10+
* @package Go\Zend\Framework\Tests\Aspect
911
*/
1012
class TestAspect implements Aspect
1113
{
12-
14+
/**
15+
* @param MethodInvocation $invocation
16+
* @Around("execution(public Go\Zend\Framework\Tests\Advice\TestAdvice->get*(*))")
17+
*/
18+
public function aspectAdvice(MethodInvocation $invocation)
19+
{
20+
}
1321
}

tests/Functional/WarmupTest.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Go\Zend\Framework\Tests\Functional;
4+
5+
use Go\Zend\Framework\Console\Command\WarmupCommand;
6+
use PHPUnit\Framework\TestCase;
7+
use Prophecy\Argument;
8+
use Symfony\Component\Console\Input\ArgvInput;
9+
use Symfony\Component\Console\Input\Input;
10+
use Symfony\Component\Console\Input\InputArgument;
11+
use Symfony\Component\Console\Input\InputDefinition;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
15+
/**
16+
* @package Go\Zend\Framework\Tests\Functional
17+
*/
18+
class WarmupTest extends TestCase
19+
{
20+
/**
21+
* @test
22+
*/
23+
public function itShouldFindAdviceAccordingToConfig()
24+
{
25+
$input = $this->prophesize(InputInterface::class);
26+
$input->bind(Argument::any())->willReturn();
27+
$input->isInteractive()->willReturn(false);
28+
$input->hasArgument(Argument::any())->willReturn(false);
29+
$input->validate()->willReturn();
30+
31+
$input->getArgument('applicationConfig')
32+
->willReturn(__DIR__ . '/../resources/application_config.php');
33+
34+
$output = $this->getMockBuilder(OutputInterface::class)
35+
->setMethods(['writeln'])
36+
->getMockForAbstractClass();
37+
38+
$output->expects($this->at(1))
39+
->method('writeln')
40+
->with('Total <info>1</info> files to process.');
41+
42+
$command = new WarmupCommand();
43+
$command->run($input->reveal(), $output);
44+
}
45+
}

tests/Integration/ModuleTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22

3-
namespace Go\ZF2\GoAopModule\Tests\Integration;
3+
namespace Go\Zend\Framework\Tests\Integration;
44

55
use Go\Core\AspectContainer;
66
use Go\Core\GoAspectContainer;
7-
use Go\ZF2\GoAopModule\Tests\Aspect\TestAspect;
7+
use Go\Zend\Framework\Tests\Aspect\TestAspect;
88
use PHPUnit\Framework\TestCase;
99
use Zend\Mvc\Application;
1010

1111
/**
12-
* @package Go\ZF2\GoAopModule\Tests\Integration
12+
* @package Go\Zend\Framework\Tests\Integration
1313
*/
1414
class ModuleTest extends TestCase
1515
{

tests/Unit/Factory/AspectContainerFactoryTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22

3-
namespace Go\ZF2\GoAopModule\Tests\Unit\Factory;
3+
namespace Go\Zend\Framework\Tests\Unit\Factory;
44

55
use Go\Core\AspectContainer;
66
use Go\Core\AspectKernel;
7-
use Go\ZF2\GoAopModule\Factory\AspectContainerFactory;
7+
use Go\Zend\Framework\Factory\AspectContainerFactory;
88
use PHPUnit\Framework\TestCase;
99
use Zend\ServiceManager\ServiceLocatorInterface;
1010

1111
/**
12-
* @package Go\ZF2\GoAopModule\Tests\Unit\Factory
12+
* @package Go\Zend\Framework\Tests\Unit\Factory
1313
*/
1414
class AspectContainerFactoryTest extends TestCase
1515
{

tests/Unit/Factory/AspectKernelFactoryTest.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?php
22

3-
namespace Go\ZF2\GoAopModule\Tests\Unit\Factory;
3+
namespace Go\Zend\Framework\Tests\Unit\Factory;
44

55
use Go\Core\AspectKernel;
6-
use Go\ZF2\GoAopModule\Factory\AspectKernelFactory;
6+
use Go\Zend\Framework\Factory\AspectKernelFactory;
7+
use Go\Zend\Framework\Module;
78
use PHPUnit\Framework\TestCase;
89
use Zend\ServiceManager\ServiceLocatorInterface;
910

1011
/**
11-
* @package Go\ZF2\GoAopModule\Tests\Unit\Factory
12+
* @package Go\Zend\Framework\Tests\Unit\Factory
1213
*/
1314
class AspectKernelFactoryTest extends TestCase
1415
{
@@ -19,7 +20,7 @@ public function itCreatesKernelOnInvoke()
1920
{
2021
$serviceLocator = $this->prophesize(ServiceLocatorInterface::class);
2122
$serviceLocator->get('config')
22-
->willReturn(['goaop_module' => require __DIR__ . '/../../resources/goaop_module.php'])
23+
->willReturn([Module::CONFIG_KEY => require __DIR__ . '/../../resources/goaop_module.php'])
2324
->shouldBeCalled();
2425

2526
$factory = new AspectKernelFactory();
@@ -40,7 +41,7 @@ public function itCreatesKernelOnCreateService()
4041
{
4142
$serviceLocator = $this->prophesize(ServiceLocatorInterface::class);
4243
$serviceLocator->get('config')
43-
->willReturn(['goaop_module' => require __DIR__ . '/../../resources/goaop_module.php'])
44+
->willReturn([Module::CONFIG_KEY => require __DIR__ . '/../../resources/goaop_module.php'])
4445
->shouldBeCalled();
4546

4647
$factory = new AspectKernelFactory();

tests/Unit/ModuleTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace Go\ZF2\GoAopModule\Tests\Unit;
3+
namespace Go\Zend\Framework\Tests\Unit;
44

55
use Go\Aop\Aspect;
66
use Go\Core\AspectContainer;
7-
use Go\ZF2\GoAopModule\Module;
7+
use Go\Zend\Framework\Module;
88
use PHPUnit\Framework\TestCase;
99
use Prophecy\Argument;
1010
use Zend\EventManager\EventManagerInterface;
@@ -13,7 +13,7 @@
1313
use Zend\ServiceManager\ServiceManager;
1414

1515
/**
16-
* @package Go\ZF2\GoAopModule\Tests\Unit
16+
* @package Go\Zend\Framework\Tests\Unit
1717
*/
1818
class ModuleTest extends TestCase
1919
{
@@ -66,7 +66,7 @@ public function itRegisterAspectsOnInitializeAspects()
6666
->willReturn($aspectContainer->reveal())
6767
->shouldBeCalled();
6868
$serviceManager->get('config')
69-
->willReturn(['goaop_aspect' => ['testAspect']])
69+
->willReturn([Module::ASPECT_CONFIG_KEY => ['testAspect']])
7070
->shouldBeCalled();
7171
$serviceManager->get('testAspect')
7272
->willReturn($aspect)

0 commit comments

Comments
 (0)