Esempio n. 1
0
        //[Fact]
        //public void GeneratedScript_UsesNpmInstall_IfPackageLockJsonFileIsPresent()
        //{
        //    // Arrange
        //    var scriptGenerator = GetScriptGenerator(defaultNpmVersion: "6.0.0");
        //    var repo = new MemorySourceRepo();
        //    repo.AddFile(ComposerFileWithNoNpmVersion, NodeConstants.ComposerFileFileName);
        //    repo.AddFile("Package lock json file content here", NodeConstants.PackageLockJsonFileName);
        //    var context = CreateBuildScriptGeneratorContext(repo);
        //    context.LanguageVersion = "8.2.1";
        //    var expected = new NodeBashBuildSnippetProperties(
        //        packageInstallCommand: NpmInstallCommand,
        //        runBuildCommand: null,
        //        runBuildAzureCommand: null);

        //    // Act
        //    var snippet = scriptGenerator.GenerateBashBuildScriptSnippet(context);

        //    // Assert
        //    Assert.NotNull(snippet);
        //    Assert.Equal(TemplateHelpers.Render(
        //        TemplateHelpers.TemplateResource.NodeSnippet, expected), snippet.BashBuildScriptSnippet);
        //}

        //[Fact]
        //public void GeneratedScript_UsesNpmRunBuild_IfBuildNodeIsPresentUnderScripts()
        //{
        //    // Arrange
        //    var scriptGenerator = GetScriptGenerator(defaultNpmVersion: "6.0.0");
        //    var repo = new MemorySourceRepo();
        //    repo.AddFile(ComposerFileWithBuildScript, NodeConstants.ComposerFileFileName);
        //    var context = CreateBuildScriptGeneratorContext(repo);
        //    context.LanguageVersion = "8.2.1";
        //    var expected = new NodeBashBuildSnippetProperties(
        //        packageInstallCommand: NpmInstallCommand,
        //        runBuildCommand: "npm run build",
        //        runBuildAzureCommand: "npm run build:azure");

        //    // Act
        //    var snippet = scriptGenerator.GenerateBashBuildScriptSnippet(context);

        //    // Assert
        //    Assert.NotNull(snippet);
        //    Assert.Equal(TemplateHelpers.Render(
        //        TemplateHelpers.TemplateResource.NodeSnippet, expected), snippet.BashBuildScriptSnippet);
        //}

        private IProgrammingPlatform GetScriptGenerator(string defaultVersion = null)
        {
            var environment = new TestEnvironment();

            environment.Variables[PhpConstants.PhpRuntimeVersionEnvVarName] = defaultVersion;

            var phpVersionProvider = new TestPhpVersionProvider(new[] { "7.2.15", Common.PhpVersions.Php73Version });

            var scriptGeneratorOptions = Options.Create(new PhpScriptGeneratorOptions());
            var optionsSetup           = new PhpScriptGeneratorOptionsSetup(environment);

            optionsSetup.Configure(scriptGeneratorOptions.Value);

            return(new PhpPlatform(scriptGeneratorOptions, phpVersionProvider, NullLogger <PhpPlatform> .Instance, null));
        }
Esempio n. 2
0
        private PhpPlatform CreatePhpPlatform(
            string[] supportedPhpVersions         = null,
            string[] supportedPhpComposerVersions = null,
            string defaultVersion                               = null,
            string defaultComposerVersion                       = null,
            string detectedVersion                              = null,
            BuildScriptGeneratorOptions commonOptions           = null,
            PhpScriptGeneratorOptions phpScriptGeneratorOptions = null,
            bool?isPhpVersionAlreadyInstalled                   = null,
            string phpInstallationScript                        = null,
            bool?isPhpComposerAlreadyInstalled                  = null,
            string phpComposerInstallationScript                = null)
        {
            commonOptions                 = commonOptions ?? new BuildScriptGeneratorOptions();
            phpScriptGeneratorOptions     = phpScriptGeneratorOptions ?? new PhpScriptGeneratorOptions();
            isPhpVersionAlreadyInstalled  = isPhpVersionAlreadyInstalled ?? true;
            phpInstallationScript         = phpInstallationScript ?? "default-php-installation-script";
            isPhpComposerAlreadyInstalled = isPhpComposerAlreadyInstalled ?? true;
            phpComposerInstallationScript = phpComposerInstallationScript ?? "default-php-composer-installation-script";
            var versionProvider = new TestPhpVersionProvider(supportedPhpVersions, defaultVersion);

            supportedPhpComposerVersions = supportedPhpComposerVersions ?? new[] { PhpVersions.ComposerVersion };
            defaultComposerVersion       = defaultComposerVersion ?? PhpVersions.ComposerVersion;
            var composerVersionProvider = new TestPhpComposerVersionProvider(
                supportedPhpComposerVersions,
                defaultComposerVersion);
            var detector     = new TestPhpPlatformDetector(detectedVersion: detectedVersion);
            var phpInstaller = new TestPhpPlatformInstaller(
                Options.Create(commonOptions),
                isPhpVersionAlreadyInstalled.Value,
                phpInstallationScript);
            var phpComposerInstaller = new TestPhpComposerInstaller(
                Options.Create(commonOptions),
                isPhpComposerAlreadyInstalled.Value,
                phpComposerInstallationScript);

            return(new TestPhpPlatform(
                       Options.Create(phpScriptGeneratorOptions),
                       Options.Create(commonOptions),
                       versionProvider,
                       composerVersionProvider,
                       NullLogger <TestPhpPlatform> .Instance,
                       detector,
                       phpInstaller,
                       phpComposerInstaller));
        }
