Skip to content

Commit aaf944e

Browse files
test coverage
1 parent 7e4cfe2 commit aaf944e

File tree

1 file changed

+107
-8
lines changed

1 file changed

+107
-8
lines changed

setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php

Lines changed: 107 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,18 @@
6262
class InstallerTest extends TestCase
6363
{
6464
/**
65-
* @var \Magento\Setup\Model\Installer
65+
* @var array
66+
*/
67+
private $request = [
68+
ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1',
69+
ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento',
70+
ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento',
71+
ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key',
72+
ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend',
73+
];
74+
75+
/**
76+
* @var Installer
6677
*/
6778
private $object;
6879

@@ -426,13 +437,7 @@ public function installDataProvider()
426437
{
427438
return [
428439
[
429-
'request' => [
430-
ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1',
431-
ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento',
432-
ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento',
433-
ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key',
434-
ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend',
435-
],
440+
'request' => $this->request,
436441
'logMessages' => [
437442
['Starting Magento installation:'],
438443
['File permissions check...'],
@@ -526,6 +531,100 @@ public function installDataProvider()
526531
];
527532
}
528533

534+
/**
535+
* Test for InstallDataFixtures
536+
*
537+
* @dataProvider testInstallDataFixturesDataProvider
538+
*
539+
* @param bool $keepCache
540+
* @param array $expectedToEnableCacheTypes
541+
* @return void
542+
*/
543+
public function testInstallDataFixtures(bool $keepCache, array $expectedToEnableCacheTypes): void
544+
{
545+
$cacheManagerMock = $this->createMock(Manager::class);
546+
//simulate disabled layout cache type
547+
$cacheManagerMock->expects($this->atLeastOnce())
548+
->method('getStatus')
549+
->willReturn(['layout' => 0]);
550+
$cacheManagerMock->expects($this->atLeastOnce())
551+
->method('getAvailableTypes')
552+
->willReturn(['block_html', 'full_page', 'layout' , 'config', 'collections']);
553+
$cacheManagerMock->expects($this->exactly(2))
554+
->method('setEnabled')
555+
->withConsecutive([$expectedToEnableCacheTypes, false], [$expectedToEnableCacheTypes, true])
556+
->willReturn([]);
557+
558+
$this->objectManager->expects($this->atLeastOnce())
559+
->method('create')
560+
->willReturnMap([
561+
[Manager::class, [], $cacheManagerMock],
562+
[
563+
PatchApplierFactory::class,
564+
['objectManager' => $this->objectManager],
565+
$this->patchApplierFactoryMock
566+
],
567+
]);
568+
569+
$registryMock = $this->createMock(Registry::class);
570+
$this->objectManager->expects($this->atLeastOnce())
571+
->method('get')
572+
->with(Registry::class)
573+
->willReturn($registryMock);
574+
575+
$this->config->expects($this->atLeastOnce())
576+
->method('get')
577+
->willReturn(true);
578+
579+
$this->filePermissions->expects($this->atLeastOnce())
580+
->method('getMissingWritableDirectoriesForDbUpgrade')
581+
->willReturn([]);
582+
583+
$connection = $this->getMockBuilder(AdapterInterface::class)
584+
->addMethods(['getSchemaListener'])
585+
->getMockForAbstractClass();
586+
$connection->expects($this->once())
587+
->method('getSchemaListener')
588+
->willReturn($this->schemaListenerMock);
589+
590+
$resource = $this->createMock(ResourceConnection::class);
591+
$resource->expects($this->atLeastOnce())
592+
->method('getConnection')
593+
->willReturn($connection);
594+
$this->contextMock->expects($this->once())
595+
->method('getResources')
596+
->willReturn($resource);
597+
598+
$dataSetup = $this->createMock(DataSetup::class);
599+
$dataSetup->expects($this->once())
600+
->method('getConnection')
601+
->willReturn($connection);
602+
603+
$this->dataSetupFactory->expects($this->atLeastOnce())
604+
->method('create')
605+
->willReturn($dataSetup);
606+
607+
$this->object->installDataFixtures($this->request, $keepCache);
608+
}
609+
610+
/**
611+
* DataProvider for testInstallDataFixtures
612+
*
613+
* @return array
614+
*/
615+
public function testInstallDataFixturesDataProvider(): array
616+
{
617+
return [
618+
'keep cache' => [
619+
true, ['block_html', 'full_page']
620+
],
621+
'do not keep a cache' => [
622+
false,
623+
['block_html', 'full_page', 'layout']
624+
],
625+
];
626+
}
627+
529628
public function testCheckInstallationFilePermissions()
530629
{
531630
$this->filePermissions

0 commit comments

Comments
 (0)