From caf60ef0f8e4e1d04dc21617cd41172d82153a9a Mon Sep 17 00:00:00 2001 From: Tim Weisenberger Date: Mon, 20 Nov 2023 15:00:15 +0100 Subject: [PATCH] [BUGFIX] Ignore non-typo3 packages in PackageState todo's: * Test against issue 512 * Test against the core * Check if tests are possible * Commit message Resolves: #510 Releases: main --- Classes/Core/PackageCollection.php | 24 ++++++++++++++++++------ Classes/Core/Testbase.php | 3 ++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Classes/Core/PackageCollection.php b/Classes/Core/PackageCollection.php index d520d3f9..6a3ff288 100644 --- a/Classes/Core/PackageCollection.php +++ b/Classes/Core/PackageCollection.php @@ -25,6 +25,7 @@ use TYPO3\CMS\Core\Service\DependencyOrderingService; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\PathUtility; +use TYPO3\TestingFramework\Composer\ComposerPackageManager; /** * Collection for extension packages to resolve their dependencies in a test-base. @@ -45,23 +46,28 @@ class PackageCollection protected array $packages; /** + * @param ComposerPackageManager $composerPackageManager * @param PackageManager $packageManager * @param array $packageStates */ - public static function fromPackageStates(PackageManager $packageManager, string $basePath, array $packageStates): self + public static function fromPackageStates(ComposerPackageManager $composerPackageManager, PackageManager $packageManager, string $basePath, array $packageStates): self { $packages = []; foreach ($packageStates as $packageKey => $packageStateConfiguration) { $packagePath = PathUtility::sanitizeTrailingSeparator( rtrim($basePath, '/') . '/' . $packageStateConfiguration['packagePath'] ); - $packages[] = new Package($packageManager, $packageKey, $packagePath); + $packages[] = $package = new Package($packageManager, $packageKey, $packagePath); + $packageManager->registerPackage($package); } - return new self(...$packages); + + return new self($composerPackageManager, ...$packages); } - public function __construct(PackageInterface ...$packages) - { + public function __construct( + private ComposerPackageManager $composerPackageManager, + PackageInterface ...$packages, + ) { $this->packages = array_combine( array_map(static fn(PackageInterface $package) => $package->getPackageKey(), $packages), $packages @@ -253,6 +259,11 @@ protected function getDependencyArrayForPackage(PackageInterface $package, array $dependentPackageKeys[] = $dependentPackageKey; } if (!isset($this->packages[$dependentPackageKey])) { + if ($this->isComposerDependency($dependentPackageKey)) { + // The given package has a dependency to a Composer package that has no relation to TYPO3 + // We can ignore those, when calculating the extension order + continue; + } throw new Exception( sprintf( 'Package "%s" depends on package "%s" which does not exist.', @@ -305,6 +316,7 @@ protected function findFrameworkKeys(): array protected function isComposerDependency(string $packageKey): bool { - return false; + $packageInfo = $this->composerPackageManager->getPackageInfo($packageKey); + return !(($packageInfo?->isSystemExtension() ?? false) || ($packageInfo?->isExtension())); } } diff --git a/Classes/Core/Testbase.php b/Classes/Core/Testbase.php index 7b40adf1..eb5d3857 100644 --- a/Classes/Core/Testbase.php +++ b/Classes/Core/Testbase.php @@ -613,9 +613,10 @@ public function setUpPackageStates( ); // PackageManager is required to create a Package instance... $packageCollection = PackageCollection::fromPackageStates( + $this->composerPackageManager, $packageManager, $instancePath, - $packageStates['packages'] + $packageStates['packages'], ); $packageStates['packages'] = $packageCollection->sortPackageStates( $packageStates['packages'],