From bed1483d1bbb22ba8f60beb9eb689d3ada33e295 Mon Sep 17 00:00:00 2001 From: Georg Ringer Date: Tue, 20 Nov 2018 21:41:55 +0100 Subject: [PATCH] [TASK] Provide ExtensionTestEnvironment for 8branch (#112) --- Classes/Composer/ExtensionTestEnvironment.php | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Classes/Composer/ExtensionTestEnvironment.php diff --git a/Classes/Composer/ExtensionTestEnvironment.php b/Classes/Composer/ExtensionTestEnvironment.php new file mode 100644 index 00000000..3debf677 --- /dev/null +++ b/Classes/Composer/ExtensionTestEnvironment.php @@ -0,0 +1,87 @@ +/typo3conf/ext/". + * + * This class is added as composer "script" in TYPO3 extensions: + * + * "scripts": { + * "post-autoload-dump": [ + * "@prepare-extension-test-environment" + * ], + * "prepare-extension-test-structure": [ + * "TYPO3\TestingFramework\Composer\ExtensionTestEnvironment::prepare" + * ] + * }, + * + * It additionally needs the "extension key" (that will become the directory name in + * typo3conf/ext) and the name of the target directory in the extra section. Example for + * a extension "my_cool_extension": + * + * "extra": { + * "typo3/cms": { + * "web-dir": ".Build/Web", + * "extension-key": "my_cool_extension" + * } + * } + */ +final class ExtensionTestEnvironment +{ + /** + * Link directory that contains the composer.json file as + * .//typo3conf/ext/. + * + * @param Event $event + */ + public static function prepare(Event $event) + { + $composerConfigExtraSection = $event->getComposer()->getPackage()->getExtra(); + if (empty($composerConfigExtraSection['typo3/cms']['extension-key']) + || empty($composerConfigExtraSection['typo3/cms']['web-dir']) + ) { + throw new \RuntimeException( + 'This script needs properties in composer.json:' + . '"extra" "typo3/cms" "extension-key"' + . ' and "extra" "typo3/cms" "web-dir"', + 1540644486 + ); + } + $extensionKey = $composerConfigExtraSection['typo3/cms']['extension-key']; + $webDir = $composerConfigExtraSection['typo3/cms']['web-dir']; + $typo3confExt = __DIR__ . '/../../../../../../' . $webDir . '/typo3conf/ext'; + if (!is_dir($typo3confExt) && + !mkdir($typo3confExt, 0775, true) && + !is_dir($typo3confExt) + ) { + throw new \RuntimeException( + sprintf('Directory "%s" could not be created', $typo3confExt), + 1540650485 + ); + } + if (!is_link($typo3confExt . '/' . $extensionKey)) { + symlink(dirname(__DIR__, 6) . '/', $typo3confExt . '/' . $extensionKey); + } + } +}