From fff4a66926abda9bc2fb71660d32b640a1592200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Fri, 21 Apr 2023 10:15:03 +0200 Subject: [PATCH] feat: PHAR (#129) * feat: PHAR environment * feat: PHAR init * fix: few SA fixes --- phpstan.baseline.neon | 100 ---------------------- psalm.baseline.xml | 117 +++++--------------------- resources/PHP/phar.mk | 13 +++ resources/PHP/phar/box.json.dist | 7 ++ tests/functional/MakefileTestCase.php | 13 +++ tests/functional/PHP/PharTest.php | 86 +++++++++++++++++++ tests/functional/PHP/PhpTrait.php | 6 ++ 7 files changed, 148 insertions(+), 194 deletions(-) create mode 100644 resources/PHP/phar.mk create mode 100644 resources/PHP/phar/box.json.dist create mode 100644 tests/functional/PHP/PharTest.php diff --git a/phpstan.baseline.neon b/phpstan.baseline.neon index 8f0d941..b61515a 100644 --- a/phpstan.baseline.neon +++ b/phpstan.baseline.neon @@ -1,15 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\Common\\\\DefaultTest\\:\\:getExpectedHelpCommandsExecutionPath\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/Common/DefaultTest.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\Common\\\\DefaultTest\\:\\:getExpectedInitPaths\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/Common/DefaultTest.php - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\MakefileTestCase\\:\\:dryRun\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#" count: 1 @@ -50,97 +40,7 @@ parameters: count: 1 path: tests/functional/MakefileTestCase.php - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\MakefileTestCase\\:\\:getExpectedHelpCommandsExecutionPath\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/MakefileTestCase.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\MakefileTestCase\\:\\:getExpectedInitPaths\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/MakefileTestCase.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\MakefileTestCase\\:\\:testMakefileCommandsWork\\(\\) has parameter \\$env with no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/MakefileTestCase.php - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\MakefileTestCase\\:\\:testMakefileCommandsWork\\(\\) has parameter \\$expected with no value type specified in iterable type array\\.$#" count: 1 path: tests/functional/MakefileTestCase.php - - - - message: "#^Property Sigwin\\\\Infra\\\\Test\\\\Functional\\\\MakefileTestCase\\:\\:\\$help type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/MakefileTestCase.php - - - - message: "#^Property Sigwin\\\\Infra\\\\Test\\\\Functional\\\\MakefileTestCase\\:\\:\\$helpOverride type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/MakefileTestCase.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\PHP\\\\LibraryTest\\:\\:getExpectedHelpCommandsExecutionPath\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/PHP/LibraryTest.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\PHP\\\\LibraryTest\\:\\:getExpectedInitPaths\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/PHP/LibraryTest.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\PHP\\\\LibraryTest\\:\\:paths\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/PHP/LibraryTest.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\Pimcore\\\\ApplicationTest\\:\\:getExpectedHelpCommandsExecutionPath\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/Pimcore/ApplicationTest.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\Pimcore\\\\ApplicationTest\\:\\:getExpectedInitPaths\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/Pimcore/ApplicationTest.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\Pimcore\\\\ApplicationTest\\:\\:paths\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/Pimcore/ApplicationTest.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\Pimcore\\\\LibraryTest\\:\\:getExpectedHelpCommandsExecutionPath\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/Pimcore/LibraryTest.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\Pimcore\\\\LibraryTest\\:\\:getExpectedInitPaths\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/Pimcore/LibraryTest.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\Pimcore\\\\LibraryTest\\:\\:paths\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/Pimcore/LibraryTest.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\YASSG\\\\CompatTest\\:\\:getExpectedHelpCommandsExecutionPath\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/YASSG/CompatTest.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\YASSG\\\\CompatTest\\:\\:getExpectedInitPaths\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/YASSG/CompatTest.php - - - - message: "#^Method Sigwin\\\\Infra\\\\Test\\\\Functional\\\\YASSG\\\\CompatTest\\:\\:paths\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/YASSG/CompatTest.php - - - - message: "#^Property Sigwin\\\\Infra\\\\Test\\\\Functional\\\\YASSG\\\\CompatTest\\:\\:\\$helpOverride type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/functional/YASSG/CompatTest.php diff --git a/psalm.baseline.xml b/psalm.baseline.xml index be9fa41..4a1aaa6 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -16,10 +16,8 @@ $dir $dir $files - helpOverride[$command] ?? $this->help[$command] ?? '']]> - $env $files $files $command $dir - $path - - , array}>]]> - + + array_values + - - $composer - $composer - $mkdir - $mkdir - $mkdir - $mkdir - $mkdir - $mkdir + + + + + + - $test - $test - - - $composer - $composer - $mkdir - $mkdir - $mkdir - $test - + + + + + + $helpOverride + + @@ -79,41 +70,11 @@ iterable - - array - + + >]]> + - - $clean - $composer - $mkdir - $mkdir - $mkdir - $mkdir - $mkdir - $mkdir - - - - - - $testFunctional - $testFunctional - $testUnit - $testUnit - $testUnit - $touch - - - $clean - $composer - $mkdir - $mkdir - $testFunctional - $testUnit - $touch - @@ -139,34 +100,10 @@ - - $mkdir - $mkdir - $mkdir - $mkdir - $mkdir - - - - - - - $testFunctional - $testFunctional - $testUnit - $testUnit - $testUnit - - - $mkdir - $testFunctional - $testUnit - - @@ -179,17 +116,9 @@ - - $mkdir - $mkdir - $mkdir - - - - - - $mkdir - + + $helpOverride + diff --git a/resources/PHP/phar.mk b/resources/PHP/phar.mk new file mode 100644 index 0000000..693be55 --- /dev/null +++ b/resources/PHP/phar.mk @@ -0,0 +1,13 @@ +ifndef SIGWIN_INFRA_ROOT +SIGWIN_INFRA_ROOT := $(dir $(abspath $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))) +endif +include ${SIGWIN_INFRA_ROOT:%/=%}/PHP/common.mk + +dist: composer/normalize cs analyze/phpstan analyze/psalm test ## Prepare the codebase for commit +analyze: analyze/composer analyze/cs analyze/phpstan analyze/psalm ## Analyze the codebase +test: test/infection ## Test the codebase + +phar/build: | ${HOME}/.composer var/phpqa composer.lock ## Build PHAR file + $(call block_start,$@) + ${PHPQA_DOCKER_COMMAND} box compile + $(call block_end) diff --git a/resources/PHP/phar/box.json.dist b/resources/PHP/phar/box.json.dist new file mode 100644 index 0000000..a56e989 --- /dev/null +++ b/resources/PHP/phar/box.json.dist @@ -0,0 +1,7 @@ +{ + "files": [ + "config/bundles.php", + "config/services.yaml" + ], + "compression": "GZ" +} diff --git a/tests/functional/MakefileTestCase.php b/tests/functional/MakefileTestCase.php index 15c1835..2d43111 100644 --- a/tests/functional/MakefileTestCase.php +++ b/tests/functional/MakefileTestCase.php @@ -26,6 +26,9 @@ */ abstract class MakefileTestCase extends TestCase { + /** + * @var array + */ private array $help = [ 'analyze' => 'Analyze the codebase', 'analyze/lighthouse' => 'Analyze built files using Lighthouse', @@ -50,13 +53,21 @@ abstract class MakefileTestCase extends TestCase 'visual/reference' => 'Generate visual testing references', ]; + /** + * @var array + */ protected array $helpOverride = []; /** * @param null|array $env + * + * @return array> */ abstract protected function getExpectedHelpCommandsExecutionPath(?array $env = null): array; + /** + * @return list + */ abstract protected function getExpectedInitPaths(): array; public function testMakefileExists(): void @@ -97,6 +108,8 @@ public function testMakefileHasInit(): void /** * @dataProvider provideHelpCommandsExecutionPathFixtures + * + * @param array $env */ public function testMakefileCommandsWork(string $command, array $expected, array $env): void { diff --git a/tests/functional/PHP/PharTest.php b/tests/functional/PHP/PharTest.php new file mode 100644 index 0000000..d419087 --- /dev/null +++ b/tests/functional/PHP/PharTest.php @@ -0,0 +1,86 @@ + 'Build PHAR file', + ]; + + public function testCanRunComposerInstallLowest(): void + { + $paths = $this->paths(null); + + $mkdir = $paths['mkdir: phpqa']; + $composer = $paths['composer: install-lowest']; + $expected = array_merge($mkdir, $composer); + $actual = $this->dryRun('composer/install-lowest'); + + static::assertSame($expected, $actual); + } + + public function testCanRunComposerInstallHighest(): void + { + $paths = $this->paths(null); + + $mkdir = $paths['mkdir: phpqa']; + $composer = $paths['composer: install-highest']; + $expected = array_merge($mkdir, $composer); + $actual = $this->dryRun('composer/install-highest'); + + static::assertSame($expected, $actual); + } + + protected function getExpectedInitPaths(): array + { + return [ + 'Common/Platform/$PLATFORM/default', + 'Common/default', + 'PHP/common', + 'PHP/phar', + ]; + } + + protected function getExpectedHelpCommandsExecutionPath(?array $env = null): array + { + $paths = $this->paths($env); + + $mkdir = $paths['mkdir: phpqa']; + $test = $paths['test: unit']; + + return [ + 'help' => [$this->generateHelpExecutionPath([ + __DIR__.'/../../../resources/PHP/phar.mk', + __DIR__.'/../../../resources/PHP/common.mk', + ])], + 'phar/build' => array_merge($mkdir, $paths['box: build']), + 'analyze' => array_merge($mkdir, $paths['analyze']), + 'dist' => array_merge($mkdir, $paths['prepareAndAnalyze'], $test), + 'sh/php' => array_merge($mkdir, $paths['shell: PHP']), + 'test' => array_merge($mkdir, $test), + ]; + } +} diff --git a/tests/functional/PHP/PhpTrait.php b/tests/functional/PHP/PhpTrait.php index 1c3144f..b2cc0af 100644 --- a/tests/functional/PHP/PhpTrait.php +++ b/tests/functional/PHP/PhpTrait.php @@ -27,6 +27,8 @@ protected function getEnvs(): iterable /** * @param null|array $env + * + * @return array> */ private function paths(?array $env): array { @@ -48,6 +50,10 @@ private function paths(?array $env): array $this->generatePhpqaExecutionPath('psalm --php-version=%1$s --config psalm.xml.dist', phpVersion: $phpVersion, dockerImage: $phpqaDockerImage), ], + 'box: build' => [ + $this->generatePhpqaExecutionPath('box compile', phpVersion: $phpVersion, dockerImage: $phpqaDockerImage), + ], + 'build: dev' => [ $this->generateDockerBuildxExecutionPath('dev'), ],