|
| 1 | +<?php |
| 2 | + |
| 3 | +namespaceAutomate\Tests\Context; |
| 4 | + |
| 5 | +useAutomate\Context\ContextInterface; |
| 6 | +useAutomate\Logger\ConsoleLogger; |
| 7 | +useAutomate\Model\Server; |
| 8 | +useAutomate\Session\SSHSession; |
| 9 | +useAutomate\Tests\AbstractContextTest; |
| 10 | +usePhake; |
| 11 | +usephpseclib\Net\SSH2; |
| 12 | + |
| 13 | +class ContextTestextends AbstractContextTest |
| 14 | +{ |
| 15 | +publicfunctiontestSimpleContext() |
| 16 | + { |
| 17 | +$logger = Phake::mock(ConsoleLogger::class); |
| 18 | + |
| 19 | +$ssh = Phake::mock(SSH2::class); |
| 20 | + Phake::when($ssh)->getExitStatus()->thenReturn(1); |
| 21 | + |
| 22 | +$session =newSSHSession($ssh); |
| 23 | +$context =$this->createContext($session,$logger); |
| 24 | + |
| 25 | +$server =$this->getServerFromContext($context); |
| 26 | + |
| 27 | +$this->assertEquals('/home/wwwroot/automate/demo/shared',$context->getSharedPath($server)); |
| 28 | + } |
| 29 | + |
| 30 | +publicfunctiontestSimpleWithSharedPathContext() |
| 31 | + { |
| 32 | +$logger = Phake::mock(ConsoleLogger::class); |
| 33 | + |
| 34 | +$ssh = Phake::mock(SSH2::class); |
| 35 | + Phake::when($ssh)->getExitStatus()->thenReturn(1); |
| 36 | + |
| 37 | +$session =newSSHSession($ssh); |
| 38 | +$context =$this->createContextWithServerSharedPath($session,$logger); |
| 39 | + |
| 40 | +$server =$this->getServerFromContext($context); |
| 41 | + |
| 42 | +$this->assertEquals('/home/wwwroot/shared',$context->getSharedPath($server)); |
| 43 | + } |
| 44 | + |
| 45 | +/** |
| 46 | + * @param ContextInterface $context |
| 47 | + * |
| 48 | + * @return Server |
| 49 | + */ |
| 50 | +privatefunctiongetServerFromContext(ContextInterface$context) |
| 51 | + { |
| 52 | +$project =$context->getProject(); |
| 53 | + |
| 54 | +$platform =$project->getPlatform('development'); |
| 55 | + |
| 56 | +/** @var Server $server */ |
| 57 | +$server =current($platform->getServers()); |
| 58 | + |
| 59 | +return$server; |
| 60 | + } |
| 61 | +} |