5
5
use Nette \Utils \Json ;
6
6
use PHPUnit \Framework \TestCase ;
7
7
use function chdir ;
8
- use function file_put_contents ;
9
8
use function getcwd ;
10
9
11
10
/**
@@ -24,9 +23,8 @@ public function testErrorWithTrait(): void
24
23
25
24
public function testGenerateBaselineAndRunAgainWithIt (): void
26
25
{
27
- $ output = $ this ->runPhpStan (__DIR__ . '/data/ ' , __DIR__ . '/empty.neon ' , 'baselineNeon ' );
28
26
$ baselineFile = __DIR__ . '/../../../../baseline.neon ' ;
29
- file_put_contents ( $ baselineFile , $ output );
27
+ $ output = $ this -> runPhpStan ( __DIR__ . ' /data/ ' , __DIR__ . ' /empty.neon ' , ' json ' , $ baselineFile );
30
28
31
29
$ output = $ this ->runPhpStan (__DIR__ . '/data/ ' , $ baselineFile );
32
30
@unlink ($ baselineFile );
@@ -54,7 +52,8 @@ public function testRunUnixFileWithWindowsBaseline(): void
54
52
private function runPhpStan (
55
53
string $ analysedPath ,
56
54
?string $ configFile ,
57
- string $ errorFormatter = 'json '
55
+ string $ errorFormatter = 'json ' ,
56
+ ?string $ baselineFile = null
58
57
): string
59
58
{
60
59
$ originalDir = getcwd ();
@@ -67,7 +66,7 @@ private function runPhpStan(
67
66
throw new \PHPStan \ShouldNotHappenException ('Could not clear result cache. ' );
68
67
}
69
68
70
- exec (sprintf ('%s %s analyse --no-progress --error-format=%s --level=7 %s %s ' , escapeshellarg (PHP_BINARY ), 'bin/phpstan ' , $ errorFormatter , $ configFile !== null ? '--configuration ' . escapeshellarg ($ configFile ) : '' , escapeshellarg ($ analysedPath )), $ outputLines );
69
+ exec (sprintf ('%s %s analyse --no-progress --error-format=%s --level=7 %s %s%s ' , escapeshellarg (PHP_BINARY ), 'bin/phpstan ' , $ errorFormatter , $ configFile !== null ? '--configuration ' . escapeshellarg ($ configFile ) : '' , escapeshellarg ($ analysedPath ), $ baselineFile !== null ? ' --generate-baseline ' . escapeshellarg ( $ baselineFile ) : '' ), $ outputLines );
71
70
chdir ($ originalDir );
72
71
73
72
return implode ("\n" , $ outputLines );
0 commit comments