From d96f4fd044958a9f4af5553e4afd8bb6b3f5e18c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Mar 2026 21:20:00 +0000 Subject: [PATCH 1/2] Make --autoload mandatory when running as PHAR When phparkitect is used as a PHAR, no project autoloader is loaded automatically, so --autoload must be explicitly provided to avoid silent class-resolution failures. https://claude.ai/code/session_01DHLEWujytAcAhyLyxELTuS --- src/CLI/Command/Check.php | 11 +++++++++++ tests/E2E/Cli/CheckCommandTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/CLI/Command/Check.php b/src/CLI/Command/Check.php index 67fac7fe..91cd4e01 100644 --- a/src/CLI/Command/Check.php +++ b/src/CLI/Command/Check.php @@ -108,6 +108,11 @@ protected function configure(): void ); } + protected function isRunningAsPhar(): bool + { + return \Phar::running() !== ''; + } + protected function execute(InputInterface $input, OutputInterface $output): int { ini_set('memory_limit', '-1'); @@ -130,6 +135,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int $stdOut = $output; $output = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output; + if ($this->isRunningAsPhar() && null === $input->getOption(self::AUTOLOAD_PARAM)) { + $output->writeln('❌ The --autoload option is required when running phparkitect as a PHAR'); + + return self::ERROR_CODE; + } + $this->printHeadingLine($output); $config = ConfigBuilder::loadFromFile($rulesFilename) diff --git a/tests/E2E/Cli/CheckCommandTest.php b/tests/E2E/Cli/CheckCommandTest.php index c60ef9c5..f757ba4b 100644 --- a/tests/E2E/Cli/CheckCommandTest.php +++ b/tests/E2E/Cli/CheckCommandTest.php @@ -4,8 +4,10 @@ namespace Arkitect\Tests\E2E\Cli; +use Arkitect\CLI\Command\Check; use Arkitect\CLI\PhpArkitectApplication; use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\ApplicationTester; class CheckCommandTest extends TestCase @@ -252,6 +254,30 @@ public function test_gitlab_format_output_no_errors(): void self::assertJsonStringEqualsJsonString($expectedJson, $cmdTester->getDisplay()); } + public function test_autoload_is_required_when_running_as_phar(): void + { + $pharCheck = new class extends Check { + protected function isRunningAsPhar(): bool + { + return true; + } + }; + + $app = new Application(); + $app->setAutoExit(false); + $addMethod = method_exists($app, 'addCommand') ? 'addCommand' : 'add'; + $app->$addMethod($pharCheck); + + $appTester = new ApplicationTester($app); + $appTester->run( + ['check', '--config' => __DIR__.'/../_fixtures/configMvcWithoutErrors.php'], + ['capture_stderr_separately' => true] + ); + + self::assertCommandExitedWithError($appTester); + self::assertStringContainsString('--autoload', $appTester->getErrorOutput()); + } + public function test_autoload_file(): void { $configFilePath = __DIR__.'/../_fixtures/autoload/phparkitect.php'; From 720a0c56797d30a8c4228f8d8481ed9932720f53 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Mar 2026 21:29:43 +0000 Subject: [PATCH 2/2] Fix CS: use Yoda-style comparison in isRunningAsPhar https://claude.ai/code/session_01DHLEWujytAcAhyLyxELTuS --- src/CLI/Command/Check.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CLI/Command/Check.php b/src/CLI/Command/Check.php index 91cd4e01..836c9f1f 100644 --- a/src/CLI/Command/Check.php +++ b/src/CLI/Command/Check.php @@ -110,7 +110,7 @@ protected function configure(): void protected function isRunningAsPhar(): bool { - return \Phar::running() !== ''; + return '' !== \Phar::running(); } protected function execute(InputInterface $input, OutputInterface $output): int