Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 4, 2023
1 parent 02753c6 commit 752baaf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Command/AnalyseCommand.php
Expand Up @@ -98,7 +98,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
if ((bool) $input->getOption('debug')) {
$application = $this->getApplication();
if ($application === null) {
throw new ShouldNotHappenException();
return;
}
$application->setCatchExceptions(false);
return;
Expand Down
25 changes: 19 additions & 6 deletions tests/PHPStan/Command/AnalyseCommandTest.php
Expand Up @@ -50,12 +50,24 @@ public function testInvalidAutoloadFile(): void

public function testValidAutoloadFile(): void
{
$originalDir = getcwd();
if ($originalDir === false) {
throw new ShouldNotHappenException();
}

$autoloadFile = __DIR__ . DIRECTORY_SEPARATOR . 'data/autoload-file.php';

$output = $this->runCommand(0, ['--autoload-file' => $autoloadFile]);
$this->assertStringContainsString('[OK] No errors', $output);
$this->assertStringNotContainsString(sprintf('Autoload file "%s" not found.' . PHP_EOL, $autoloadFile), $output);
$this->assertSame('magic value', SOME_CONSTANT_IN_AUTOLOAD_FILE);
chdir(__DIR__);

try {
$output = $this->runCommand(0, ['--autoload-file' => $autoloadFile]);
$this->assertStringContainsString('[OK] No errors', $output);
$this->assertStringNotContainsString(sprintf('Autoload file "%s" not found.' . PHP_EOL, $autoloadFile), $output);
$this->assertSame('magic value', SOME_CONSTANT_IN_AUTOLOAD_FILE);
} catch (Throwable $e) {
chdir($originalDir);
throw $e;
}
}

/**
Expand Down Expand Up @@ -96,9 +108,10 @@ private function runCommand(int $expectedStatusCode, array $parameters = []): st

$commandTester->execute([
'paths' => [__DIR__ . DIRECTORY_SEPARATOR . 'test'],
] + $parameters);
'--debug' => true,
] + $parameters, ['debug' => true]);

$this->assertSame($expectedStatusCode, $commandTester->getStatusCode());
$this->assertSame($expectedStatusCode, $commandTester->getStatusCode(), $commandTester->getDisplay());

return $commandTester->getDisplay();
}
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Command/test/empty.php
@@ -0,0 +1 @@
<?php declare(strict_types = 1);

0 comments on commit 752baaf

Please sign in to comment.