1
0
Fork 0

Introduce Arguments / Module class

- move from App
- add tests for Arguments/Module class
This commit is contained in:
Philipp Holzer 2019-08-11 14:24:05 +02:00
commit 2c5ba7fc15
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
12 changed files with 1080 additions and 358 deletions

View file

@ -38,22 +38,20 @@ class ModeTest extends MockedTest
$this->setUpVfsDir();
$this->basePathMock = \Mockery::mock(BasePath::class);
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$this->databaseMock = \Mockery::mock(Database::class);
$this->configCacheMock = \Mockery::mock(Config\Cache\ConfigCache::class);
}
public function testItEmpty()
{
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$mode = new Mode();
$this->assertTrue($mode->isInstall());
$this->assertFalse($mode->isNormal());
}
public function testWithoutConfig()
{
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$this->assertTrue($this->root->hasChild('config/local.config.php'));
@ -61,7 +59,7 @@ class ModeTest extends MockedTest
$this->assertFalse($this->root->hasChild('config/local.config.php'));
$mode->determine();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$this->assertTrue($mode->isInstall());
$this->assertFalse($mode->isNormal());
@ -71,10 +69,11 @@ class ModeTest extends MockedTest
public function testWithoutDatabase()
{
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$this->databaseMock->shouldReceive('connected')->andReturn(false)->once();
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$mode->determine();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$this->assertFalse($mode->isNormal());
$this->assertTrue($mode->isInstall());
@ -85,12 +84,13 @@ class ModeTest extends MockedTest
public function testWithoutDatabaseSetup()
{
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
$this->databaseMock->shouldReceive('fetchFirst')
->with('SHOW TABLES LIKE \'config\'')->andReturn(false)->once();
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$mode->determine();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$this->assertFalse($mode->isNormal());
$this->assertTrue($mode->isInstall());
@ -100,14 +100,15 @@ class ModeTest extends MockedTest
public function testWithMaintenanceMode()
{
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
$this->databaseMock->shouldReceive('fetchFirst')
->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once();
$this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
->andReturn(true)->once();
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$mode->determine();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$this->assertFalse($mode->isNormal());
$this->assertFalse($mode->isInstall());
@ -118,6 +119,8 @@ class ModeTest extends MockedTest
public function testNormalMode()
{
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
$this->databaseMock->shouldReceive('fetchFirst')
->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once();
@ -127,8 +130,7 @@ class ModeTest extends MockedTest
->with('config', ['v'], ['cat' => 'system', 'k' => 'maintenance'])
->andReturn(['v' => null])->once();
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$mode->determine();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$this->assertTrue($mode->isNormal());
$this->assertFalse($mode->isInstall());
@ -142,6 +144,8 @@ class ModeTest extends MockedTest
*/
public function testDisabledMaintenance()
{
$this->basePathMock->shouldReceive('getPath')->andReturn($this->root->url())->once();
$this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
$this->databaseMock->shouldReceive('fetchFirst')
->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once();
@ -151,8 +155,7 @@ class ModeTest extends MockedTest
->with('config', ['v'], ['cat' => 'system', 'k' => 'maintenance'])
->andReturn(['v' => '0'])->once();
$mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$mode->determine();
$mode = (new Mode())->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$this->assertTrue($mode->isNormal());
$this->assertFalse($mode->isInstall());
@ -160,4 +163,18 @@ class ModeTest extends MockedTest
$this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
$this->assertTrue($mode->has(Mode::MAINTENANCEDISABLED));
}
/**
* Test that modes are immutable
*/
public function testImmutable()
{
$this->basePathMock->shouldReceive('getPath')->andReturn(null)->once();
$mode = new Mode();
$modeNew = $mode->determine($this->basePathMock, $this->databaseMock, $this->configCacheMock);
$this->assertNotSame($modeNew, $mode);
}
}