Esempio n. 3
0
        //[Fact]
        //public void GeneratedScript_UsesNpmInstall_IfPackageLockJsonFileIsPresent()
        //{
        //    // Arrange
        //    var scriptGenerator = GetScriptGenerator(defaultNpmVersion: "6.0.0");
        //    var repo = new MemorySourceRepo();
        //    repo.AddFile(ComposerFileWithNoNpmVersion, NodeConstants.ComposerFileFileName);
        //    repo.AddFile("Package lock json file content here", NodeConstants.PackageLockJsonFileName);
        //    var context = CreateBuildScriptGeneratorContext(repo);
        //    context.LanguageVersion = "8.2.1";
        //    var expected = new NodeBashBuildSnippetProperties(
        //        packageInstallCommand: NpmInstallCommand,
        //        runBuildCommand: null,
        //        runBuildAzureCommand: null);

        //    // Act
        //    var snippet = scriptGenerator.GenerateBashBuildScriptSnippet(context);

        //    // Assert
        //    Assert.NotNull(snippet);
        //    Assert.Equal(TemplateHelpers.Render(
        //        TemplateHelpers.TemplateResource.NodeSnippet, expected), snippet.BashBuildScriptSnippet);
        //}

        //[Fact]
        //public void GeneratedScript_UsesNpmRunBuild_IfBuildNodeIsPresentUnderScripts()
        //{
        //    // Arrange
        //    var scriptGenerator = GetScriptGenerator(defaultNpmVersion: "6.0.0");
        //    var repo = new MemorySourceRepo();
        //    repo.AddFile(ComposerFileWithBuildScript, NodeConstants.ComposerFileFileName);
        //    var context = CreateBuildScriptGeneratorContext(repo);
        //    context.LanguageVersion = "8.2.1";
        //    var expected = new NodeBashBuildSnippetProperties(
        //        packageInstallCommand: NpmInstallCommand,
        //        runBuildCommand: "npm run build",
        //        runBuildAzureCommand: "npm run build:azure");

        //    // Act
        //    var snippet = scriptGenerator.GenerateBashBuildScriptSnippet(context);

        //    // Assert
        //    Assert.NotNull(snippet);
        //    Assert.Equal(TemplateHelpers.Render(
        //        TemplateHelpers.TemplateResource.NodeSnippet, expected), snippet.BashBuildScriptSnippet);
        //}

        private IProgrammingPlatform GetScriptGenerator(
            string defaultVersion,
            BuildScriptGeneratorOptions commonOptions,
            PhpScriptGeneratorOptions phpScriptGeneratorOptions)
        {
            var phpVersionProvider = new TestPhpVersionProvider(
                supportedPhpVersions: new[] { "7.2.15", Common.PhpVersions.Php73Version });

            phpScriptGeneratorOptions = phpScriptGeneratorOptions ?? new PhpScriptGeneratorOptions();
            commonOptions             = commonOptions ?? new BuildScriptGeneratorOptions();

            return(new PhpPlatform(
                       Options.Create(phpScriptGeneratorOptions),
                       Options.Create(commonOptions),
                       phpVersionProvider,
                       NullLogger <PhpPlatform> .Instance,
                       detector: null));
        }