[TASK] Activate all packages in unit tests 36/29036/10
authorHelmut Hummel <helmut.hummel@typo3.org>
Tue, 1 Apr 2014 10:08:15 +0000 (12:08 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sun, 6 Apr 2014 19:37:49 +0000 (21:37 +0200)
Introduce a new package manager class for unit tests
that does not read the PackageState.php file any more
but scans for packages and activates them,
so that the class loader can find the classes of all
extensions even if the according extension is not active in
the current TYPO3 installation.

Since the unit test bootstrap does not read other
extension files (ext_localconf.php, etc.) any more,
we can be sure that this does not introduce any
further side effects.

Since the PackageStates.php file will then be obsolete,
it will be removed from the travis integration repository.

Resolves: #57487
Releases: 6.2
Change-Id: Id0cd50db68fd94a31a996496fd5c54049ca94e78
Reviewed-on: https://review.typo3.org/29036
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/core/Build/UnitTestsBootstrap.php
typo3/sysext/core/Classes/Package/UnitTestPackageManager.php [new file with mode: 0644]

index ef74bd6..443c00a 100644 (file)
@@ -106,7 +106,7 @@ $GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();
        ->disableCoreAndClassesCache()
        ->initializeCachingFramework()
        ->initializeClassLoaderCaches()
-       ->initializePackageManagement('TYPO3\\CMS\\Core\\Package\\PackageManager');
+       ->initializePackageManagement('TYPO3\\CMS\\Core\\Package\\UnitTestPackageManager');
 
 require PATH_site . 'typo3conf/ext/phpunit/Composer/vendor/autoload.php';
 require PATH_site . 'typo3conf/ext/phpunit/Migrations/vfsStream.php';
diff --git a/typo3/sysext/core/Classes/Package/UnitTestPackageManager.php b/typo3/sysext/core/Classes/Package/UnitTestPackageManager.php
new file mode 100644 (file)
index 0000000..cfb325c
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+namespace TYPO3\CMS\Core\Package;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2014 Helmut Hummel <helmut.hummel@typo3.org>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the text file GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\Flow\Utility\Files;
+
+/**
+ * This is an intermediate package manager that loads
+ * all extensions that are present in one of the package base paths,
+ * so that the class loader can find the classes of all tests,
+ * whether the according extension is active in the installation itself or not.
+ */
+class UnitTestPackageManager extends \TYPO3\CMS\Core\Package\PackageManager {
+
+       /**
+        * Initializes the package manager
+        *
+        * @param \TYPO3\CMS\Core\Core\Bootstrap|\TYPO3\Flow\Core\Bootstrap $bootstrap The current bootstrap; Flow Bootstrap is here by intention to keep the PackageManager valid to the interface
+        * @return void
+        */
+       public function initialize(\TYPO3\Flow\Core\Bootstrap $bootstrap) {
+               $this->bootstrap = $bootstrap;
+
+               $this->scanAvailablePackages();
+               $this->activePackages = $this->packages;
+
+               $cacheIdentifier = uniqid();
+               $this->classLoader->setCacheIdentifier($cacheIdentifier)->setPackages($this->activePackages);
+       }
+
+       /**
+        * Overwrite the original method to avoid resolving dependencies (which we do not need)
+        * and saving the PackageStates.php file (which we do not want), when calling scanAvailablePackages()
+        *
+        * @return void
+        */
+       protected function sortAndSavePackageStates() {
+               // Deliberately empty!
+       }
+
+}
\ No newline at end of file