1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

create real path for Psalm to stop ignoring suppressions

This commit is contained in:
orklah 2021-08-19 19:31:58 +02:00
parent 3e236fc2fe
commit 7fd0d5f28e
3 changed files with 22 additions and 19 deletions

View File

@ -17,7 +17,7 @@ class IssueSuppressionTest extends TestCase
$this->expectExceptionMessage('UnusedPsalmSuppress'); $this->expectExceptionMessage('UnusedPsalmSuppress');
$this->addFile( $this->addFile(
'somefile.php', getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php',
'<?php '<?php
class A { class A {
/** /**
@ -32,7 +32,7 @@ class IssueSuppressionTest extends TestCase
}' }'
); );
$this->analyzeFile('somefile.php', new \Psalm\Context()); $this->analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', new \Psalm\Context());
} }
public function testIssueSuppressedOnStatement(): void public function testIssueSuppressedOnStatement(): void
@ -41,13 +41,13 @@ class IssueSuppressionTest extends TestCase
$this->expectExceptionMessage('UnusedPsalmSuppress'); $this->expectExceptionMessage('UnusedPsalmSuppress');
$this->addFile( $this->addFile(
'somefile.php', getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php',
'<?php '<?php
/** @psalm-suppress InvalidArgument */ /** @psalm-suppress InvalidArgument */
echo strlen("hello");' echo strlen("hello");'
); );
$this->analyzeFile('somefile.php', new \Psalm\Context()); $this->analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', new \Psalm\Context());
} }
public function testUnusedSuppressAllOnFunction(): void public function testUnusedSuppressAllOnFunction(): void
@ -55,8 +55,9 @@ class IssueSuppressionTest extends TestCase
$this->expectException(\Psalm\Exception\CodeException::class); $this->expectException(\Psalm\Exception\CodeException::class);
$this->expectExceptionMessage('UnusedPsalmSuppress'); $this->expectExceptionMessage('UnusedPsalmSuppress');
$this->addFile( $this->addFile(
'somefile.php', getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php',
'<?php '<?php
/** @psalm-suppress all */ /** @psalm-suppress all */
function foo(): string { function foo(): string {
@ -64,7 +65,7 @@ class IssueSuppressionTest extends TestCase
}' }'
); );
$this->analyzeFile('somefile.php', new \Psalm\Context()); $this->analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', new \Psalm\Context());
} }
public function testUnusedSuppressAllOnStatement(): void public function testUnusedSuppressAllOnStatement(): void
@ -73,13 +74,12 @@ class IssueSuppressionTest extends TestCase
$this->expectExceptionMessage('UnusedPsalmSuppress'); $this->expectExceptionMessage('UnusedPsalmSuppress');
$this->addFile( $this->addFile(
'somefile.php', getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php',
'<?php '<?php
/** @psalm-suppress all */ /** @psalm-suppress all */
print("foo");' print("foo");'
); );
$this->analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', new \Psalm\Context());
$this->analyzeFile('somefile.php', new \Psalm\Context());
} }
public function testMissingThrowsDocblockSuppressed(): void public function testMissingThrowsDocblockSuppressed(): void
@ -87,7 +87,7 @@ class IssueSuppressionTest extends TestCase
Config::getInstance()->check_for_throws_docblock = true; Config::getInstance()->check_for_throws_docblock = true;
$this->addFile( $this->addFile(
'somefile.php', getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php',
'<?php '<?php
function example1 (): void { function example1 (): void {
/** @psalm-suppress MissingThrowsDocblock */ /** @psalm-suppress MissingThrowsDocblock */
@ -104,7 +104,7 @@ class IssueSuppressionTest extends TestCase
$context = new Context(); $context = new Context();
$this->analyzeFile('somefile.php', $context); $this->analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', $context);
} }
public function testMissingThrowsDocblockSuppressedWithoutThrow(): void public function testMissingThrowsDocblockSuppressedWithoutThrow(): void
@ -114,7 +114,7 @@ class IssueSuppressionTest extends TestCase
Config::getInstance()->check_for_throws_docblock = true; Config::getInstance()->check_for_throws_docblock = true;
$this->addFile( $this->addFile(
'somefile.php', getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php',
'<?php '<?php
/** @psalm-suppress MissingThrowsDocblock */ /** @psalm-suppress MissingThrowsDocblock */
if (rand(0, 1)) { if (rand(0, 1)) {
@ -124,7 +124,7 @@ class IssueSuppressionTest extends TestCase
$context = new Context(); $context = new Context();
$this->analyzeFile('somefile.php', $context); $this->analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', $context);
} }
public function testMissingThrowsDocblockSuppressedDuplicate(): void public function testMissingThrowsDocblockSuppressedDuplicate(): void
@ -134,7 +134,7 @@ class IssueSuppressionTest extends TestCase
Config::getInstance()->check_for_throws_docblock = true; Config::getInstance()->check_for_throws_docblock = true;
$this->addFile( $this->addFile(
'somefile.php', getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php',
'<?php '<?php
/** @psalm-suppress MissingThrowsDocblock */ /** @psalm-suppress MissingThrowsDocblock */
function example1 (): void { function example1 (): void {
@ -145,7 +145,7 @@ class IssueSuppressionTest extends TestCase
$context = new Context(); $context = new Context();
$this->analyzeFile('somefile.php', $context); $this->analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', $context);
} }
public function testUncaughtThrowInGlobalScopeSuppressed(): void public function testUncaughtThrowInGlobalScopeSuppressed(): void
@ -153,7 +153,7 @@ class IssueSuppressionTest extends TestCase
Config::getInstance()->check_for_throws_in_global_scope = true; Config::getInstance()->check_for_throws_in_global_scope = true;
$this->addFile( $this->addFile(
'somefile.php', getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php',
'<?php '<?php
/** @psalm-suppress UncaughtThrowInGlobalScope */ /** @psalm-suppress UncaughtThrowInGlobalScope */
throw new Exception(); throw new Exception();
@ -171,7 +171,7 @@ class IssueSuppressionTest extends TestCase
$context = new Context(); $context = new Context();
$this->analyzeFile('somefile.php', $context); $this->analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', $context);
} }
public function testUncaughtThrowInGlobalScopeSuppressedWithoutThrow(): void public function testUncaughtThrowInGlobalScopeSuppressedWithoutThrow(): void
@ -181,7 +181,7 @@ class IssueSuppressionTest extends TestCase
Config::getInstance()->check_for_throws_in_global_scope = true; Config::getInstance()->check_for_throws_in_global_scope = true;
$this->addFile( $this->addFile(
'somefile.php', getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php',
'<?php '<?php
/** @psalm-suppress UncaughtThrowInGlobalScope */ /** @psalm-suppress UncaughtThrowInGlobalScope */
echo "hello";' echo "hello";'
@ -189,7 +189,7 @@ class IssueSuppressionTest extends TestCase
$context = new Context(); $context = new Context();
$this->analyzeFile('somefile.php', $context); $this->analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', $context);
} }
/** /**

View File

@ -47,6 +47,7 @@ class TestConfig extends Config
return '<?xml version="1.0"?> return '<?xml version="1.0"?>
<projectFiles> <projectFiles>
<directory name="src" /> <directory name="src" />
<file name="tests/somefile.php" />
<ignoreFiles> <ignoreFiles>
<directory name="src/Psalm/Internal/Stubs" /> <directory name="src/Psalm/Internal/Stubs" />
</ignoreFiles> </ignoreFiles>

2
tests/somefile.php Normal file
View File

@ -0,0 +1,2 @@
<?php
//placeholder file to have a real file when analysing tests