mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 09:00:18 +01:00 
			
		
		
		
	Merge pull request #330 from Toflar/composer-environments
Added support for composer environments
This commit is contained in:
		
						commit
						fef0fee920
					
				@ -229,6 +229,26 @@ class Runtime
 | 
				
			|||||||
        return $default;
 | 
					        return $default;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Shortcut to get the the configuration option for a specific environment and merge it with
 | 
				
			||||||
 | 
					     * the global one (environment specific overrides the global one if present).
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param       $key
 | 
				
			||||||
 | 
					     * @param array $defaultEnv
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return array
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function getMergedOption($key, $defaultEnv = [])
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $userGlobalOptions = $this->getConfigOption($key, $defaultEnv);
 | 
				
			||||||
 | 
					        $userEnvOptions = $this->getEnvOption($key, $defaultEnv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return array_merge(
 | 
				
			||||||
 | 
					            (is_array($userGlobalOptions) ? $userGlobalOptions : []),
 | 
				
			||||||
 | 
					            (is_array($userEnvOptions) ? $userEnvOptions : [])
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Overwrites an Environment Configuration Option
 | 
					     * Overwrites an Environment Configuration Option
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 | 
				
			|||||||
@ -43,10 +43,9 @@ class DumpAutoloadTask extends AbstractTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $userOptions = $this->runtime->getConfigOption('composer', []);
 | 
					 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['path' => 'composer', 'flags' => '--optimize'],
 | 
					            ['path' => 'composer', 'flags' => '--optimize'],
 | 
				
			||||||
            (is_array($userOptions) ? $userOptions : []),
 | 
					            $this->runtime->getMergedOption('composer'),
 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -43,10 +43,9 @@ class InstallTask extends AbstractTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $userOptions = $this->runtime->getConfigOption('composer', []);
 | 
					 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['path' => 'composer', 'flags' => '--optimize-autoloader'],
 | 
					            ['path' => 'composer', 'flags' => '--optimize-autoloader'],
 | 
				
			||||||
            (is_array($userOptions) ? $userOptions : []),
 | 
					            $this->runtime->getMergedOption('composer'),
 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -43,12 +43,9 @@ class AsseticDumpTask extends AbstractTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
 | 
					 | 
				
			||||||
        $userEnvOptions = $this->runtime->getEnvOption('symfony', []);
 | 
					 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
					            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
				
			||||||
            (is_array($userGlobalOptions) ? $userGlobalOptions : []),
 | 
					            $this->runtime->getMergedOption('symfony'),
 | 
				
			||||||
            (is_array($userEnvOptions) ? $userEnvOptions : []),
 | 
					 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -43,12 +43,9 @@ class AssetsInstallTask extends AbstractTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
 | 
					 | 
				
			||||||
        $userEnvOptions = $this->runtime->getEnvOption('symfony', []);
 | 
					 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['console' => 'bin/console', 'env' => 'dev', 'target' => 'web', 'flags' => '--symlink --relative'],
 | 
					            ['console' => 'bin/console', 'env' => 'dev', 'target' => 'web', 'flags' => '--symlink --relative'],
 | 
				
			||||||
            (is_array($userGlobalOptions) ? $userGlobalOptions : []),
 | 
					            $this->runtime->getMergedOption('symfony'),
 | 
				
			||||||
            (is_array($userEnvOptions) ? $userEnvOptions : []),
 | 
					 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -43,12 +43,9 @@ class CacheClearTask extends AbstractTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
 | 
					 | 
				
			||||||
        $userEnvOptions = $this->runtime->getEnvOption('symfony', []);
 | 
					 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
					            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
				
			||||||
            (is_array($userGlobalOptions) ? $userGlobalOptions : []),
 | 
					            $this->runtime->getMergedOption('symfony'),
 | 
				
			||||||
            (is_array($userEnvOptions) ? $userEnvOptions : []),
 | 
					 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -43,12 +43,9 @@ class CacheWarmupTask extends AbstractTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
 | 
					 | 
				
			||||||
        $userEnvOptions = $this->runtime->getEnvOption('symfony', []);
 | 
					 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
					            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
				
			||||||
            (is_array($userGlobalOptions) ? $userGlobalOptions : []),
 | 
					            $this->runtime->getMergedOption('symfony'),
 | 
				
			||||||
            (is_array($userEnvOptions) ? $userEnvOptions : []),
 | 
					 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -80,6 +80,36 @@ class DeployCommandMiscTasksTest extends TestCase
 | 
				
			|||||||
        $this->assertEquals(0, $tester->getStatusCode());
 | 
					        $this->assertEquals(0, $tester->getStatusCode());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testComposerEnvFlags()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $application = new MageApplicationMockup(__DIR__ . '/../../Resources/composer-env.yml');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var AbstractCommand $command */
 | 
				
			||||||
 | 
					        $command = $application->find('deploy');
 | 
				
			||||||
 | 
					        $this->assertTrue($command instanceof DeployCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester = new CommandTester($command);
 | 
				
			||||||
 | 
					        $tester->execute(['command' => $command->getName(), 'environment' => 'test']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $application->getRuntime()->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => '/usr/foobar/composer install --prefer-source',
 | 
				
			||||||
 | 
					            1 => '/usr/foobar/composer dump-autoload --no-scripts',
 | 
				
			||||||
 | 
					            2 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertEquals(0, $tester->getStatusCode());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function testInvalidTaskName()
 | 
					    public function testInvalidTaskName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $application = new MageApplicationMockup(__DIR__ . '/../../Resources/invalid-task.yml');
 | 
					        $application = new MageApplicationMockup(__DIR__ . '/../../Resources/invalid-task.yml');
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										19
									
								
								tests/Resources/composer-env.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								tests/Resources/composer-env.yml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					magephp:
 | 
				
			||||||
 | 
					    log_dir: /tmp
 | 
				
			||||||
 | 
					    composer:
 | 
				
			||||||
 | 
					        path: /usr/bin/composer.phar
 | 
				
			||||||
 | 
					    environments:
 | 
				
			||||||
 | 
					        test:
 | 
				
			||||||
 | 
					            composer:
 | 
				
			||||||
 | 
					                path: /usr/foobar/composer
 | 
				
			||||||
 | 
					            user: tester
 | 
				
			||||||
 | 
					            host_path: /var/www/test
 | 
				
			||||||
 | 
					            exclude:
 | 
				
			||||||
 | 
					                - ./var/cache/*
 | 
				
			||||||
 | 
					                - ./var/log/*
 | 
				
			||||||
 | 
					                - ./web/app_dev.php
 | 
				
			||||||
 | 
					            hosts:
 | 
				
			||||||
 | 
					                - testhost
 | 
				
			||||||
 | 
					            pre-deploy:
 | 
				
			||||||
 | 
					                - composer/install: { flags: '--prefer-source' }
 | 
				
			||||||
 | 
					                - composer/dump-autoload: { flags: '--no-scripts' }
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user