Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/CLI/Command/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions tests/E2E/Cli/CheckCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down
Loading