Skip to content

Commit

Permalink
SUPESC-838 Fixed issue with project config. (#323)
Browse files Browse the repository at this point in the history
* FRW-838 Fixed allowed memory size

* FRW-838 Fixed CI

* SUPESC-838 Optimization for phpstan

* SUPESC-838 Added config, adjustments

* SUPESC-838 Renamed the var

* SUPESC-838 Renamed the var

* SUPESC-838 Fixes for project config

* SUPESC-838 Added verificiation
  • Loading branch information
olhalivitchuk committed Jul 30, 2024
1 parent cb51ac1 commit 28c3534
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class FileErrorsFetcher implements FileErrorsFetcherInterface
*/
protected string $executableConfig;

/**
* @var string
*/
protected string $executableProjectConfig;

/**
* @var string
*/
Expand Down Expand Up @@ -61,6 +66,7 @@ class FileErrorsFetcher implements FileErrorsFetcherInterface

/**
* @param string $executableConfig
* @param string $executableProjectConfig
* @param string $executable
* @param \SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface $processRunnerService
* @param \DynamicEvaluator\Application\Checker\BrokenPhpFilesChecker\Baseline\BaselineStorageInterface $baselineStorage
Expand All @@ -70,6 +76,7 @@ class FileErrorsFetcher implements FileErrorsFetcherInterface
*/
public function __construct(
string $executableConfig,
string $executableProjectConfig,
string $executable,
ProcessRunnerServiceInterface $processRunnerService,
BaselineStorageInterface $baselineStorage,
Expand All @@ -78,6 +85,7 @@ public function __construct(
string $phpstanNeonFileName = 'phpstan.neon'
) {
$this->executableConfig = $executableConfig;
$this->executableProjectConfig = $executableProjectConfig;
$this->executable = $executable;
$this->processRunnerService = $processRunnerService;
$this->baselineStorage = $baselineStorage;
Expand Down Expand Up @@ -211,11 +219,13 @@ protected function fetchErrorsArray(array $dirs): array
return $this->fetchErrorsArrayPerDirectory($dirs);
}

$executableConfig = file_exists(getcwd() . DIRECTORY_SEPARATOR . $this->phpstanNeonFileName) && $this->configurationProvider->isPhpStanOptimizationRun() === true ? $this->executableProjectConfig : $this->executableConfig;

$process = $this->processRunnerService->run([
$this->executable,
'analyse',
'-c',
$this->executableConfig,
$executableConfig,
'--error-format',
'prettyJson',
...$dirs,
Expand All @@ -232,13 +242,14 @@ protected function fetchErrorsArray(array $dirs): array
protected function fetchErrorsArrayPerDirectory(array $dirs): array
{
$result = [];
$executableConfig = file_exists(getcwd() . DIRECTORY_SEPARATOR . $this->phpstanNeonFileName) && $this->configurationProvider->isPhpStanOptimizationRun() === true ? $this->executableProjectConfig : $this->executableConfig;

foreach ($dirs as $dir) {
$process = $this->processRunnerService->run([
$this->executable,
'analyse',
'-c',
$this->executableConfig,
$executableConfig,
'--error-format',
'prettyJson',
$dir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function testFetchProjectFileErrorsAndSaveInBaseLineShouldValidate(array
$this->expectException(InvalidArgumentException::class);

$fileErrorsFetcher = new FileErrorsFetcher(
'',
'',
'',
$this->createProcessRunnerServiceMock($toolOutput),
Expand Down Expand Up @@ -72,7 +73,7 @@ public function testFetchProjectFileErrorsAndSaveInBaseLineShouldReturnEmptyWhen
$baseLineStorage = new BaselineStorage();
$baseLineStorage->addFileError(new FileErrorDto('src/someClass.php', 1, 'test message'));

$fileErrorsFetcher = new FileErrorsFetcher('', '', $this->createProcessRunnerServiceMock($toolOutput), $baseLineStorage, $this->createLoggerMock(), $this->createConfigurationProviderMock());
$fileErrorsFetcher = new FileErrorsFetcher('', '', '', $this->createProcessRunnerServiceMock($toolOutput), $baseLineStorage, $this->createLoggerMock(), $this->createConfigurationProviderMock());

// Act
$fileErrors = $fileErrorsFetcher->fetchProjectFileErrorsAndSaveInBaseLine();
Expand All @@ -93,7 +94,7 @@ public function testFetchProjectFileErrorsAndSaveInBaseLineShouldFetchFileErrors
{
// Arrange
$baseLineStorage = new BaselineStorage();
$fileErrorsFetcher = new FileErrorsFetcher('', '', $this->createProcessRunnerServiceMock($toolOutput), $baseLineStorage, $this->createLoggerMock(), $this->createConfigurationProviderMock());
$fileErrorsFetcher = new FileErrorsFetcher('', '', '', $this->createProcessRunnerServiceMock($toolOutput), $baseLineStorage, $this->createLoggerMock(), $this->createConfigurationProviderMock());

// Act
$fileErrors = $fileErrorsFetcher->fetchProjectFileErrorsAndSaveInBaseLine();
Expand Down Expand Up @@ -135,7 +136,7 @@ public function testResetShouldInvokeBaselineStorageResetting(): void
$baseLineStorageMock = $this->createMock(BaselineStorage::class);
$baseLineStorageMock->expects($this->once())->method('clear');

$fileErrorsFetcher = new FileErrorsFetcher('', '', $this->createProcessRunnerServiceMock([]), $baseLineStorageMock, $this->createLoggerMock(), $this->createConfigurationProviderMock());
$fileErrorsFetcher = new FileErrorsFetcher('', '', '', $this->createProcessRunnerServiceMock([]), $baseLineStorageMock, $this->createLoggerMock(), $this->createConfigurationProviderMock());

// Act
$fileErrorsFetcher->reset();
Expand Down Expand Up @@ -195,7 +196,7 @@ public function testRunWithoutProjectConfig(): void
->with(['phpstan', 'analyse', '-c', 'internal', '--error-format', 'prettyJson'])
->willReturn($processMock);

$fileErrorsFetcher = new FileErrorsFetcher('internal', 'phpstan', $processRunnerServiceMock, new BaselineStorage(), $this->createLoggerMock(), $this->createConfigurationProviderMock(), 'nonexist.neon');
$fileErrorsFetcher = new FileErrorsFetcher('internal', '', 'phpstan', $processRunnerServiceMock, new BaselineStorage(), $this->createLoggerMock(), $this->createConfigurationProviderMock(), 'nonexist.neon');

// Act
$fileErrors = $fileErrorsFetcher->fetchProjectFileErrorsAndSaveInBaseLine();
Expand All @@ -222,7 +223,7 @@ public function testRunProcessWithTimeout(): void
->method('run')
->willThrowException(new ProcessTimedOutException($processMock, ProcessTimedOutException::TYPE_GENERAL));

$fileErrorsFetcher = new FileErrorsFetcher('', '', $processRunnerServiceMock, new BaselineStorage(), $loggerMock, $this->createConfigurationProviderMock(), 'phpstan.neon');
$fileErrorsFetcher = new FileErrorsFetcher('', '', '', $processRunnerServiceMock, new BaselineStorage(), $loggerMock, $this->createConfigurationProviderMock(), 'phpstan.neon');

// Act
$fileErrors = $fileErrorsFetcher->fetchProjectFileErrorsAndSaveInBaseLine();
Expand Down Expand Up @@ -251,7 +252,7 @@ public function testRunProcessWithException(): void
->method('run')
->willThrowException(new Exception('error'));

$fileErrorsFetcher = new FileErrorsFetcher('', '', $processRunnerServiceMock, new BaselineStorage(), $loggerMock, $this->createConfigurationProviderMock(), 'phpstan.neon');
$fileErrorsFetcher = new FileErrorsFetcher('', '', '', $processRunnerServiceMock, new BaselineStorage(), $loggerMock, $this->createConfigurationProviderMock(), 'phpstan.neon');

// Act
$fileErrors = $fileErrorsFetcher->fetchProjectFileErrorsAndSaveInBaseLine();
Expand Down Expand Up @@ -290,6 +291,7 @@ public function testFetchProjectFileErrorsExecutesPerDir(): void
$fileErrorsFetcher = new FileErrorsFetcher(
'config/DynamicEvaluator/checker_phpstan.neon',
'',
'',
$processRunnerServiceMock,
new BaselineStorage(),
$this->createLoggerMock(),
Expand Down

0 comments on commit 28c3534

Please sign in to comment.