mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	[Nostromo] Improve tests.
This commit is contained in:
		
							parent
							
								
									89e780a0bf
								
							
						
					
					
						commit
						5bff78e1cd
					
				@ -97,4 +97,61 @@ class DeployCommandMiscTasksTest extends TestCase
 | 
				
			|||||||
        $this->assertEquals(7, $tester->getStatusCode());
 | 
					        $this->assertEquals(7, $tester->getStatusCode());
 | 
				
			||||||
        $this->assertContains('Invalid task name "invalid/task"', $tester->getDisplay());
 | 
					        $this->assertContains('Invalid task name "invalid/task"', $tester->getDisplay());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testBrokenGitBranch()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $application = new MageApplicationMockup();
 | 
				
			||||||
 | 
					        $application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var AbstractCommand $command */
 | 
				
			||||||
 | 
					        $command = $application->find('deploy');
 | 
				
			||||||
 | 
					        $this->assertTrue($command instanceof DeployCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester = new CommandTester($command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $application->getRuntime()->forceFail('git branch | grep "*"');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester->execute(['command' => $command->getName(), 'environment' => 'test']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
 | 
				
			||||||
 | 
					        $this->assertNotEquals(0, $tester->getStatusCode());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testBrokenGitCheckout()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $application = new MageApplicationMockup();
 | 
				
			||||||
 | 
					        $application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var AbstractCommand $command */
 | 
				
			||||||
 | 
					        $command = $application->find('deploy');
 | 
				
			||||||
 | 
					        $this->assertTrue($command instanceof DeployCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester = new CommandTester($command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $application->getRuntime()->forceFail('git checkout broken-test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester->execute(['command' => $command->getName(), 'environment' => 'test']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
 | 
				
			||||||
 | 
					        $this->assertNotEquals(0, $tester->getStatusCode());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testBrokenGitUpdate()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $application = new MageApplicationMockup();
 | 
				
			||||||
 | 
					        $application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var AbstractCommand $command */
 | 
				
			||||||
 | 
					        $command = $application->find('deploy');
 | 
				
			||||||
 | 
					        $this->assertTrue($command instanceof DeployCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester = new CommandTester($command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $application->getRuntime()->forceFail('git pull');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester->execute(['command' => $command->getName(), 'environment' => 'test']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('Running [Git] Update ... FAIL', $tester->getDisplay());
 | 
				
			||||||
 | 
					        $this->assertNotEquals(0, $tester->getStatusCode());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										15
									
								
								src/Mage/Tests/Resources/broken-git-branch.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/Mage/Tests/Resources/broken-git-branch.yml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					magephp:
 | 
				
			||||||
 | 
					    log_dir: /tmp
 | 
				
			||||||
 | 
					    environments:
 | 
				
			||||||
 | 
					        test:
 | 
				
			||||||
 | 
					            user: tester
 | 
				
			||||||
 | 
					            branch: broken-test
 | 
				
			||||||
 | 
					            host_path: /var/www/test
 | 
				
			||||||
 | 
					            exclude:
 | 
				
			||||||
 | 
					                - ./var/cache/*
 | 
				
			||||||
 | 
					                - ./var/log/*
 | 
				
			||||||
 | 
					                - ./web/app_dev.php
 | 
				
			||||||
 | 
					            hosts:
 | 
				
			||||||
 | 
					                - githost1
 | 
				
			||||||
 | 
					            pre-deploy:
 | 
				
			||||||
 | 
					                - git/update
 | 
				
			||||||
@ -14,6 +14,7 @@ use Symfony\Component\Process\Process;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class ProcessMockup extends Process
 | 
					class ProcessMockup extends Process
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    public $forceFail = [];
 | 
				
			||||||
    protected $commandline;
 | 
					    protected $commandline;
 | 
				
			||||||
    protected $timeout;
 | 
					    protected $timeout;
 | 
				
			||||||
    protected $success = true;
 | 
					    protected $success = true;
 | 
				
			||||||
@ -30,6 +31,10 @@ class ProcessMockup extends Process
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function run($callback = null)
 | 
					    public function run($callback = null)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        if (in_array($this->commandline, $this->forceFail)) {
 | 
				
			||||||
 | 
					            $this->success = false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@host1 sh -c \"readlink -f /var/www/test/current\"') {
 | 
					        if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@host1 sh -c \"readlink -f /var/www/test/current\"') {
 | 
				
			||||||
            $this->success = false;
 | 
					            $this->success = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -16,6 +16,7 @@ use Symfony\Component\Process\Process;
 | 
				
			|||||||
class RuntimeMockup extends Runtime
 | 
					class RuntimeMockup extends Runtime
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    protected $ranCommands = [];
 | 
					    protected $ranCommands = [];
 | 
				
			||||||
 | 
					    protected $forceFail = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getRanCommands()
 | 
					    public function getRanCommands()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -45,6 +46,7 @@ class RuntimeMockup extends Runtime
 | 
				
			|||||||
        $this->ranCommands[] = $cmd;
 | 
					        $this->ranCommands[] = $cmd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $process = new ProcessMockup($cmd);
 | 
					        $process = new ProcessMockup($cmd);
 | 
				
			||||||
 | 
					        $process->forceFail = $this->forceFail;
 | 
				
			||||||
        $process->setTimeout($timeout);
 | 
					        $process->setTimeout($timeout);
 | 
				
			||||||
        $process->run();
 | 
					        $process->run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -72,4 +74,9 @@ class RuntimeMockup extends Runtime
 | 
				
			|||||||
        $this->environment = $environment;
 | 
					        $this->environment = $environment;
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function forceFail($cmd)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->forceFail[] = $cmd;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user