Skip to content

Conversation

IanDelMar
Copy link
Contributor

Changes

  • Reorganised tests by purpose - return types (@phpstan-return), parameter types (@phpstan-param), assertions (@phpstan-assert, @phpstan-assert-if-true, @phpstan-assert-if-false), pure functions (@phpstan-pure), and impure functions (@phpstan-impure). Each test purpose now has its own test class and its own data directory. By default, each test is configured via tests/phpstan.neon.
  • Simplified data inclusion for type-inference tests by gathering test data from a directory rather than from individual files. Test data will now be discovered automatically as soon as it is placed in the respective data directory. For example, a file containing return-type inference will be included in ReturnTypeTest when placed in tests/data/return. It is no longer necessary to add a separate line yield from $this->gatherAssertTypes($file) for each file.
  • Added a test for pure functions (some additions to the functionMap.php including test data will follow in a subsequent PR).
  • Added files demonstrating how to test pure/impure functions.
  • Added level: max to the default configuration.

Most of the changes are file moves from tests/data to the new purpose-specific directories (e.g. tests/data/return). No changes to the test data have been made. No changes to the functionMap.php have been made.

Reasoning

  • Grouping tests by purpose improves readability and maintenance, aligning the test structure with what is being verified (return types, parameter types, assertions, purity).
  • Directory-based discovery reduces boilerplate and the risk of forgetting to "register" new files; contributors can add files without touching the test harness.
  • Separating pure from impure tests is necessary because pure checks require a distinct PHPStan configuration (tests/data/pure/forget-possibly-impure-values.neon) that configures PHPStan to forget possibly impure values.
  • Setting level: max ensures the suite runs under the strictest diagnostics, catching anything possible early and makes the level explicit.

@IanDelMar
Copy link
Contributor Author

These errors do not occur for me under PHP 8.4. I'll look into this.

@szepeviktor
Copy link
Member

My beloved data inclusion!

@IanDelMar
Copy link
Contributor Author

My beloved data inclusion!

Would you like me to revise that part? I find it more convenient not to include each file individually.

@szepeviktor
Copy link
Member

It would be too good without tests also.

@szepeviktor szepeviktor merged commit b8c3ff0 into php-stubs:master Aug 26, 2025
7 checks passed
@IanDelMar IanDelMar deleted the tests branch August 26, 2025 18:46
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants