<commit_before><?php
namespace ZendServerAPITest;

use ZendServerAPI\Request;

use ZendServerAPI\Deployment;

class DeploymentTest extends \PHPUnit_Framework_TestCase
{

    protected function setUp ()
    {
        
    }
    
    public function testConstructorInjection()
    {
        $deployment = new Deployment("example62");
        $config = $deployment->getRequest()->getConfig();
        $request = new Request();
        $request->setConfig($config);
        $deployment->setRequest($request);
        
        $this->assertSame($request, $deployment->getRequest());
        $this->assertInstanceOf('\ZendServerAPI\Config', $deployment->getRequest()->getConfig());
        $this->assertInstanceOf('\ZendServerAPI\ApiKey', $deployment->getRequest()->getConfig()->getApiKey());
    }
    
    public function testApplicationGetStatus()
    {
        $responseStub = $this->getMock('\Guzzle\Http\Message\Response', array('getBody'), array(200));
        require_once 'ZendServerAPITest/Method/ApplicationGetStatusTest.php';
        $responseStub->expects($this->once())->method('getBody')->will($this->returnValue(ApplicationGetStatusTest::getResponse()));
        
        $clientStub = $this->getMock('\Guzzle\Http\Client', array('send'));
        $clientStub->expects($this->once())->method('send')->will($this->returnValue($responseStub));
        
        $deployment = new \ZendServerAPI\Deployment();
        $deployment->setClient($clientStub);
        $result = $deployment->applicationGetStatus(array(1,2));
        $this->assertInstanceOf('\ZendServerAPI\DataTypes\ApplicationList', $result);
    }

    public function testApplicationGetStatusAgainstProduction()
    {
        try {
            $deployment = new \ZendServerAPI\Deployment("example62");
            $deploymentStatus = $deployment->applicationGetStatus();
        } catch(\Exception $e) {
            $this->markTestSkipped();
        }
        
        $this->assertInstanceOf('\ZendServerAPI\DataTypes\ApplicationList', $deploymentStatus);
    }
    
    public function testApplicationDeploy()
    {
        $deployment = new \ZendServerAPI\Deployment("example62");
        if(!$deployment->canConnect())
            $this->markTestSkipped();
        
        $apps = $deployment->applicationGetStatus();
        foreach($apps->getApplicationInfos() as $applicationInfo)
        {
            $deployment->applicationRemove($applicationInfo->getId());
        }
        
        $deploy = $deployment->applicationDeploy(
                __DIR__.'/../_files/example2.zpk', 
                "http://test2.com", 
                true, 
                false, 
                'Simple test app', 
                false, 
                array(
                    'locale' => 'GMT',
                    'db_host' => 'localhost'        
                )
        );
        $deployment->waitForStableState($deploy->getId());
        $this->assertInstanceOf('\ZendServerAPI\DataTypes\ApplicationInfo', $deploy);
        $deployment->applicationRemove($deploy->getId());
        $deployment->waitForRemoved($deploy->getId());
            
    }
    
    public function testWaitForMethods()
    {
        $deployment = new \ZendServerAPI\Deployment("example62");
        if(!$deployment->canConnect())
            $this->markTestSkipped();
        
        $deploy = $deployment->applicationDeploy(
                __DIR__.'/../_files/example2.zpk',
                "http://testwait.com",
                true,
                false,
                'Simple test app for waiting function',
                false,
                array(
                        'locale' => 'GMT',
                        'db_host' => 'localhost'
                )
        );
        $result = $deployment->waitForStableState($deploy->getId());
        
        $this->assertEquals("deployed", $result->getStatus());
        $deployment->applicationRemove($result->getId());
        $retVal = $deployment->waitForRemoved($result->getId());
        $this->assertTrue($retVal);
    }
    
    public function testUpdateAndRollback()
    {
        $deployment = new \ZendServerAPI\Deployment("example62");
        if(!$deployment->canConnect())
            $this->markTestSkipped();
        
        $deploy = $deployment->applicationDeploy(
                __DIR__.'/../_files/example1.zpk',
                "http://test.com",
                true,
                false,
                'Simple test app',
                false,
                array(
                        'locale' => 'GMT',
                        'db_host' => 'localhost'
                )
        );
        $result = $deployment->waitForStableState($deploy->getId());
        
        $app = $deployment->applicationUpdate($result->getId(), __DIR__.'/../_files/example1-2.zpk');
        $app = $deployment->waitForStableState($app->getId());
        
        $deployedVersions = $app->getDeployedVersions();
        $deployedVersion = new \ZendServerAPI\DataTypes\DeployedVersions();
        $deployedVersion->setVersion("0.2");
        $this->assertEquals($deployedVersions[0], $deployedVersion);
        
        $app = $deployment->applicationRollback($app->getId());
        $app = $deployment->waitForStableState($app->getId());
        
        $deployedVersions = $app->getDeployedVersions();
        $deployedVersion = new \ZendServerAPI\DataTypes\DeployedVersions();
        $deployedVersion->setVersion("0.1");
        $this->assertEquals($deployedVersions[0], $deployedVersion);
        
    }
    
