public void HasPhpAndComposerInstallScript_IfDynamicInstallIsEnabled_AndPhpAndComposerVersionIsNotAlreadyInstalled() { // Arrange var expectedPhpScript = "test-php-installation-script"; var expectedPhpComposerScript = "test-php-composer-installation-script"; var commonOptions = new BuildScriptGeneratorOptions(); commonOptions.EnableDynamicInstall = true; var phpPlatform = CreatePhpPlatform( commonOptions: commonOptions, isPhpVersionAlreadyInstalled: false, phpInstallationScript: expectedPhpScript, isPhpComposerAlreadyInstalled: false, phpComposerInstallationScript: expectedPhpComposerScript); var repo = new MemorySourceRepo(); repo.AddFile("{}", PhpConstants.ComposerFileName); var context = CreateContext(repo); var detectedResult = new PhpPlatformDetectorResult { Platform = PhpConstants.PlatformName, PlatformVersion = "7.3.5", }; // Act var actualScriptSnippet = phpPlatform.GetInstallerScriptSnippet(context, detectedResult); // Assert Assert.NotNull(actualScriptSnippet); Assert.Contains(expectedPhpScript, actualScriptSnippet); Assert.Contains(expectedPhpComposerScript, actualScriptSnippet); }
private void ResolveVersionsUsingHierarchicalRules(PhpPlatformDetectorResult detectorResult) { var phpVersion = ResolvePhpVersion(detectorResult.PlatformVersion); phpVersion = this.GetMaxSatisfyingPhpVersionAndVerify(phpVersion); var phpComposerVersion = ResolvePhpComposerVersion(detectorResult.PhpComposerVersion); phpComposerVersion = this.GetMaxSatisfyingPhpComposerVersionAndVerify(phpComposerVersion); detectorResult.PlatformVersion = phpVersion; detectorResult.PhpComposerVersion = phpComposerVersion; string ResolvePhpVersion(string detectedVersion) { // Explicitly specified version by user wins over detected version if (!string.IsNullOrEmpty(this.phpScriptGeneratorOptions.PhpVersion)) { return(this.phpScriptGeneratorOptions.PhpVersion); } // If a version was detected, then use it. if (detectedVersion != null) { return(detectedVersion); } // Fallback to default version var versionInfo = this.phpVersionProvider.GetVersionInfo(); return(versionInfo.DefaultVersion); } string ResolvePhpComposerVersion(string detectedVersion) { // Explicitly specified version by user wins over detected version if (!string.IsNullOrEmpty(this.phpScriptGeneratorOptions.PhpComposerVersion)) { return(this.phpScriptGeneratorOptions.PhpComposerVersion); } // If a version was detected, then use it. if (detectedVersion != null) { return(detectedVersion); } // Fallback to default version return(PhpVersions.ComposerVersion); } }
private static PlatformDetectorResult GetPlatformDetectorResult(string name, string version) { var result = new PlatformDetectorResult(); switch (name) { case DotNetCoreConstants.PlatformName: result = new DotNetCorePlatformDetectorResult(); break; case NodeConstants.PlatformName: result = new NodePlatformDetectorResult(); break; case PythonConstants.PlatformName: result = new PythonPlatformDetectorResult(); break; case HugoConstants.PlatformName: result = new PlatformDetectorResult(); break; case PhpConstants.PlatformName: result = new PhpPlatformDetectorResult(); break; case JavaConstants.PlatformName: result = new JavaPlatformDetectorResult(); break; case RubyConstants.PlatformName: result = new RubyPlatformDetectorResult(); break; } result.Platform = name; result.PlatformVersion = version; return(result); }
public void GeneratedScript_UsesComposerInstall() { // Arrange var scriptGenerator = GetScriptGenerator( defaultVersion: "7.3", new BuildScriptGeneratorOptions(), new PhpScriptGeneratorOptions()); var repo = new MemorySourceRepo(); repo.AddFile(ComposerFileWithBuildScript, PhpConstants.ComposerFileName); var context = CreateBuildScriptGeneratorContext(repo); var detectorResult = new PhpPlatformDetectorResult { Platform = PhpConstants.PlatformName, PlatformVersion = "10.10.10", }; // Act var snippet = scriptGenerator.GenerateBashBuildScriptSnippet(context, detectorResult); // Assert Assert.NotNull(snippet); Assert.Contains("$composer install", snippet.BashBuildScriptSnippet); }