@@ -69,6 +69,100 @@ public function testValidAutoloadFile(): void
6969 }
7070 }
7171
72+ public function testStopOnFailureWithoutErrors (): void
73+ {
74+ $ output = $ this ->runCommand (0 , ['--stop-on-failure ' => true ]);
75+ $ this ->assertStringContainsString ('[OK] No errors ' , $ output );
76+ }
77+
78+ public function testStopOnFailureWithErrors (): void
79+ {
80+ $ originalDir = getcwd ();
81+ if ($ originalDir === false ) {
82+ throw new ShouldNotHappenException ();
83+ }
84+
85+ chdir (__DIR__ );
86+
87+ try {
88+ $ output = $ this ->runCommand (1 , [
89+ '--stop-on-failure ' => true ,
90+ 'paths ' => [
91+ __DIR__ . DIRECTORY_SEPARATOR . 'test ' . DIRECTORY_SEPARATOR . 'file1-with-error.php ' ,
92+ __DIR__ . DIRECTORY_SEPARATOR . 'test ' . DIRECTORY_SEPARATOR . 'file2-with-error.php ' ,
93+ ],
94+ ]);
95+
96+ // Should have errors from the first file
97+ $ this ->assertStringContainsString ('file1-with-error.php ' , $ output );
98+
99+ // Should stop after first file with errors, so second file should not be processed
100+ // This is the key test - we expect PHPStan to stop after the first file
101+ $ errorCount = substr_count ($ output , 'ERROR ' );
102+ $ this ->assertGreaterThan (0 , $ errorCount , 'Should have at least one error from the first file ' );
103+ } catch (Throwable $ e ) {
104+ chdir ($ originalDir );
105+ throw $ e ;
106+ }
107+ }
108+
109+ public function testStopOnFailureWithoutFlag (): void
110+ {
111+ $ originalDir = getcwd ();
112+ if ($ originalDir === false ) {
113+ throw new ShouldNotHappenException ();
114+ }
115+
116+ chdir (__DIR__ );
117+
118+ try {
119+ $ output = $ this ->runCommand (1 , [
120+ 'paths ' => [
121+ __DIR__ . DIRECTORY_SEPARATOR . 'test ' . DIRECTORY_SEPARATOR . 'file1-with-error.php ' ,
122+ __DIR__ . DIRECTORY_SEPARATOR . 'test ' . DIRECTORY_SEPARATOR . 'file2-with-error.php ' ,
123+ ],
124+ ]);
125+
126+ // Without --stop-on-failure, both files should be analyzed
127+ $ this ->assertStringContainsString ('file1-with-error.php ' , $ output );
128+ $ this ->assertStringContainsString ('file2-with-error.php ' , $ output );
129+ } catch (Throwable $ e ) {
130+ chdir ($ originalDir );
131+ throw $ e ;
132+ }
133+ }
134+
135+ public function testStopOnFailureWithConfigFile (): void
136+ {
137+ $ originalDir = getcwd ();
138+ if ($ originalDir === false ) {
139+ throw new ShouldNotHappenException ();
140+ }
141+
142+ chdir (__DIR__ );
143+
144+ try {
145+ $ output = $ this ->runCommand (1 , [
146+ '--stop-on-failure ' => true ,
147+ '--configuration ' => __DIR__ . DIRECTORY_SEPARATOR . 'test ' . DIRECTORY_SEPARATOR . 'phpstan-test.neon ' ,
148+ 'paths ' => [
149+ __DIR__ . DIRECTORY_SEPARATOR . 'test ' . DIRECTORY_SEPARATOR . 'file1-with-error.php ' ,
150+ __DIR__ . DIRECTORY_SEPARATOR . 'test ' . DIRECTORY_SEPARATOR . 'file2-with-error.php ' ,
151+ ],
152+ ]);
153+
154+ // Should have errors from the first file
155+ $ this ->assertStringContainsString ('file1-with-error.php ' , $ output );
156+
157+ // With --stop-on-failure, should stop after first file with errors
158+ $ errorCount = substr_count ($ output , 'ERROR ' );
159+ $ this ->assertGreaterThan (0 , $ errorCount , 'Should have at least one error from the first file ' );
160+ } catch (Throwable $ e ) {
161+ chdir ($ originalDir );
162+ throw $ e ;
163+ }
164+ }
165+
72166 /**
73167 * @return string[][]
74168 */
@@ -115,14 +209,18 @@ public static function autoDiscoveryPathsProvider(): array
115209 }
116210
117211 /**
118- * @param array<string, string> $parameters
212+ * @param array<string, string|string[]|bool > $parameters
119213 */
120214 private function runCommand (int $ expectedStatusCode , array $ parameters = []): string
121215 {
122216 $ commandTester = new CommandTester (new AnalyseCommand ([], microtime (true )));
123217
218+ $ defaultPaths = [__DIR__ . DIRECTORY_SEPARATOR . 'test ' ];
219+ $ paths = $ parameters ['paths ' ] ?? $ defaultPaths ;
220+ unset($ parameters ['paths ' ]);
221+
124222 $ commandTester ->execute ([
125- 'paths ' => [ __DIR__ . DIRECTORY_SEPARATOR . ' test ' ] ,
223+ 'paths ' => $ paths ,
126224 '--debug ' => true ,
127225 ] + $ parameters , ['debug ' => true ]);
128226
0 commit comments