Skip to content

Commit

Permalink
Merge pull request #495 from daniellienert/task/refactor-namespaces-i…
Browse files Browse the repository at this point in the history
…n-functional-tests-aop-to-object

TASK: Refactor absolute namespaces in Flow / Functional Test Classes

Refactors AOP to Object classes.
Also refactored legacy array syntax
  • Loading branch information
kitsunet committed Sep 16, 2016
2 parents 4367870 + a1aae57 commit cc3087f
Show file tree
Hide file tree
Showing 57 changed files with 558 additions and 474 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use TYPO3\Flow\Cache\CacheManager;
use TYPO3\Flow\Tests\Behavior\Features\Bootstrap\IsolatedBehatStepsTrait;
use TYPO3\Flow\Tests\Behavior\Features\Bootstrap\SecurityOperationsTrait;
use TYPO3\Flow\Tests\Functional\Command\BehatTestHelper;
use TYPO3\Flow\Utility\Environment;

require_once(__DIR__ . '/../../../../../../Application/Flowpack.Behat/Tests/Behat/FlowContext.php');
require_once(__DIR__ . '/IsolatedBehatStepsTrait.php');
Expand All @@ -21,7 +23,7 @@ class FeatureContext extends BehatContext
/**
* @var string
*/
protected $behatTestHelperObjectName = 'TYPO3\Flow\Tests\Functional\Command\BehatTestHelper';
protected $behatTestHelperObjectName = BehatTestHelper::class;

/**
* Initializes the context
Expand All @@ -33,7 +35,7 @@ public function __construct(array $parameters)
$this->useContext('flow', new FlowContext($parameters));
$flowContext = $this->getSubcontext('flow');
$this->objectManager = $flowContext->getObjectManager();
$this->environment = $this->objectManager->get('TYPO3\Flow\Utility\Environment');
$this->environment = $this->objectManager->get(Environment::class);
$this->setupSecurity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require_once(__DIR__ . '/SubProcess/SubProcess.php');

use TYPO3\Flow\Configuration\ConfigurationManager;
use TYPO3\Flow\Tests\Features\Bootstrap\SubProcess\SubProcess;
use TYPO3\Flow\Cache\CacheManager;
use PHPUnit_Framework_Assert as Assert;
Expand Down Expand Up @@ -38,7 +39,7 @@ protected function getSubProcess()
{
if ($this->subProcess === null) {
/** @var CacheManager $cacheManager */
$cacheManager = $this->objectManager->get('TYPO3\Flow\Cache\CacheManager');
$cacheManager = $this->objectManager->get(CacheManager::class);
if ($cacheManager->hasCache('Flow_Security_Authorization_Privilege_Method')) {
$cacheManager->getCache('Flow_Security_Authorization_Privilege_Method')->flush();
}
Expand All @@ -48,7 +49,7 @@ protected function getSubProcess()
$objectConfigurationCache->remove('allCompiledCodeUpToDate');
$cacheManager->getCache('Flow_Object_Classes')->flush();

$configurationManager = $this->objectManager->get('TYPO3\Flow\Configuration\ConfigurationManager');
$configurationManager = $this->objectManager->get(ConfigurationManager::class);
$configurationManager->flushConfigurationCache();

