This repository has been archived by the owner on Dec 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ab072d
commit 3ca9d36
Showing
8 changed files
with
160 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/composer-json-manipulator/tests/Sorter/ComposerPackageSorterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symplify\ComposerJsonManipulator\Tests\Sorter; | ||
|
||
use Iterator; | ||
use Symplify\ComposerJsonManipulator\Sorter\ComposerPackageSorter; | ||
use Symplify\ComposerJsonManipulator\Tests\HttpKernel\ComposerJsonManipulatorKernel; | ||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase; | ||
|
||
final class ComposerPackageSorterTest extends AbstractKernelTestCase | ||
{ | ||
/** | ||
* @var ComposerPackageSorter | ||
*/ | ||
private $composerPackageSorter; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->bootKernel(ComposerJsonManipulatorKernel::class); | ||
|
||
$this->composerPackageSorter = self::$container->get(ComposerPackageSorter::class); | ||
} | ||
|
||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(array $packages, array $expectedSortedPackages): void | ||
{ | ||
$sortedPackages = $this->composerPackageSorter->sortPackages($packages); | ||
$this->assertSame($expectedSortedPackages, $sortedPackages); | ||
} | ||
|
||
public function provideData(): Iterator | ||
{ | ||
yield [ | ||
[ | ||
'symfony/console' => '^5.2', | ||
'php' => '^8.0', | ||
'ext-json' => '*', | ||
], | ||
[ | ||
'php' => '^8.0', | ||
'ext-json' => '*', | ||
'symfony/console' => '^5.2', | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/monorepo-builder/packages/testing/src/ComposerJsonUpdater.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symplify\MonorepoBuilder\Testing; | ||
|
||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symplify\ComposerJsonManipulator\FileSystem\JsonFileManager; | ||
use Symplify\MonorepoBuilder\Package\PackageNamesProvider; | ||
use Symplify\MonorepoBuilder\Testing\ComposerJson\ComposerJsonSymlinker; | ||
use Symplify\MonorepoBuilder\Testing\ComposerJson\ComposerVersionManipulator; | ||
use Symplify\MonorepoBuilder\Testing\PackageDependency\UsedPackagesResolver; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class ComposerJsonUpdater | ||
{ | ||
/** | ||
* @var PackageNamesProvider | ||
*/ | ||
private $packageNamesProvider; | ||
|
||
/** | ||
* @var JsonFileManager | ||
*/ | ||
private $jsonFileManager; | ||
|
||
/** | ||
* @var SymfonyStyle | ||
*/ | ||
private $symfonyStyle; | ||
|
||
/** | ||
* @var ComposerJsonSymlinker | ||
*/ | ||
private $composerJsonSymlinker; | ||
|
||
/** | ||
* @var ComposerVersionManipulator | ||
*/ | ||
private $composerVersionManipulator; | ||
|
||
/** | ||
* @var UsedPackagesResolver | ||
*/ | ||
private $usedPackagesResolver; | ||
|
||
public function __construct( | ||
PackageNamesProvider $packageNamesProvider, | ||
JsonFileManager $jsonFileManager, | ||
SymfonyStyle $symfonyStyle, | ||
ComposerJsonSymlinker $composerJsonSymlinker, | ||
ComposerVersionManipulator $composerVersionManipulator, | ||
UsedPackagesResolver $usedPackagesResolver | ||
) { | ||
$this->packageNamesProvider = $packageNamesProvider; | ||
$this->jsonFileManager = $jsonFileManager; | ||
$this->symfonyStyle = $symfonyStyle; | ||
$this->composerJsonSymlinker = $composerJsonSymlinker; | ||
$this->composerVersionManipulator = $composerVersionManipulator; | ||
$this->usedPackagesResolver = $usedPackagesResolver; | ||
} | ||
|
||
public function processPackage(SmartFileInfo $packageFileInfo, SmartFileInfo $mainComposerJsonFileInfo): void | ||
{ | ||
$packageComposerJson = $this->jsonFileManager->loadFromFileInfo($packageFileInfo); | ||
|
||
$usedPackageNames = $this->usedPackagesResolver->resolveForPackage($packageComposerJson); | ||
$packageComposerJson = $this->composerVersionManipulator->setAsteriskVersionForUsedPackages( | ||
$packageComposerJson, | ||
$usedPackageNames | ||
); | ||
|
||
// possibly replace them all to cover recursive secondary dependencies | ||
$packageNames = $this->packageNamesProvider->provide(); | ||
|
||
$packageComposerJson = $this->composerJsonSymlinker->decoratePackageComposerJsonWithPackageSymlinks( | ||
$packageComposerJson, | ||
$packageNames, | ||
$mainComposerJsonFileInfo | ||
); | ||
|
||
$message = sprintf('File "%s" was updated', $packageFileInfo->getRelativeFilePathFromCwd()); | ||
$this->symfonyStyle->note($message); | ||
|
||
$this->jsonFileManager->saveJsonWithFileInfo($packageComposerJson, $packageFileInfo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters