Skip to content

Commit

Permalink
TASK: Hack inject properties to custom ActionController in behat
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Oct 20, 2024
1 parent 805694e commit 1c50ecd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Neos.Neos/Tests/Behavior/Features/Bootstrap/DispatcherTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ public function iDeclareTheFollowingController(string $fullyQualifiedClassName,
$controllerInstance = new ('\\' . $fullyQualifiedClassName)();

if ($controllerInstance instanceof \Neos\Flow\Mvc\Controller\ActionController) {
// inject all the necessary properties of an action controller, as extended classes dont call $this->Flow_Proxy_injectProperties();
\Neos\Utility\ObjectAccess::setProperty($controllerInstance, 'validatorResolver', $this->getObject(\Neos\Flow\Validation\ValidatorResolver::class), true);
\Neos\Utility\ObjectAccess::setProperty($controllerInstance, 'mvcPropertyMappingConfigurationService', $this->getObject(\Neos\Flow\Mvc\Controller\MvcPropertyMappingConfigurationService::class), true);
\Neos\Utility\ObjectAccess::setProperty($controllerInstance, 'viewConfigurationManager', $this->getObject(\Neos\Flow\Mvc\ViewConfigurationManager::class), true);
\Neos\Utility\ObjectAccess::setProperty($controllerInstance, 'objectManager', $this->getObject(\Neos\Flow\ObjectManagement\ObjectManager::class), true);
// run flow property injection code of parent class ActionController not ActionController_Original manually as the extended classes is not proxied and doesnt call $this->Flow_Proxy_injectProperties();
$ref = new \ReflectionClass(get_parent_class($controllerInstance));
$method = $ref->getMethod('Flow_Proxy_injectProperties');
$method->invoke($controllerInstance);
}


$objectManager = $this->getObject(\Neos\Flow\ObjectManagement\ObjectManager::class);
$objects = \Neos\Utility\ObjectAccess::getProperty($objectManager, 'objects', true);
$objects[get_class($controllerInstance)]['i'] = $controllerInstance;
Expand Down

0 comments on commit 1c50ecd

Please sign in to comment.