Skip to content

Commit 752baaf

Browse files
committed
Fix test
1 parent 02753c6 commit 752baaf

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/Command/AnalyseCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
9898
if ((bool) $input->getOption('debug')) {
9999
$application = $this->getApplication();
100100
if ($application === null) {
101-
throw new ShouldNotHappenException();
101+
return;
102102
}
103103
$application->setCatchExceptions(false);
104104
return;

tests/PHPStan/Command/AnalyseCommandTest.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,24 @@ public function testInvalidAutoloadFile(): void
5050

5151
public function testValidAutoloadFile(): void
5252
{
53+
$originalDir = getcwd();
54+
if ($originalDir === false) {
55+
throw new ShouldNotHappenException();
56+
}
57+
5358
$autoloadFile = __DIR__ . DIRECTORY_SEPARATOR . 'data/autoload-file.php';
5459

55-
$output = $this->runCommand(0, ['--autoload-file' => $autoloadFile]);
56-
$this->assertStringContainsString('[OK] No errors', $output);
57-
$this->assertStringNotContainsString(sprintf('Autoload file "%s" not found.' . PHP_EOL, $autoloadFile), $output);
58-
$this->assertSame('magic value', SOME_CONSTANT_IN_AUTOLOAD_FILE);
60+
chdir(__DIR__);
61+
62+
try {
63+
$output = $this->runCommand(0, ['--autoload-file' => $autoloadFile]);
64+
$this->assertStringContainsString('[OK] No errors', $output);
65+
$this->assertStringNotContainsString(sprintf('Autoload file "%s" not found.' . PHP_EOL, $autoloadFile), $output);
66+
$this->assertSame('magic value', SOME_CONSTANT_IN_AUTOLOAD_FILE);
67+
} catch (Throwable $e) {
68+
chdir($originalDir);
69+
throw $e;
70+
}
5971
}
6072

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

97109
$commandTester->execute([
98110
'paths' => [__DIR__ . DIRECTORY_SEPARATOR . 'test'],
99-
] + $parameters);
111+
'--debug' => true,
112+
] + $parameters, ['debug' => true]);
100113

101-
$this->assertSame($expectedStatusCode, $commandTester->getStatusCode());
114+
$this->assertSame($expectedStatusCode, $commandTester->getStatusCode(), $commandTester->getDisplay());
102115

103116
return $commandTester->getDisplay();
104117
}

tests/PHPStan/Command/test/empty.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php declare(strict_types = 1);

0 commit comments

Comments
 (0)