Files
Phraseanet/tests/Alchemy/Tests/Phrasea/Command/Setup/InstallTest.php
2018-03-01 17:41:08 +04:00

105 lines
3.8 KiB
PHP

<?php
namespace Alchemy\Tests\Phrasea\Command\Setup;
use Alchemy\Phrasea\Command\Setup\Install;
use Symfony\Component\Yaml\Yaml;
use Alchemy\Phrasea\Core\Configuration\StructureTemplate;
/**
* @group functional
* @group legacy
*/
class InstallTest extends \PhraseanetTestCase
{
public function testRunWithoutProblems()
{
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$email = 'jean@dupont.io';
$password = 'sup4ssw0rd';
$serverName = 'http://phrasea.io';
$dataPath = '/tmp';
$template = 'fr-simple';
$infoDb = Yaml::parse(file_get_contents(__DIR__ . '/../../../../../../resources/hudson/InstallDBs.yml'));
$helperSet = $this->getMockBuilder('Symfony\Component\Console\Helper\HelperSet')
->disableOriginalConstructor()
->getMock();
$dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
->disableOriginalConstructor()
->getMock();
$helperSet->expects($this->once())
->method('get')
->with('dialog')
->will($this->returnValue($dialog));
$input->expects($this->any())
->method('getOption')
->will($this->returnCallback(function ($option) use ($infoDb, $template, $email, $password, $serverName, $dataPath) {
switch ($option) {
case 'appbox':
return $infoDb['database']['ab_name'];
break;
case 'databox':
return $infoDb['database']['db_name'];
break;
case 'db-template':
return $template;
break;
case 'email':
return $email;
break;
case 'password':
return $password;
break;
case 'data-path':
return $dataPath;
break;
case 'server-name':
return $serverName;
break;
case 'yes':
return true;
break;
case 'db-host':
return $infoDb['database']['host'];
break;
case 'db-port':
return $infoDb['database']['port'];
break;
case 'db-user':
return $infoDb['database']['user'];
break;
case 'db-password':
return $infoDb['database']['password'];
break;
case 'yes':
return true;
break;
default:
return '';
}
}));
self::$DI['cli']['phraseanet.installer'] = $this->getMockBuilder('Alchemy\Phrasea\Setup\Installer')
->disableOriginalConstructor()
->getMock();
self::$DI['cli']['phraseanet.installer']->expects($this->once())
->method('install')
->with($email, $password, $this->isInstanceOf('Doctrine\DBAL\Driver\Connection'), $serverName, $dataPath, $this->isInstanceOf('Doctrine\DBAL\Driver\Connection'), $template, $this->anything());
$structureTemplate = self::$DI['cli']['phraseanet.structure-template'];
$command = new Install('system:check', $structureTemplate);
$command->setHelperSet($helperSet);
$command->setContainer(self::$DI['cli']);
$this->assertEquals(0, $command->execute($input, $output));
}
}