Skip to content

Commit

Permalink
SDK-2870: Use new structure of test data provider (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroKlymanSpryker committed Jul 6, 2023
1 parent d236c5f commit 6e0c515
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 184 deletions.
5 changes: 4 additions & 1 deletion src/IntegratorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ final protected function __construct()
*/
public static function getInstance()
{
if (static::$instance === null) {
if (
static::$instance === null ||
(defined('TEST_INTEGRATOR_MODE') && TEST_INTEGRATOR_MODE === 'true')
) {
static::$instance = new static();
static::$instance->loadConfig();
}
Expand Down
8 changes: 1 addition & 7 deletions src/Manifest/RepositoryRepositoryManifestReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

class RepositoryRepositoryManifestReader implements RepositoryManifestReaderInterface
{
/**
* @var string
*/
public const ARCHIVE_DIR = 'integrator-manifests-master/';

/**
* @var \SprykerSdk\Integrator\IntegratorConfig
*/
Expand Down Expand Up @@ -192,9 +187,8 @@ protected function getModuleManifestsDir(
}

$moduleManifestsDir = sprintf(
'%s%s%s/%s/',
'%s%s/%s/',
$this->config->getManifestsDirectory(),
static::ARCHIVE_DIR,
$organization,
$moduleName,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function apply(array $manifest, string $moduleName, InputOutputInterface
$classInformationTransfer = $this->createClassBuilderFacade()->unwireGlueRelationship(
$classInformationTransfer,
static::TARGET_METHOD_NAME,
$targetClassKey,
(string)$targetClassKey,
$targetClass,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function apply(array $manifest, string $moduleName, InputOutputInterface
$classInformationTransfer = $this->createClassBuilderFacade()->wireGlueRelationship(
$classInformationTransfer,
static::TARGET_METHOD_NAME,
$targetClassKey,
(string)$targetClassKey,
$targetClass,
);

Expand Down
143 changes: 143 additions & 0 deletions tests/SprykerSdkTest/Integrator/AbstractIntegratorTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

declare(strict_types=1);

namespace SprykerSdkTest\Integrator;

use SprykerSdk\Integrator\IntegratorFacade;
use Symfony\Component\Filesystem\Filesystem;

abstract class AbstractIntegratorTestCase extends BaseTestCase
{
/**
* @var string
*/
protected const MANIFESTS_DIR_PATH = '';

/**
* @var string
*/
protected const ZIP_PATH = '';

/**
* @return void
*/
protected function setUp(): void
{
$this->prepareTestEnv();
}

/**
* @return void
*/
protected function tearDown(): void
{
$this->clearTestEnv();
}

/**
* @return void
*/
public static function setUpBeforeClass(): void
{
$zipPath = ROOT_TESTS . DIRECTORY_SEPARATOR . static::ZIP_PATH;
$dirPath = DATA_PROVIDER_DIR . DIRECTORY_SEPARATOR . static::MANIFESTS_DIR_PATH;

static::zipDir($dirPath, $zipPath);
}

/**
* @return void
*/
public static function tearDownAfterClass(): void
{
$fs = new Filesystem();
$zipPath = ROOT_TESTS . DIRECTORY_SEPARATOR . static::ZIP_PATH;
$fs->remove($zipPath);
}

/**
* @return \SprykerSdk\Integrator\Business\IntegratorFacade
*/
protected function createIntegratorFacade(): IntegratorFacade
{
return new IntegratorFacade();
}

/**
* @return void
*/
private function removeTmpDirectory(): void
{
$fileSystem = $this->createFilesystem();
$tmpPath = $this->getTempDirectoryPath();

if ($fileSystem->exists($tmpPath)) {
$fileSystem->remove($tmpPath);
}
}

/**
* @return void
*/
private function createTmpDirectory(): void
{
$fileSystem = $this->createFilesystem();
$tmpPath = $this->getTempDirectoryPath();

if (!$fileSystem->exists($tmpPath)) {
$fileSystem->mkdir($tmpPath, 0700);
}
}

/**
* @return void
*/
private function createTmpStandaloneModulesDirectory(): void
{
$fileSystem = $this->createFilesystem();
$path = $this->getTempStandaloneModulesDirectoryPath();

if (!$fileSystem->exists($path)) {
$fileSystem->mkdir($path, 0700);
}
}

/**
* @return void
*/
protected function copyProjectMockToTmpDirectory(): void
{
$fileSystem = $this->createFilesystem();
$tmpPath = $this->getTempDirectoryPath();
$projectMockPath = $this->getProjectMockOriginalPath();

if ($fileSystem->exists($this->getTempDirectoryPath())) {
$fileSystem->mirror($projectMockPath, $tmpPath);
}
}

/**
* @return void
*/
private function prepareTestEnv(): void
{
$this->removeTmpDirectory();
$this->createTmpDirectory();
$this->createTmpStandaloneModulesDirectory();
$this->copyProjectMockToTmpDirectory();
}

/**
* @return void
*/
private function clearTestEnv(): void
{
$this->removeTmpDirectory();
}
}
36 changes: 13 additions & 23 deletions tests/SprykerSdkTest/Integrator/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use RecursiveIteratorIterator;
use SprykerSdk\Integrator\Dependency\Console\InputOutputInterface;
use SprykerSdk\Integrator\Dependency\Console\SymfonyConsoleInputOutputAdapter;
use SprykerSdk\Integrator\IntegratorConfig;
use SprykerSdk\Integrator\IntegratorFactoryAwareTrait;
use SprykerSdk\Integrator\Manifest\RepositoryRepositoryManifestReader;
use SprykerSdk\Integrator\Transfer\ClassInformationTransfer;
use SprykerSdk\Integrator\Transfer\IntegratorCommandArgumentsTransfer;
use SprykerSdk\Integrator\Transfer\ModuleTransfer;
Expand All @@ -33,70 +31,62 @@
use Symfony\Component\Filesystem\Filesystem;
use ZipArchive;

class BaseTestCase extends PHPUnitTestCase
abstract class BaseTestCase extends PHPUnitTestCase
{
use IntegratorFactoryAwareTrait;

/**
* @return \SprykerSdk\Integrator\IntegratorConfig
*/
public function getIntegratorConfig(): IntegratorConfig
{
return IntegratorConfig::getInstance();
}

/**
* @return \Symfony\Component\Filesystem\Filesystem
*/
public function createFilesystem(): Filesystem
protected function createFilesystem(): Filesystem
{
return new Filesystem();
}

/**
* @return string
*/
public function getTempDirectoryPath(): string
protected function getTempDirectoryPath(): string
{
return APPLICATION_ROOT_DIR;
}

/**
* @return string
*/
public function getTempStandaloneModulesDirectoryPath(): string
protected function getTempStandaloneModulesDirectoryPath(): string
{
return APPLICATION_STANDALONE_MODULES_DIR;
}

/**
* @return string
*/
public function getDataDirectoryPath(): string
protected function getDataDirectoryPath(): string
{
return DATA_PROVIDER_DIR;
}

/**
* @return string
*/
public function getProjectMockOriginalPath(): string
protected function getProjectMockOriginalPath(): string
{
return $this->getDataDirectoryPath() . DIRECTORY_SEPARATOR . 'project_original';
return $this->getDataDirectoryPath() . DIRECTORY_SEPARATOR . 'integrator' . DIRECTORY_SEPARATOR . 'project_original';
}

/**
* @return string
*/
public function getProjectMockCurrentPath(): string
protected function getProjectMockCurrentPath(): string
{
return $this->getDataDirectoryPath() . DIRECTORY_SEPARATOR . 'project_current';
return $this->getDataDirectoryPath() . DIRECTORY_SEPARATOR . 'integrator' . DIRECTORY_SEPARATOR . 'project_current';
}

/**
* @return string
*/
public function getTestTmpDirPath(): string
protected function getTestTmpDirPath(): string
{
return ROOT_TESTS . DIRECTORY_SEPARATOR . 'tmp';
}
Expand All @@ -107,7 +97,7 @@ public function getTestTmpDirPath(): string
*
* @return void
*/
public static function zipDir(string $dirPath, string $zipPath): void
protected static function zipDir(string $dirPath, string $zipPath): void
{
$zip = new ZipArchive();
$zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE);
Expand All @@ -122,7 +112,7 @@ public static function zipDir(string $dirPath, string $zipPath): void
// Skip directories (they would be added automatically)
if (!$file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strpos($filePath, RepositoryRepositoryManifestReader::ARCHIVE_DIR));
$relativePath = substr($filePath, strpos($filePath, 'Spryker/'));
$zip->addFile($filePath, $relativePath);
}
}
Expand All @@ -136,7 +126,7 @@ public static function zipDir(string $dirPath, string $zipPath): void
*
* @return \SprykerSdk\Integrator\Transfer\IntegratorCommandArgumentsTransfer
*/
public function createCommandArgumentsTransfer(bool $isDry = false, array $ModuleTransfers = []): IntegratorCommandArgumentsTransfer
protected function createCommandArgumentsTransfer(bool $isDry = false, array $ModuleTransfers = []): IntegratorCommandArgumentsTransfer
{
$commandArgumentsTransfer = new IntegratorCommandArgumentsTransfer();
$commandArgumentsTransfer->setModules($ModuleTransfers);
Expand Down
71 changes: 71 additions & 0 deletions tests/SprykerSdkTest/Integrator/IntegratorFacadeGeneralTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

declare(strict_types=1);

namespace SprykerSdkTest\Integrator;

class IntegratorFacadeGeneralTest extends AbstractIntegratorTestCase
{
/**
* @var string
*/
protected const MANIFESTS_DIR_PATH = 'general/manifests/src';

/**
* @var string
*/
protected const ZIP_PATH = '_data/archive.zip';

/**
* Rewrite the path to mock project
*
* @return string
*/
protected function getProjectMockOriginalPath(): string
{
return $this->getDataDirectoryPath() . DIRECTORY_SEPARATOR . 'general' . DIRECTORY_SEPARATOR . 'project_original';
}

/**
* Rewrite the path to mock project after integration
*
* @return string
*/
protected function getProjectMockCurrentPath(): string
{
return $this->getDataDirectoryPath() . DIRECTORY_SEPARATOR . 'general' . DIRECTORY_SEPARATOR . 'project_current';
}

/**
* @return void
*/
public function testRunInstallationGlossary(): void
{
// Arrange
$ioAdapter = $this->buildSymfonyConsoleInputOutputAdapter();

// Act
$this->createIntegratorFacade()->runModuleManifestInstallation(
$ioAdapter,
$this->createCommandArgumentsTransfer(false, [$this->getModuleTransfer('Spryker.TestIntegratorGlossary')]),
);

// Assert
$glossaryPath = '/data/import/common/common/glossary.csv';
$testFilePath = $this->getProjectMockCurrentPath() . $glossaryPath;
$testResultFile = $this->getTestTmpDirPath() . $glossaryPath;

$this->assertFileExists($testFilePath);
$this->assertFileExists($testResultFile);
$this->assertStringContainsString(
trim(file_get_contents($this->getProjectMockOriginalPath() . $glossaryPath)),
trim(file_get_contents($testResultFile)),
);
$this->assertSame(trim(file_get_contents($testFilePath)), trim(file_get_contents($testResultFile)));
}
}
Loading

0 comments on commit 6e0c515

Please sign in to comment.