-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sorting (segment before literal) to help eyeball-scans. Better test coverage.
- Loading branch information
Showing
17 changed files
with
974 additions
and
349 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
bundle/Spec/CirclicalAutoWire/Controller/ControllerWithParameters.php
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,31 @@ | ||
<?php | ||
|
||
namespace Spec\CirclicalAutoWire\Controller; | ||
|
||
use Spec\CirclicalAutoWire\Form\DummyForm; | ||
use Spec\CirclicalAutoWire\Model\DummyObject; | ||
use Zend\Form\FormElementManager\FormElementManagerV3Polyfill; | ||
use Zend\Mvc\Controller\AbstractActionController; | ||
|
||
/** | ||
* Class ControllerWithParameters | ||
* @package Spec\CirclicalAutoWire\Controller | ||
*/ | ||
class ControllerWithParameters extends AbstractActionController | ||
{ | ||
/** | ||
* ControllerWithParameters constructor. | ||
* | ||
* @param DummyObject $dummyObject | ||
* @param FormElementManagerV3Polyfill $formManager | ||
* @param DummyForm $form This should invoke the FormElementManager | ||
* @param array $config This is a magic name that conjures the ZF config | ||
* @param $formElementManager Magic parameter that injects the FormElementManager | ||
* @param $serviceLocator Should inject the container (bad, but here by popular demand) | ||
*/ | ||
public function __construct(DummyObject $dummyObject, FormElementManagerV3Polyfill $formManager, DummyForm $form, array $config, $formElementManager, $serviceLocator) | ||
{ | ||
|
||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
bundle/Spec/CirclicalAutoWire/Factory/Controller/ReflectionFactorySpec.php
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,47 @@ | ||
<?php | ||
|
||
namespace Spec\CirclicalAutoWire\Factory\Controller; | ||
|
||
use CirclicalAutoWire\Factory\Controller\ReflectionFactory; | ||
use CirclicalAutoWire\Model\AnnotatedRoute; | ||
use Interop\Container\ContainerInterface; | ||
use PhpSpec\ObjectBehavior; | ||
use Spec\CirclicalAutoWire\Controller\AnnotatedController; | ||
use Spec\CirclicalAutoWire\Controller\ControllerWithParameters; | ||
use Spec\CirclicalAutoWire\Form\DummyForm; | ||
use Spec\CirclicalAutoWire\Model\DummyObject; | ||
use Zend\Form\FormElementManager\FormElementManagerTrait; | ||
use Zend\Form\FormElementManager\FormElementManagerV3Polyfill; | ||
|
||
class ReflectionFactorySpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(ReflectionFactory::class); | ||
} | ||
|
||
function it_can_create_classes_that_end_with_controller(ContainerInterface $interface) | ||
{ | ||
$this->canCreate($interface, 'SuperController')->shouldBe(true); | ||
} | ||
|
||
function it_only_creates_controllers(ContainerInterface $interface) | ||
{ | ||
$this->canCreate($interface, 'SuperFactory')->shouldBe(false); | ||
} | ||
|
||
function it_can_create_controllers_through_reflection(ContainerInterface $interface, DummyObject $dummyObject, FormElementManagerV3Polyfill $formManager, DummyForm $form) | ||
{ | ||
$formManager->get(DummyForm::class)->willReturn($form); | ||
$interface->get(DummyObject::class)->willReturn($dummyObject); | ||
$interface->get('FormElementManager')->willReturn($formManager); | ||
$interface->get('config')->willReturn([]); | ||
$this->__invoke($interface, ControllerWithParameters::class); | ||
} | ||
|
||
function it_creates_parameterless_controllers(ContainerInterface $interface) | ||
{ | ||
$this->__invoke($interface, AnnotatedController::class); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
bundle/Spec/CirclicalAutoWire/Factory/Service/RouterServiceFactorySpec.php
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,31 @@ | ||
<?php | ||
|
||
namespace Spec\CirclicalAutoWire\Factory\Service; | ||
|
||
use CirclicalAutoWire\Factory\Service\RouterServiceFactory; | ||
use CirclicalAutoWire\Service\RouterService; | ||
use Interop\Container\ContainerInterface; | ||
use PhpSpec\ObjectBehavior; | ||
use Zend\Router\Http\TreeRouteStack; | ||
|
||
class RouterServiceFactorySpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(RouterServiceFactory::class); | ||
} | ||
|
||
function it_creates_router_services(ContainerInterface $container, TreeRouteStack $stack) | ||
{ | ||
$container->get('config')->willReturn([ | ||
'circlical' => [ | ||
'autowire' => [ | ||
'production_mode' => false, | ||
], | ||
], | ||
]); | ||
$container->get('HttpRouter')->willReturn($stack); | ||
|
||
$this->__invoke($container, RouterService::class)->shouldBeAnInstanceOf(RouterService::class); | ||
} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace Spec\CirclicalAutoWire\Form; | ||
|
||
class DummyForm | ||
{ | ||
|
||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace Spec\CirclicalAutoWire\Model; | ||
|
||
class DummyObject | ||
{ | ||
|
||
} | ||
|
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,125 @@ | ||
<?php | ||
|
||
namespace Spec\CirclicalAutoWire; | ||
|
||
use CirclicalAutoWire\Module; | ||
use CirclicalAutoWire\Service\RouterService; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use Psr\Container\ContainerInterface; | ||
use Zend\Console\Console; | ||
use Zend\EventManager\EventManager; | ||
use Zend\ModuleManager\Listener\ConfigListener; | ||
use Zend\ModuleManager\ModuleEvent; | ||
use Zend\ModuleManager\ModuleManager; | ||
use Zend\Mvc\Application; | ||
use Zend\Mvc\MvcEvent; | ||
use Zend\Router\Http\TreeRouteStack; | ||
|
||
class ModuleSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(Module::class); | ||
} | ||
|
||
function it_returns_its_config() | ||
{ | ||
$this->getConfig()->shouldBeArray(); | ||
} | ||
|
||
function it_binds_its_events(ModuleManager $moduleManager, EventManager $eventManager) | ||
{ | ||
$eventManager->attach(ModuleEvent::EVENT_LOAD_MODULE, Argument::type('array'))->shouldBeCalled(); | ||
$eventManager->attach(ModuleEvent::EVENT_MERGE_CONFIG, Argument::type('array'))->shouldBeCalled(); | ||
$moduleManager->getEventManager()->willReturn($eventManager); | ||
$this->init($moduleManager); | ||
} | ||
|
||
function it_merges_config(ModuleEvent $event, ConfigListener $configListener) | ||
{ | ||
$event->getConfigListener()->willReturn($configListener); | ||
$configListener->getMergedConfig(false)->willReturn(include __DIR__ . '/../../../config/module.config.php'); | ||
$this->configMerge($event); | ||
} | ||
|
||
function it_freaks_out_if_autowire_config_is_missing(ModuleEvent $event, ConfigListener $configListener) | ||
{ | ||
$event->getConfigListener()->willReturn($configListener); | ||
$config = include __DIR__ . '/../../../config/module.config.php'; | ||
unset($config['circlical']); | ||
$configListener->getMergedConfig(false)->willReturn($config); | ||
$this->shouldThrow(\Exception::class)->during('configMerge', [$event]); | ||
} | ||
|
||
function it_sets_routes_in_production_mode_during_config_merge(ModuleEvent $event, ConfigListener $configListener) | ||
{ | ||
$event->getConfigListener()->willReturn($configListener); | ||
$config = include __DIR__ . '/../../../config/module.config.php'; | ||
$config['circlical']['autowire']['compile_to'] = __DIR__ . '/compiled_routes.php'; | ||
$configListener->getMergedConfig(false)->willReturn($config); | ||
$configListener->setMergedConfig(Argument::type('array'))->shouldBeCalled(); | ||
$this->configMerge($event); | ||
} | ||
|
||
function it_listens_for_loading_modules(ModuleEvent $event1, ModuleEvent $event2) | ||
{ | ||
$event1->getModuleName()->willReturn('A'); | ||
$event2->getModuleName()->willReturn('B'); | ||
$this->moduleLoaded($event1); | ||
$this->moduleLoaded($event2); | ||
} | ||
|
||
function it_merges_with_existing_routes_in_production_mode_during_config_merge(ModuleEvent $event, ConfigListener $configListener) | ||
{ | ||
$event->getConfigListener()->willReturn($configListener); | ||
$config = include __DIR__ . '/../../../config/module.config.php'; | ||
$config['circlical']['autowire']['compile_to'] = __DIR__ . '/compiled_routes.php'; | ||
$config['router']['routes'] = []; | ||
$configListener->getMergedConfig(false)->willReturn($config); | ||
$configListener->setMergedConfig(Argument::type('array'))->shouldBeCalled(); | ||
$this->configMerge($event); | ||
} | ||
|
||
function it_scans_modules_during_bootstrap_in_dev_mode_only(MvcEvent $mvcEvent, Application $application, ContainerInterface $container) | ||
{ | ||
$mvcEvent->getApplication()->willReturn($application); | ||
$application->getServiceManager()->willReturn($container); | ||
|
||
Console::overrideIsConsole(false); | ||
|
||
$container->get('config')->willReturn([ | ||
'circlical' => [ | ||
'autowire' => [ | ||
'production_mode' => false, | ||
'compile_to' => __DIR__ . '/compiled_routes.php', | ||
], | ||
], | ||
]); | ||
|
||
$container->get(RouterService::class)->willReturn(new RouterService(new TreeRouteStack(), false)); | ||
|
||
$this->onBootstrap($mvcEvent); | ||
} | ||
|
||
function it_skips_compiling_in_prod_mode(MvcEvent $mvcEvent, Application $application, ContainerInterface $container) | ||
{ | ||
$mvcEvent->getApplication()->willReturn($application); | ||
$application->getServiceManager()->willReturn($container); | ||
|
||
Console::overrideIsConsole(false); | ||
|
||
$container->get('config')->willReturn([ | ||
'circlical' => [ | ||
'autowire' => [ | ||
'production_mode' => true, | ||
'compile_to' => __DIR__ . '/compiled_routes.php', | ||
], | ||
], | ||
]); | ||
|
||
$container->get(RouterService::class)->shouldNotBeCalled(); | ||
|
||
$this->onBootstrap($mvcEvent); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
include __DIR__ . '/Controller/AnnotatedController.php'; | ||
include __DIR__ . '/Controller/SimpleController.php'; | ||
include __DIR__ . '/Controller/SameNameAController.php'; | ||
include __DIR__ . '/Controller/SameNameBController.php'; | ||
include __DIR__ . '/Controller/ChildRouteController.php'; | ||
include __DIR__ . '/Controller/ControllerWithParameters.php'; | ||
include __DIR__ . '/Model/DummyObject.php'; | ||
include __DIR__ . '/Form/DummyForm.php'; |
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,3 @@ | ||
<?php | ||
return array( | ||
); |
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
Oops, something went wrong.