From 28c3534e898d1ae4fba16f38cdb6cdcbf4782de5 Mon Sep 17 00:00:00 2001 From: Olha Livitchuk <77281282+olhalivitchuk@users.noreply.github.com> Date: Tue, 30 Jul 2024 11:32:22 +0200 Subject: [PATCH] SUPESC-838 Fixed issue with project config. (#323) * 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 --- .../FileErrorsFetcher/FileErrorsFetcher.php | 15 +++++++++++++-- .../FileErrorsFetcher/FileErrorsFetcherTest.php | 14 ++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/DynamicEvaluator/Application/Checker/BrokenPhpFilesChecker/FileErrorsFetcher/FileErrorsFetcher.php b/src/DynamicEvaluator/Application/Checker/BrokenPhpFilesChecker/FileErrorsFetcher/FileErrorsFetcher.php index 29ddd711..de198b35 100644 --- a/src/DynamicEvaluator/Application/Checker/BrokenPhpFilesChecker/FileErrorsFetcher/FileErrorsFetcher.php +++ b/src/DynamicEvaluator/Application/Checker/BrokenPhpFilesChecker/FileErrorsFetcher/FileErrorsFetcher.php @@ -29,6 +29,11 @@ class FileErrorsFetcher implements FileErrorsFetcherInterface */ protected string $executableConfig; + /** + * @var string + */ + protected string $executableProjectConfig; + /** * @var string */ @@ -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 @@ -70,6 +76,7 @@ class FileErrorsFetcher implements FileErrorsFetcherInterface */ public function __construct( string $executableConfig, + string $executableProjectConfig, string $executable, ProcessRunnerServiceInterface $processRunnerService, BaselineStorageInterface $baselineStorage, @@ -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; @@ -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, @@ -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, diff --git a/tests/DynamicEvaluatorTest/Application/Checker/BrokenPhpFilesChecker/FileErrorsFetcher/FileErrorsFetcherTest.php b/tests/DynamicEvaluatorTest/Application/Checker/BrokenPhpFilesChecker/FileErrorsFetcher/FileErrorsFetcherTest.php index 49277e37..90b60921 100644 --- a/tests/DynamicEvaluatorTest/Application/Checker/BrokenPhpFilesChecker/FileErrorsFetcher/FileErrorsFetcherTest.php +++ b/tests/DynamicEvaluatorTest/Application/Checker/BrokenPhpFilesChecker/FileErrorsFetcher/FileErrorsFetcherTest.php @@ -36,6 +36,7 @@ public function testFetchProjectFileErrorsAndSaveInBaseLineShouldValidate(array $this->expectException(InvalidArgumentException::class); $fileErrorsFetcher = new FileErrorsFetcher( + '', '', '', $this->createProcessRunnerServiceMock($toolOutput), @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -290,6 +291,7 @@ public function testFetchProjectFileErrorsExecutesPerDir(): void $fileErrorsFetcher = new FileErrorsFetcher( 'config/DynamicEvaluator/checker_phpstan.neon', '', + '', $processRunnerServiceMock, new BaselineStorage(), $this->createLoggerMock(),