$this->subProcess = new SubProcess($this->objectManager->getContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
namespace TYPO3\Flow\Tests\Behavior\Features\Bootstrap;

use TYPO3\Flow\Cache\CacheManager;
use TYPO3\Flow\Configuration\ConfigurationManager;
use TYPO3\Flow\Http\Request;
use TYPO3\Flow\Http\RequestHandler;
use TYPO3\Flow\Mvc\ActionRequest;
use TYPO3\Flow\Security\Account;
use TYPO3\Flow\Reflection\ObjectAccess;
use TYPO3\Flow\Security;
use TYPO3\Flow\Security\Authentication\AuthenticationProviderManager;
use TYPO3\Flow\Security\Authentication\Provider\TestingProvider;
use TYPO3\Flow\Security\Authentication\TokenInterface;
use TYPO3\Flow\Security\Authorization\PrivilegeManagerInterface;
use TYPO3\Flow\Security\Exception\AccessDeniedException;
use TYPO3\Flow\Security\Policy\PolicyService;
use TYPO3\Flow\Tests\Functional\Security\Fixtures\Controller\AuthenticationController;
use TYPO3\Flow\Utility\Arrays;
use PHPUnit_Framework_Assert as Assert;

Expand Down Expand Up @@ -45,13 +54,13 @@ public function iHaveTheFollowingPolicies($string)
self::$testingPolicyPathAndFilename = $this->environment->getPathToTemporaryDirectory() . 'Policy.yaml';
file_put_contents(self::$testingPolicyPathAndFilename, $string->getRaw());

$configurationManager = $this->objectManager->get('TYPO3\Flow\Configuration\ConfigurationManager');
$configurations = \TYPO3\Flow\Reflection\ObjectAccess::getProperty($configurationManager, 'configurations', true);
unset($configurations[\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_POLICY]);
\TYPO3\Flow\Reflection\ObjectAccess::setProperty($configurationManager, 'configurations', $configurations, true);
$configurationManager = $this->objectManager->get(ConfigurationManager::class);
$configurations = ObjectAccess::getProperty($configurationManager, 'configurations', true);
unset($configurations[ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_POLICY]);
ObjectAccess::setProperty($configurationManager, 'configurations', $configurations, true);

$policyService = $this->objectManager->get('TYPO3\Flow\Security\Policy\PolicyService');
\TYPO3\Flow\Reflection\ObjectAccess::setProperty($policyService, 'initialized', false, true);
$policyService = $this->objectManager->get(PolicyService::class);
ObjectAccess::setProperty($policyService, 'initialized', false, true);
}

