Fixed ConsoleTest

This commit is contained in:
Philipp Holzer 2019-03-11 22:46:00 +01:00 committed by Hypolite Petovan
parent f4ec7c47b9
commit acd5060ec2
3 changed files with 59 additions and 2 deletions

View File

@ -30,6 +30,11 @@ trait AppMockTrait
*/ */
protected $profilerMock; protected $profilerMock;
/**
* @var MockInterface|App\Mode The mocked App mode
*/
protected $mode;
/** /**
* Mock the App * Mock the App
* *
@ -38,6 +43,7 @@ trait AppMockTrait
public function mockApp($root) public function mockApp($root)
{ {
$this->configMock = \Mockery::mock(Config\Cache\IConfigCache::class); $this->configMock = \Mockery::mock(Config\Cache\IConfigCache::class);
$this->mode = \Mockery::mock(App\Mode::class);
$configAdapterMock = \Mockery::mock(Config\Adapter\IConfigAdapter::class); $configAdapterMock = \Mockery::mock(Config\Adapter\IConfigAdapter::class);
// Disable the adapter // Disable the adapter
$configAdapterMock->shouldReceive('isConnected')->andReturn(false); $configAdapterMock->shouldReceive('isConnected')->andReturn(false);
@ -52,6 +58,10 @@ trait AppMockTrait
->shouldReceive('getBasePath') ->shouldReceive('getBasePath')
->andReturn($root->url()); ->andReturn($root->url());
$this->app
->shouldReceive('getMode')
->andReturn($this->mode);
$this->configMock $this->configMock
->shouldReceive('has') ->shouldReceive('has')
->andReturn(true); ->andReturn(true);

View File

@ -3,6 +3,7 @@
namespace Friendica\Test\src\Core\Console; namespace Friendica\Test\src\Core\Console;
use Friendica\Core\Console\AutomaticInstallation; use Friendica\Core\Console\AutomaticInstallation;
use Friendica\Core\Installer;
use Friendica\Test\Util\DBAMockTrait; use Friendica\Test\Util\DBAMockTrait;
use Friendica\Test\Util\DBStructureMockTrait; use Friendica\Test\Util\DBStructureMockTrait;
use Friendica\Test\Util\L10nMockTrait; use Friendica\Test\Util\L10nMockTrait;
@ -55,6 +56,19 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
$this->configMock $this->configMock
->shouldReceive('get') ->shouldReceive('get')
->with('config', 'php_path') ->with('config', 'php_path')
->andReturn(null);
$this->configMock->shouldReceive('set')
->with('config', 'php_path', \Mockery::any())->once();
$this->configMock->shouldReceive('set')
->with('config', 'hostname', '')->once();
$this->configMock->shouldReceive('set')
->with('system', 'basepath', \Mockery::any())->once();
$this->configMock->shouldReceive('set')
->with('system', 'urlpath' , '')->once();
$this->configMock->shouldReceive('set')
->with('system', 'ssl_policy', SSL_POLICY_NONE)->once();
$this->mode->shouldReceive('isInstall')
->andReturn(false); ->andReturn(false);
$this->mockL10nT(); $this->mockL10nT();
@ -75,9 +89,11 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
'$dbuser' => (($withDb) ? $this->db_user : ''), '$dbuser' => (($withDb) ? $this->db_user : ''),
'$dbpass' => (($withDb) ? $this->db_pass : ''), '$dbpass' => (($withDb) ? $this->db_pass : ''),
'$dbdata' => (($withDb) ? $this->db_data : ''), '$dbdata' => (($withDb) ? $this->db_data : ''),
'$timezone' => 'Europe/Berlin', '$timezone' => Installer::DEFAULT_TZ,
'$language' => 'de', '$language' => Installer::DEFAULT_LANG,
'$urlpath' => '/friendica', '$urlpath' => '/friendica',
'$basepath' => '/test',
'$hostname' => 'friendica.local',
'$adminmail' => 'admin@friendica.local' '$adminmail' => 'admin@friendica.local'
]; ];
@ -176,6 +192,36 @@ FIN;
$this->assertEquals($finished, $txt); $this->assertEquals($finished, $txt);
} }
/**
* Test the automatic installation without any parameter
*/
public function testEmpty()
{
$this->mockConnect(true, 1);
$this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1);
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
$this->configMock->shouldReceive('set')
->with('database', 'hostname', Installer::DEFAULT_HOST)->once();
$this->configMock->shouldReceive('set')
->with('database', 'username', '')->once();
$this->configMock->shouldReceive('set')
->with('database', 'password', '')->once();
$this->configMock->shouldReceive('set')
->with('database', 'database', '')->once();
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
$console = new AutomaticInstallation($this->consoleArgv);
$txt = $this->dumpExecute($console);
$this->assertFinished($txt, false, true);
}
/** /**
* @medium * @medium
*/ */

View File

@ -30,6 +30,7 @@ abstract class ConsoleTest extends MockedTest
$this->setUpVfsDir(); $this->setUpVfsDir();
$this->mockApp($this->root); $this->mockApp($this->root);
} }
/** /**