|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * Copyright (C) 2024 Daniel Siepmann <[email protected]> |
| 7 | + * |
| 8 | + * This program is free software; you can redistribute it and/or |
| 9 | + * modify it under the terms of the GNU General Public License |
| 10 | + * as published by the Free Software Foundation; either version 2 |
| 11 | + * of the License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License |
| 19 | + * along with this program; if not, write to the Free Software |
| 20 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 21 | + * 02110-1301, USA. |
| 22 | + */ |
| 23 | + |
| 24 | +namespace Typo3\TestingFramework\Tests\Unit\Core; |
| 25 | + |
| 26 | +use PHPUnit\Framework\TestCase; |
| 27 | +use TYPO3\CMS\Core\Package\PackageManager; |
| 28 | +use TYPO3\CMS\Core\Service\DependencyOrderingService; |
| 29 | +use TYPO3\TestingFramework\Composer\ComposerPackageManager; |
| 30 | +use TYPO3\TestingFramework\Core\PackageCollection; |
| 31 | + |
| 32 | +final class PackageCollectionTest extends TestCase |
| 33 | +{ |
| 34 | + /** |
| 35 | + * @test |
| 36 | + */ |
| 37 | + public function sortsComposerPackages(): void |
| 38 | + { |
| 39 | + $packageStates = require __DIR__ . '/Fixtures/Packages/PackageStates.php'; |
| 40 | + $packageStates = $packageStates['packages']; |
| 41 | + $basePath = realpath(__DIR__ . '/../../../'); |
| 42 | + |
| 43 | + $composerPackageManager = new ComposerPackageManager(); |
| 44 | + // That way it knows about the extensions, this is done by TestBase upfront. |
| 45 | + $composerPackageManager->getPackageInfoWithFallback(__DIR__ . '/Fixtures/Packages/package0'); |
| 46 | + $composerPackageManager->getPackageInfoWithFallback(__DIR__ . '/Fixtures/Packages/package1'); |
| 47 | + $composerPackageManager->getPackageInfoWithFallback(__DIR__ . '/Fixtures/Packages/package2'); |
| 48 | + |
| 49 | + $subject = PackageCollection::fromPackageStates( |
| 50 | + $composerPackageManager, |
| 51 | + new PackageManager( |
| 52 | + new DependencyOrderingService(), |
| 53 | + __DIR__ . '/Fixtures/Packages/PackageStates.php', |
| 54 | + $basePath |
| 55 | + ), |
| 56 | + $basePath, |
| 57 | + $packageStates |
| 58 | + ); |
| 59 | + |
| 60 | + $result = $subject->sortPackageStates( |
| 61 | + $packageStates, |
| 62 | + new DependencyOrderingService() |
| 63 | + ); |
| 64 | + |
| 65 | + self::assertSame(7, array_search('package2', array_keys($result)), 'Package 2 is not stored at loading order 7.'); |
| 66 | + self::assertSame(6, array_search('package1', array_keys($result)), 'Package 1 is not stored at loading order 6.'); |
| 67 | + self::assertSame(5, array_search('package0', array_keys($result)), 'Package 0 is not stored at loading order 5.'); |
| 68 | + } |
| 69 | +} |
0 commit comments