/**
Expand Down Expand Up @@ -102,12 +111,12 @@ public function iCanCallTheMethodOfClassWithArguments($not, $methodName, $classN
$instance = $this->objectManager->get($className);

try {
$result = call_user_func_array(array($instance, $methodName), Arrays::trimExplode(',', $arguments));
$result = call_user_func_array([$instance, $methodName], Arrays::trimExplode(',', $arguments));
if ($not === 'not') {
Assert::fail('Method should not be callable');
}
return $result;
} catch (\TYPO3\Flow\Security\Exception\AccessDeniedException $exception) {
} catch (AccessDeniedException $exception) {
if ($not !== 'not') {
throw $exception;
}
Expand All @@ -127,21 +136,21 @@ protected function setupSecurity()
if ($this->securityInitialized === true) {
return;
}
$this->privilegeManager = $this->objectManager->get('TYPO3\Flow\Security\Authorization\PrivilegeManagerInterface');
$this->privilegeManager = $this->objectManager->get(PrivilegeManagerInterface::class);
$this->privilegeManager->setOverrideDecision(null);

$this->policyService = $this->objectManager->get('TYPO3\Flow\Security\Policy\PolicyService');
$this->policyService = $this->objectManager->get(PolicyService::class);

$this->authenticationManager = $this->objectManager->get('TYPO3\Flow\Security\Authentication\AuthenticationProviderManager');
$this->authenticationManager = $this->objectManager->get(AuthenticationProviderManager::class);

$this->testingProvider = $this->objectManager->get('TYPO3\Flow\Security\Authentication\Provider\TestingProvider');
$this->testingProvider = $this->objectManager->get(TestingProvider::class);
$this->testingProvider->setName('TestingProvider');

$this->securityContext = $this->objectManager->get('TYPO3\Flow\Security\Context');
$this->securityContext = $this->objectManager->get(Security\Context::class);
$this->securityContext->clearContext();
$httpRequest = Request::createFromEnvironment();
$this->mockActionRequest = new ActionRequest($httpRequest);
$this->mockActionRequest->setControllerObjectName('TYPO3\Flow\Tests\Functional\Security\Fixtures\Controller\AuthenticationController');
$this->mockActionRequest->setControllerObjectName(AuthenticationController::class);
$this->securityContext->setRequest($this->mockActionRequest);

$this->securityInitialized = true;
Expand All @@ -152,16 +161,16 @@ protected function setupSecurity()
* The created account is returned for further modification, for example for attaching a Party object to it.
*
* @param array $roleNames A list of roles the new account should have
* @return Account The created account
* @return Security\Accountt The created account
*/
protected function authenticateRoles(array $roleNames)
{
// FIXME this is currently needed in order to correctly import the roles. Otherwise RepositoryInterface::isConnected() returns FALSE and importing is skipped in PolicyService::initializeRolesFromPolicy()
$this->objectManager->get('TYPO3\Flow\Security\AccountRepository')->countAll();
$this->objectManager->get(Security\AccountRepository::class)->countAll();

$account = new Account();
$account = new Security\Account();
$account->setAccountIdentifier('TestAccount');
$roles = array();
$roles = [];
foreach ($roleNames as $roleName) {
$roles[] = $this->policyService->getRole($roleName);
}
Expand All @@ -174,10 +183,10 @@ protected function authenticateRoles(array $roleNames)
/**
* Prepares the environment for and conducts an account authentication
*
* @param Account $account
* @param Security\Account $account
* @return void
*/
protected function authenticateAccount(Account $account)
protected function authenticateAccount(Security\Account $account)
{
$this->testingProvider->setAuthenticationStatus(TokenInterface::AUTHENTICATION_SUCCESSFUL);
$this->testingProvider->setAccount($account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SubProcess
/**
* @var array
*/
protected $pipes = array();
protected $pipes = [];

/**
* @var ApplicationContext
Expand Down Expand Up @@ -87,21 +87,21 @@ public function quit()
protected function launchSubProcess()
{
$systemCommand = 'FLOW_ROOTPATH=' . FLOW_PATH_ROOT . ' FLOW_PATH_TEMPORARY_BASE=' . escapeshellarg(FLOW_PATH_TEMPORARY_BASE) . ' FLOW_CONTEXT=' . (string)$this->context . ' ' . PHP_BINDIR . '/php -c ' . php_ini_loaded_file() . ' ' . FLOW_PATH_FLOW . 'Scripts/flow.php' . ' --start-slave';
$descriptorSpecification = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'a'));
$descriptorSpecification = [['pipe', 'r'], ['pipe', 'w'], ['pipe', 'a']];
$this->subProcess = proc_open($systemCommand, $descriptorSpecification, $this->pipes);
if (!is_resource($this->subProcess)) {
throw new \RuntimeException('Could not execute sub process.');
}

$read = array($this->pipes[1]);
$read = [$this->pipes[1]];
$write = null;
$except = null;
$readTimeout = 30;

stream_select($read, $write, $except, $readTimeout);

$subProcessStatus = proc_get_status($this->subProcess);
return ($subProcessStatus['running'] === true) ? array($this->subProcess, $this->pipes) : false;
return ($subProcessStatus['running'] === true) ? [$this->subProcess, $this->pipes] : false;
}

/**
Expand All @@ -114,7 +114,7 @@ protected function getSubProcessResponse()
if (!is_resource($this->subProcess)) {
return '';
}
$responseLines = array();
$responseLines = [];
while (feof($this->pipes[1]) === false) {
$responseLine = fgets($this->pipes[1]);
if ($responseLine === false) {
Expand Down
4 changes: 3 additions & 1 deletion TYPO3.Flow/Tests/Functional/Aop/AopProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
* source code.
*/

use TYPO3\Flow\Tests\FunctionalTestCase;

/**
* Test suite for aop proxy classes
*/
class AopProxyTest extends \TYPO3\Flow\Tests\FunctionalTestCase
class AopProxyTest extends FunctionalTestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Aop\JoinPointInterface;

/**
* An aspect for testing functionality related to abstract classes
Expand All @@ -22,21 +23,21 @@ class AbstractClassTestingAspect
{
/**
* @Flow\Around("method(public TYPO3\Flow\Tests\Functional\Aop\Fixtures\SubClassOfAbstractClass->abstractMethod())")
* @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint
* @param JoinPointInterface $joinPoint
* @return string
*/
public function abstractMethodInSubClassAdvice(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint)
public function abstractMethodInSubClassAdvice(JoinPointInterface $joinPoint)
{
$result = $joinPoint->getAdviceChain()->proceed($joinPoint);
return $result . ' adviced';
}

/**
* @Flow\Around("method(public TYPO3\Flow\Tests\Functional\Aop\Fixtures\AbstractClass->concreteMethod())")
* @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint
* @param JoinPointInterface $joinPoint
* @return string
*/
public function concreteMethodInAbstractClassAdvice(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint)
public function concreteMethodInAbstractClassAdvice(JoinPointInterface $joinPoint)
{
$result = $joinPoint->getAdviceChain()->proceed($joinPoint);
return $result . ' adviced';
Expand Down

0 comments on commit cc3087f

Please sign in to comment.