mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	[Nostromo] Improve test coverage
This commit is contained in:
		
							parent
							
								
									238777cb41
								
							
						
					
					
						commit
						6d708c35fa
					
				@ -94,7 +94,6 @@ class DeployCommand extends AbstractCommand
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            $this->taskFactory = new TaskFactory($this->runtime);
 | 
					            $this->taskFactory = new TaskFactory($this->runtime);
 | 
				
			||||||
            $this->runDeployment($output);
 | 
					            $this->runDeployment($output);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } catch (RuntimeException $exception) {
 | 
					        } catch (RuntimeException $exception) {
 | 
				
			||||||
            $output->writeln('');
 | 
					            $output->writeln('');
 | 
				
			||||||
            $output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
 | 
					            $output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
 | 
				
			||||||
@ -287,12 +286,10 @@ class DeployCommand extends AbstractCommand
 | 
				
			|||||||
                        $this->statusCode = 180;
 | 
					                        $this->statusCode = 180;
 | 
				
			||||||
                        $this->log(sprintf('Task %s (%s) finished with FAIL', $task->getDescription(), $task->getName()));
 | 
					                        $this->log(sprintf('Task %s (%s) finished with FAIL', $task->getDescription(), $task->getName()));
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
                } catch (SkipException $exception) {
 | 
					                } catch (SkipException $exception) {
 | 
				
			||||||
                    $succeededTasks++;
 | 
					                    $succeededTasks++;
 | 
				
			||||||
                    $output->writeln('<fg=yellow>SKIPPED</>');
 | 
					                    $output->writeln('<fg=yellow>SKIPPED</>');
 | 
				
			||||||
                    $this->log(sprintf('Task %s (%s) finished with SKIPPED, thrown SkipException', $task->getDescription(), $task->getName()));
 | 
					                    $this->log(sprintf('Task %s (%s) finished with SKIPPED, thrown SkipException', $task->getDescription(), $task->getName()));
 | 
				
			||||||
 | 
					 | 
				
			||||||
                } catch (ErrorException $exception) {
 | 
					                } catch (ErrorException $exception) {
 | 
				
			||||||
                    $output->writeln(sprintf('<fg=red>ERROR</> [%s]', $exception->getTrimmedMessage()));
 | 
					                    $output->writeln(sprintf('<fg=red>ERROR</> [%s]', $exception->getTrimmedMessage()));
 | 
				
			||||||
                    $this->log(sprintf('Task %s (%s) finished with FAIL, with Error "%s"', $task->getDescription(), $task->getName(), $exception->getMessage()));
 | 
					                    $this->log(sprintf('Task %s (%s) finished with FAIL, with Error "%s"', $task->getDescription(), $task->getName(), $exception->getMessage()));
 | 
				
			||||||
 | 
				
			|||||||
@ -134,7 +134,6 @@ class ListCommand extends AbstractCommand
 | 
				
			|||||||
                    $output->writeln('');
 | 
					                    $output->writeln('');
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } catch (RuntimeException $exception) {
 | 
					        } catch (RuntimeException $exception) {
 | 
				
			||||||
            $output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
 | 
					            $output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
 | 
				
			||||||
            $this->statusCode = $exception->getCode();
 | 
					            $this->statusCode = $exception->getCode();
 | 
				
			||||||
 | 
				
			|||||||
@ -83,7 +83,6 @@ class RollbackCommand extends DeployCommand
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            $this->taskFactory = new TaskFactory($this->runtime);
 | 
					            $this->taskFactory = new TaskFactory($this->runtime);
 | 
				
			||||||
            $this->runDeployment($output);
 | 
					            $this->runDeployment($output);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } catch (RuntimeException $exception) {
 | 
					        } catch (RuntimeException $exception) {
 | 
				
			||||||
            $output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
 | 
					            $output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
 | 
				
			||||||
            $this->statusCode = $exception->getCode();
 | 
					            $this->statusCode = $exception->getCode();
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,6 @@ class CopyTask extends AbstractFileTask
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            return sprintf('[FS] Copy "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
 | 
					            return sprintf('[FS] Copy "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } catch (Exception $exception) {
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
            return '[FS] Copy [missing parameters]';
 | 
					            return '[FS] Copy [missing parameters]';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,6 @@ class LinkTask extends AbstractFileTask
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            return sprintf('[FS] Link "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
 | 
					            return sprintf('[FS] Link "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } catch (Exception $exception) {
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
            return '[FS] Link [missing parameters]';
 | 
					            return '[FS] Link [missing parameters]';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,6 @@ class MoveTask extends AbstractFileTask
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            return sprintf('[FS] Move "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
 | 
					            return sprintf('[FS] Move "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } catch (Exception $exception) {
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
            return '[FS] Move [missing parameters]';
 | 
					            return '[FS] Move [missing parameters]';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,6 @@ class RemoveTask extends AbstractFileTask
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            return sprintf('[FS] Remove "%s"', $this->getFile('file'));
 | 
					            return sprintf('[FS] Remove "%s"', $this->getFile('file'));
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } catch (Exception $exception) {
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
            return '[FS] Remove [missing parameters]';
 | 
					            return '[FS] Remove [missing parameters]';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -18,6 +18,25 @@ use PHPUnit_Framework_TestCase as TestCase;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class DeployCommandMiscTest extends TestCase
 | 
					class DeployCommandMiscTest extends TestCase
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    public function testDeploymentWithNoHosts()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $application = new MageApplicationMockup();
 | 
				
			||||||
 | 
					        $application->configure(__DIR__ . '/../../Resources/no-hosts.yml');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var AbstractCommand $command */
 | 
				
			||||||
 | 
					        $command = $application->find('deploy');
 | 
				
			||||||
 | 
					        $this->assertTrue($command instanceof DeployCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester = new CommandTester($command);
 | 
				
			||||||
 | 
					        $tester->execute(['command' => $command->getName(), 'environment' => 'test']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('No hosts defined, skipping On Deploy tasks', $tester->getDisplay());
 | 
				
			||||||
 | 
					        $this->assertContains('No hosts defined, skipping On Release tasks', $tester->getDisplay());
 | 
				
			||||||
 | 
					        $this->assertContains('No hosts defined, skipping Post Release tasks', $tester->getDisplay());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertEquals(0, $tester->getStatusCode());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function testDeploymentWithSudo()
 | 
					    public function testDeploymentWithSudo()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $application = new MageApplicationMockup();
 | 
					        $application = new MageApplicationMockup();
 | 
				
			||||||
 | 
				
			|||||||
@ -132,4 +132,20 @@ class DeployCommandWithReleasesTest extends TestCase
 | 
				
			|||||||
        $this->assertContains('Copying files with TarGZ ... FAIL', $tester->getDisplay());
 | 
					        $this->assertContains('Copying files with TarGZ ... FAIL', $tester->getDisplay());
 | 
				
			||||||
        $this->assertNotEquals(0, $tester->getStatusCode());
 | 
					        $this->assertNotEquals(0, $tester->getStatusCode());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testDeploymentWithoutReleasesForceRelease()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $application = new MageApplicationMockup();
 | 
				
			||||||
 | 
					        $application->configure(__DIR__ . '/../../Resources/testhost-force-release.yml');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var AbstractCommand $command */
 | 
				
			||||||
 | 
					        $command = $application->find('deploy');
 | 
				
			||||||
 | 
					        $this->assertTrue($command instanceof DeployCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester = new CommandTester($command);
 | 
				
			||||||
 | 
					        $tester->execute(['command' => $command->getName(), 'environment' => 'test']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
 | 
				
			||||||
 | 
					        $this->assertNotEquals(0, $tester->getStatusCode());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										23
									
								
								src/Mage/Tests/Resources/no-hosts.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/Mage/Tests/Resources/no-hosts.yml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					magephp:
 | 
				
			||||||
 | 
					    log_dir: /tmp
 | 
				
			||||||
 | 
					    environments:
 | 
				
			||||||
 | 
					        test:
 | 
				
			||||||
 | 
					            user: tester
 | 
				
			||||||
 | 
					            branch: test
 | 
				
			||||||
 | 
					            host_path: /var/www/test
 | 
				
			||||||
 | 
					            releases: 4
 | 
				
			||||||
 | 
					            exclude:
 | 
				
			||||||
 | 
					                - ./var/cache/*
 | 
				
			||||||
 | 
					                - ./var/log/*
 | 
				
			||||||
 | 
					                - ./web/app_dev.php
 | 
				
			||||||
 | 
					            pre-deploy:
 | 
				
			||||||
 | 
					                - git/update
 | 
				
			||||||
 | 
					                - composer/install
 | 
				
			||||||
 | 
					                - composer/dump-autoload
 | 
				
			||||||
 | 
					            on-deploy:
 | 
				
			||||||
 | 
					                - symfony/cache-warmup: { env: 'dev' }
 | 
				
			||||||
 | 
					                - symfony/assets-install: { env: 'dev' }
 | 
				
			||||||
 | 
					                - symfony/assetic-dump: { env: 'dev' }
 | 
				
			||||||
 | 
					            on-release:
 | 
				
			||||||
 | 
					            post-release:
 | 
				
			||||||
 | 
					            post-deploy:
 | 
				
			||||||
							
								
								
									
										15
									
								
								src/Mage/Tests/Resources/testhost-force-release.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/Mage/Tests/Resources/testhost-force-release.yml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					magephp:
 | 
				
			||||||
 | 
					    log_dir: /tmp
 | 
				
			||||||
 | 
					    environments:
 | 
				
			||||||
 | 
					        test:
 | 
				
			||||||
 | 
					            user: tester
 | 
				
			||||||
 | 
					            branch: test
 | 
				
			||||||
 | 
					            host_path: /var/www/test
 | 
				
			||||||
 | 
					            exclude:
 | 
				
			||||||
 | 
					                - ./var/cache/*
 | 
				
			||||||
 | 
					                - ./var/log/*
 | 
				
			||||||
 | 
					                - ./web/app_dev.php
 | 
				
			||||||
 | 
					            hosts:
 | 
				
			||||||
 | 
					                - host2
 | 
				
			||||||
 | 
					            on-release:
 | 
				
			||||||
 | 
					                - deploy/release
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user