-
-
Notifications
You must be signed in to change notification settings - Fork 437
Make the root package name and path dynamically discovered in MakerTestCase
#1770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.x
Are you sure you want to change the base?
Changes from all commits
21243d2
08e8186
f5037d6
49fe41f
b1437ff
a3fcdf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
|
|
||
| namespace Symfony\Bundle\MakerBundle\Test; | ||
|
|
||
| use Composer\InstalledVersions; | ||
| use Symfony\Component\Filesystem\Filesystem; | ||
| use Symfony\Component\Process\InputStream; | ||
|
|
||
|
|
@@ -28,7 +29,8 @@ final class MakerTestEnvironment | |
| public const GENERATED_FILES_REGEX = '#(?:created|updated):\s(?:.*\\\\)*(.*\.[a-z]{3,4}).*(?:\\\\n)?#ui'; | ||
|
|
||
| private Filesystem $fs; | ||
| private bool|string $rootPath; | ||
| private string $packageName; | ||
| private string $rootPath; | ||
| private string $cachePath; | ||
| private string $flexPath; | ||
| private string $path; | ||
|
|
@@ -41,7 +43,9 @@ private function __construct( | |
| $this->isWindows = str_contains(strtolower(\PHP_OS), 'win'); | ||
|
|
||
| $this->fs = new Filesystem(); | ||
| $this->rootPath = realpath(__DIR__.'/../../'); | ||
| $composerPackage = InstalledVersions::getRootPackage(); | ||
| $this->packageName = $composerPackage['name']; | ||
| $this->rootPath = realpath($composerPackage['install_path']); | ||
| $cachePath = $this->rootPath.'/tests/tmp/cache'; | ||
|
|
||
| if (!$this->fs->exists($cachePath)) { | ||
|
|
@@ -134,7 +138,7 @@ public function prepareDirectory(): void | |
| { | ||
| // Copy MakerBundle to a "repo" directory for tests | ||
| if (!file_exists($makerRepoPath = \sprintf('%s/maker-repo', $this->cachePath))) { | ||
| MakerTestProcess::create(\sprintf('git clone %s %s', $this->rootPath, $makerRepoPath), $this->cachePath)->run(); | ||
| MakerTestProcess::create(['git', 'clone', $this->rootPath, $makerRepoPath], $this->cachePath)->run(); | ||
| } | ||
|
|
||
| if (!$this->fs->exists($this->flexPath)) { | ||
|
|
@@ -144,15 +148,7 @@ public function prepareDirectory(): void | |
| if (!$this->fs->exists($this->path)) { | ||
| try { | ||
| // let's do some magic here git is faster than copy | ||
| MakerTestProcess::create( | ||
| '\\' === \DIRECTORY_SEPARATOR ? 'git clone %FLEX_PATH% %APP_PATH%' : 'git clone "$FLEX_PATH" "$APP_PATH"', | ||
| \dirname($this->flexPath), | ||
| [ | ||
| 'FLEX_PATH' => $this->flexPath, | ||
| 'APP_PATH' => $this->path, | ||
| ] | ||
| ) | ||
| ->run(); | ||
| MakerTestProcess::create(['git', 'clone', $this->flexPath, $this->path], \dirname($this->flexPath))->run(); | ||
|
|
||
| // In Window's we have to require MakerBundle in each project - git clone doesn't symlink well | ||
| if ($this->isWindows) { | ||
|
|
@@ -190,7 +186,10 @@ public function prepareDirectory(): void | |
| } | ||
| } | ||
|
|
||
| public function runCommand(string $command): MakerTestProcess | ||
| /** | ||
| * @param string|list<string> $command | ||
| */ | ||
| public function runCommand(string|array $command): MakerTestProcess | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a breaking change because the class is internal.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest adding a phpdoc
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same in MakerTestProcess btw |
||
| { | ||
| return MakerTestProcess::create($command, $this->path)->run(); | ||
| } | ||
|
|
@@ -230,7 +229,7 @@ public function fileExists(string $file): bool | |
|
|
||
| public function runTwigCSLint(string $file): MakerTestProcess | ||
| { | ||
| if (!file_exists(__DIR__.'/../../tools/twigcs/vendor/bin/twigcs')) { | ||
| if (!file_exists($this->rootPath.'/tools/twigcs/vendor/bin/twigcs')) { | ||
| throw new \Exception('twigcs not found: run: "composer upgrade -W --working-dir=tools/twigcs".'); | ||
| } | ||
|
|
||
|
|
@@ -243,20 +242,20 @@ private function buildFlexSkeleton(): void | |
| $targetVersion = $this->getTargetSkeletonVersion(); | ||
| $versionString = $targetVersion ? \sprintf(':%s', $targetVersion) : ''; | ||
|
|
||
| $flexProjectDir = \sprintf('flex_project%s', $targetVersion); | ||
| $flexProjectDir = \sprintf('%s/flex_project%s', $this->cachePath, $targetVersion); | ||
|
|
||
| MakerTestProcess::create( | ||
| \sprintf('composer create-project symfony/skeleton%s %s --prefer-dist --no-progress --keep-vcs', $versionString, $flexProjectDir), | ||
| $this->cachePath | ||
| )->run(); | ||
|
|
||
| $rootPath = str_replace('\\', '\\\\', realpath(__DIR__.'/../..')); | ||
| $rootPath = str_replace('\\', '\\\\', $this->rootPath); | ||
|
|
||
| $this->addMakerBundleRepoToComposer(\sprintf('%s/%s/composer.json', $this->cachePath, $flexProjectDir)); | ||
| $this->addMakerBundleRepoToComposer($flexProjectDir); | ||
|
|
||
| // In Linux, git plays well with symlinks - we can add maker to the flex skeleton. | ||
| if (!$this->isWindows) { | ||
| $this->composerRequireMakerBundle(\sprintf('%s/%s', $this->cachePath, $flexProjectDir)); | ||
| $this->composerRequireMakerBundle($flexProjectDir); | ||
| } | ||
|
|
||
| // fetch a few packages needed for testing | ||
|
|
@@ -411,9 +410,7 @@ public function getTargetSkeletonVersion(): ?string | |
|
|
||
| private function composerRequireMakerBundle(string $projectDirectory): void | ||
| { | ||
| MakerTestProcess::create('composer require --dev symfony/maker-bundle', $projectDirectory) | ||
| ->run() | ||
| ; | ||
| MakerTestProcess::create(['composer', 'require', '--dev', $this->packageName], $projectDirectory)->run(); | ||
|
|
||
| $makerRepoSrcPath = \sprintf('%s/maker-repo/src', $this->cachePath); | ||
|
|
||
|
|
@@ -425,26 +422,20 @@ private function composerRequireMakerBundle(string $projectDirectory): void | |
| } | ||
|
|
||
| /** | ||
| * Adds Symfony/MakerBundle as a "path" repository to composer.json. | ||
| * Adds symfony/maker-bundle as a "path" repository to composer.json. | ||
| */ | ||
| private function addMakerBundleRepoToComposer(string $composerJsonPath): void | ||
| private function addMakerBundleRepoToComposer(string $projectDirectory): void | ||
| { | ||
| $composerJson = json_decode( | ||
| file_get_contents($composerJsonPath), true, 512, \JSON_THROW_ON_ERROR); | ||
|
|
||
| // Require-dev is empty and composer complains about this being an array when we encode it again. | ||
| unset($composerJson['require-dev']); | ||
|
|
||
| $composerJson['repositories']['symfony/maker-bundle'] = [ | ||
| $repo = [ | ||
| 'type' => 'path', | ||
| 'url' => \sprintf('%s%smaker-repo', $this->cachePath, \DIRECTORY_SEPARATOR), | ||
| 'options' => [ | ||
| 'versions' => [ | ||
| 'symfony/maker-bundle' => '9999.99', // Arbitrary version to avoid stability conflicts | ||
| $this->packageName => '9999.99', // Arbitrary version to avoid stability conflicts | ||
| ], | ||
| ], | ||
| ]; | ||
|
|
||
| file_put_contents($composerJsonPath, json_encode($composerJson, \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES)); | ||
| MakerTestProcess::create(['composer', 'repo', 'add', $this->packageName, json_encode($repo)], $projectDirectory)->run(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,10 @@ final class MakerTestProcess | |
| { | ||
| private Process $process; | ||
|
|
||
| private function __construct($commandLine, $cwd, array $envVars, $timeout) | ||
| /** | ||
| * @param string|list<string> $commandLine | ||
| */ | ||
| private function __construct(string|array $commandLine, string $cwd, array $envVars, ?float $timeout) | ||
| { | ||
| $this->process = \is_string($commandLine) | ||
| ? Process::fromShellCommandline($commandLine, $cwd, null, null, $timeout) | ||
|
|
@@ -31,7 +34,10 @@ private function __construct($commandLine, $cwd, array $envVars, $timeout) | |
| $this->process->setEnv($envVars); | ||
| } | ||
|
|
||
| public static function create($commandLine, $cwd, array $envVars = [], $timeout = null): self | ||
| /** | ||
| * @param string|list<string> $commandLine | ||
| */ | ||
| public static function create(string|array $commandLine, string $cwd, array $envVars = [], ?float $timeout = null): self | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a breaking change because the class is final and internal |
||
| { | ||
| return new self($commandLine, $cwd, $envVars, $timeout); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.