Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
VincentLanglet committed Nov 3, 2025
commit 1a2ab0db57cc8418d1b10902fed1eb642ac7c274
31 changes: 31 additions & 0 deletions tests/PHPStan/Rules/Pure/PureMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,37 @@ public function testBug12224(): void
]);
}

public function testAllMethodsArePure(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/all-methods-are-pure.php'], [
[
'Method AllMethodsArePure\Foo::test() is marked as pure but returns void.',
10,
],
[
'Method AllMethodsArePure\Foo::pure() is marked as pure but returns void.',
17,
],
[
'Method AllMethodsArePure\Foo::impure() is marked as impure but does not have any side effects.',
24,
],
[
'Method AllMethodsArePure\Bar::test() is marked as impure but does not have any side effects.',
34,
],
[
'Method AllMethodsArePure\Bar::pure() is marked as pure but returns void.',
41,
],
[
'Method AllMethodsArePure\Bar::impure() is marked as impure but does not have any side effects.',
48,
],
]);
}

public function testBug12382(): void
{
$this->treatPhpDocTypesAsCertain = true;
Expand Down
51 changes: 51 additions & 0 deletions tests/PHPStan/Rules/Pure/data/all-methods-are-pure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace AllMethodsArePure;

/**
* @phpstan-all-methods-pure
*/
final class Foo
{
function test(): void
{
}

/**
* @phpstan-pure
*/
function pure(): void
{
}

/**
* @phpstan-impure
*/
function impure(): void
{
}
}

/**
* @phpstan-all-methods-impure
*/
final class Bar
{
function test(): void
{
}

/**
* @phpstan-pure
*/
function pure(): void
{
}

/**
* @phpstan-impure
*/
function impure(): void
{
}
}