Skip to content

Commit

Permalink
SDK-5463: Adjust the upgrade process so it runs phpstan between itera… (
Browse files Browse the repository at this point in the history
  • Loading branch information
VladislavStrelchenko committed Dec 28, 2023
1 parent 93426f9 commit 328dc2e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 55 deletions.
2 changes: 2 additions & 0 deletions config/DynamicEvaluator/checker_phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ parameters:
analyse:
- %currentWorkingDirectory%/src/Generated/*
- %currentWorkingDirectory%/src/Orm/*
- %currentWorkingDirectory%/src/Pyz/Zed/*/Persistence/*Repository.php
- %currentWorkingDirectory%/src/Pyz/Zed/*/Persistence/*QueryContainer.php
10 changes: 0 additions & 10 deletions config/DynamicEvaluator/checker_phpstan_include_project.neon

This file was deleted.

2 changes: 0 additions & 2 deletions config/DynamicEvaluator/services.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
parameters:
checker_broken_php_files_executable_path: '%kernel.project_dir%/vendor/bin/phpstan'
checker_broken_php_files_config_executable_path: '%upgrader.root_dir%/config/DynamicEvaluator/checker_phpstan.neon'
checker_broken_php_files_with_project_config_executable_path: '%upgrader.root_dir%/config/DynamicEvaluator/checker_phpstan_include_project.neon'

services:
_defaults:
Expand All @@ -18,7 +17,6 @@ services:
DynamicEvaluator\Application\Checker\BrokenPhpFilesChecker\FileErrorsFetcher\FileErrorsFetcher:
arguments:
- '%checker_broken_php_files_config_executable_path%'
- '%checker_broken_php_files_with_project_config_executable_path%'
- '%checker_broken_php_files_executable_path%'
- '@SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerService'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ class FileErrorsFetcher implements FileErrorsFetcherInterface
*/
protected string $executableConfig;

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

/**
* @var string
*/
Expand Down Expand Up @@ -57,7 +52,6 @@ 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 @@ -66,15 +60,13 @@ class FileErrorsFetcher implements FileErrorsFetcherInterface
*/
public function __construct(
string $executableConfig,
string $executableProjectConfig,
string $executable,
ProcessRunnerServiceInterface $processRunnerService,
BaselineStorageInterface $baselineStorage,
LoggerInterface $logger,
string $phpstanNeonFileName = 'phpstan.neon'
) {
$this->executableConfig = $executableConfig;
$this->executableProjectConfig = $executableProjectConfig;
$this->executable = $executable;
$this->processRunnerService = $processRunnerService;
$this->baselineStorage = $baselineStorage;
Expand All @@ -94,7 +86,7 @@ public function fetchProjectFileErrorsAndSaveInBaseLine(array $dirs = []): array
try {
$errors = $this->fetchErrorsArray($dirs);
} catch (ProcessTimedOutException $e) {
$this->logger->debug($e->getMessage());
$this->logger->warning($e->getMessage());

return [
new FileErrorDto(
Expand All @@ -107,7 +99,7 @@ public function fetchProjectFileErrorsAndSaveInBaseLine(array $dirs = []): array
),
];
} catch (Exception $e) {
$this->logger->debug($e->getMessage());
$this->logger->warning($e->getMessage());

return [
new FileErrorDto(
Expand Down Expand Up @@ -170,7 +162,7 @@ protected function fetchErrorsArray(array $dirs): array
$this->executable,
'analyse',
'-c',
file_exists(getcwd() . DIRECTORY_SEPARATOR . $this->phpstanNeonFileName) ? $this->executableProjectConfig : $this->executableConfig,
$this->executableConfig,
'--error-format',
'prettyJson',
...$dirs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testFetchProjectFileErrorsAndSaveInBaseLineShouldValidate(array
// Arrange
$this->expectException(InvalidArgumentException::class);

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

// Act
$fileErrorsFetcher->fetchProjectFileErrorsAndSaveInBaseLine();
Expand Down Expand Up @@ -64,7 +64,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());
$fileErrorsFetcher = new FileErrorsFetcher('', '', $this->createProcessRunnerServiceMock($toolOutput), $baseLineStorage, $this->createLoggerMock());

// Act
$fileErrors = $fileErrorsFetcher->fetchProjectFileErrorsAndSaveInBaseLine();
Expand All @@ -82,7 +82,7 @@ public function testFetchProjectFileErrorsAndSaveInBaseLineShouldFetchFileErrors
$toolOutput = ['files' => ['src/someClass.php' => ['messages' => [['line' => 1, 'message' => 'test message']]]]];

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

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

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

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

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

// Act
$fileErrors = $fileErrorsFetcher->fetchProjectFileErrorsAndSaveInBaseLine();

// Assert
$this->assertEmpty($fileErrors);
}

/**
* @return void
*/
public function testRunWithProjectConfig(): void
{
// Arrange
$toolOutput = ['files' => []];
$processMock = $this->createMock(Process::class);
$processMock->method('getOutput')->willReturn(json_encode($toolOutput, \JSON_THROW_ON_ERROR));
/** @var \SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface&\PHPUnit\Framework\MockObject\MockObject $processRunnerServiceMock */
$processRunnerServiceMock = $this->createMock(ProcessRunnerServiceInterface::class);
$processRunnerServiceMock
->method('run')
->with(['phpstan', 'analyse', '-c', 'project', '--error-format', 'prettyJson'])
->willReturn($processMock);

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

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

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

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

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

// Act
$fileErrors = $fileErrorsFetcher->fetchProjectFileErrorsAndSaveInBaseLine();
Expand Down

0 comments on commit 328dc2e

Please sign in to comment.