    public function testSynchronize()
    {
        $deployment = new \ZendServerAPI\Deployment("example62");
        $applications = $deployment->applicationGetStatus();
        $applicationList = $applications->getApplicationInfos();
        $applicationInfo = $applicationList[0];
        $applicationInfo = $deployment->applicationSynchronize($applicationInfo->getId(), array(0));<commit_msg>added missing skip if zendserver is not available<commit_after><?php
namespace ZendServerAPITest;

use ZendServerAPI\Request;

use ZendServerAPI\Deployment;

class DeploymentTest extends \PHPUnit_Framework_TestCase
{

    protected function setUp ()
    {
        
    }
    
    public function testConstructorInjection()
    {
        $deployment = new Deployment("example62");
        $config = $deployment->getRequest()->getConfig();
        $request = new Request();
        $request->setConfig($config);
        $deployment->setRequest($request);
        
        $this->assertSame($request, $deployment->getRequest());
        $this->assertInstanceOf('\ZendServerAPI\Config', $deployment->getRequest()->getConfig());
        $this->assertInstanceOf('\ZendServerAPI\ApiKey', $deployment->getRequest()->getConfig()->getApiKey());
    }
    
    public function testApplicationGetStatus()
    {
        $responseStub = $this->getMock('\Guzzle\Http\Message\Response', array('getBody'), array(200));
        require_once 'ZendServerAPITest/Method/ApplicationGetStatusTest.php';
        $responseStub->expects($this->once())->method('getBody')->will($this->returnValue(ApplicationGetStatusTest::getResponse()));
        
        $clientStub = $this->getMock('\Guzzle\Http\Client', array('send'));
        $clientStub->expects($this->once())->method('send')->will($this->returnValue($responseStub));
        
        $deployment = new \ZendServerAPI\Deployment();
        $deployment->setClient($clientStub);
        $result = $deployment->applicationGetStatus(array(1,2));
        $this->assertInstanceOf('\ZendServerAPI\DataTypes\ApplicationList', $result);
    }

    public function testApplicationGetStatusAgainstProduction()
    {
        try {
            $deployment = new \ZendServerAPI\Deployment("example62");
            $deploymentStatus = $deployment->applicationGetStatus();
        } catch(\Exception $e) {
            $this->markTestSkipped();
        }
        
        $this->assertInstanceOf('\ZendServerAPI\DataTypes\ApplicationList', $deploymentStatus);
    }
    
    public function testApplicationDeploy()
    {
        $deployment = new \ZendServerAPI\Deployment("example62");
        if(!$deployment->canConnect())
            $this->markTestSkipped();
        
        $apps = $deployment->applicationGetStatus();
        foreach($apps->getApplicationInfos() as $applicationInfo)
        {
            $deployment->applicationRemove($applicationInfo->getId());
        }
        
        $deploy = $deployment->applicationDeploy(
                __DIR__.'/../_files/example2.zpk', 
                "http://test2.com", 
                true, 
                false, 
                'Simple test app', 
                false, 
                array(
                    'locale' => 'GMT',
                    'db_host' => 'localhost'        
                )
        );
        $deployment->waitForStableState($deploy->getId());
        $this->assertInstanceOf('\ZendServerAPI\DataTypes\ApplicationInfo', $deploy);
        $deployment->applicationRemove($deploy->getId());
        $deployment->waitForRemoved($deploy->getId());
            
    }
    
    public function testWaitForMethods()
    {
        $deployment = new \ZendServerAPI\Deployment("example62");
        if(!$deployment->canConnect())
            $this->markTestSkipped();
        
        $deploy = $deployment->applicationDeploy(
                __DIR__.'/../_files/example2.zpk',
                "http://testwait.com",
                true,
                false,
                'Simple test app for waiting function',
                false,
                array(
                        'locale' => 'GMT',
                        'db_host' => 'localhost'
                )
        );
        $result = $deployment->waitForStableState($deploy->getId());
        
        $this->assertEquals("deployed", $result->getStatus());
        $deployment->applicationRemove($result->getId());
        $retVal = $deployment->waitForRemoved($result->getId());
        $this->assertTrue($retVal);
    }
    
    public function testUpdateAndRollback()
    {
        $deployment = new \ZendServerAPI\Deployment("example62");
        if(!$deployment->canConnect())
            $this->markTestSkipped();
        
        $deploy = $deployment->applicationDeploy(
                __DIR__.'/../_files/example1.zpk',
                "http://test.com",
                true,
                false,
                'Simple test app',
                false,
                array(
                        'locale' => 'GMT',
                        'db_host' => 'localhost'
                )
        );
        $result = $deployment->waitForStableState($deploy->getId());
        
        $app = $deployment->applicationUpdate($result->getId(), __DIR__.'/../_files/example1-2.zpk');
        $app = $deployment->waitForStableState($app->getId());
        
        $deployedVersions = $app->getDeployedVersions();
        $deployedVersion = new \ZendServerAPI\DataTypes\DeployedVersions();
        $deployedVersion->setVersion("0.2");
        $this->assertEquals($deployedVersions[0], $deployedVersion);
        
        $app = $deployment->applicationRollback($app->getId());
        $app = $deployment->waitForStableState($app->getId());
        
        $deployedVersions = $app->getDeployedVersions();
        $deployedVersion = new \ZendServerAPI\DataTypes\DeployedVersions();
        $deployedVersion->setVersion("0.1");
        $this->assertEquals($deployedVersions[0], $deployedVersion);
        
    }
    
    public function testSynchronize()
    {
        $deployment = new \ZendServerAPI\Deployment("example62");
        if(!$deployment->canConnect())
            $this->markTestSkipped();
        
        $applications = $deployment->applicationGetStatus();
        $applicationList = $applications->getApplicationInfos();
        $applicationInfo = $applicationList[0];
        $applicationInfo = $deployment->applicationSynchronize($applicationInfo->getId(), array(0));
{'fraction_non_alphanumeric': 0.14409461935698817, 'fraction_numerical': 0.005164084624354489, 'mean_word_length': 2.2302932472424, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 177, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2128808', 'n_tokens_mistral': 3277, 'n_tokens_neox': 3225, 'n_words': 412}