Skip to content

1.0.0

Choose a tag to compare

@alies-dev alies-dev released this 10 Nov 13:28
e6cea62

Upgrading from 0.2X

  • Requirements: PHP 8.2, PHPUnit 11 and Psalm 7.2 or newer. Projects on PHP 8.1, PHPUnit 10 or Psalm 6 keep using 0.22, which still gets bug fixes.
  • PHPUnit 12 and newer ignore metadata in docblocks, and so does the plugin: @test, @dataProvider, @covers and the other tags are reported as IgnoredDocblockMetadata, which names the attribute to use (#[Test], #[DataProvider], #[CoversClass], ...). They no longer make a method a test or a data provider.
  • Data providers are checked more closely:
    • string-keyed datasets are matched to the test parameters by name (InvalidNamedArgument, TooFewArguments);
    • providers with only a native return type (: iterable, : array, : \Generator) have their datasets checked against the type Psalm infers from the provider's body. Where that is not possible they are reported as MixedReturnStatement, asking for a @return type.
  • New issues:
    • UnspecificEqualsAssertion, UnspecificNullAssertion, UnspecificBooleanAssertion and UnspecificCountAssertion (errorLevel="1" only) suggest assertSame() over assertEquals() for two values of one scalar type, and assertNull(), assertTrue() / assertFalse() and assertCount() over assertSame();
    • MissingParentCall reports setUp(), tearDown() and the other hook overrides that never call parent::;
    • InvalidPhpUnitAnnotation reports docblock tags that PHPUnit drops (/** @dataProvider*/, @group(slow));
    • UndefinedClass, UndefinedMethod and UndefinedFunction report missing #[Covers*] / @covers targets and ->method('typo') on mocks.

UnspecificEqualsAssertion can be numerous in older test suites. Rector's AssertEqualsToSameRector fixes it, or it can be turned off:

<issueHandlers>
    <PluginIssue name="UnspecificEqualsAssertion" errorLevel="suppress"/>
</issueHandlers>

What's Changed

Requirements

  • Require PHP 8.2 and PHPUnit 11 (#202)
  • Drop code for PHPUnit versions before 11 (#204)
  • Report docblock metadata that PHPUnit 12 ignores (#210)

New checks

  • Suggest assertNull(), assertTrue() / assertFalse() and assertCount() over assertSame() (#198)
  • Suggest assertSame() over assertEquals() for two values of one scalar type (#208)
  • Suggest assertTrue() / assertFalse() over assertEquals(true|false, ...) (#233)
  • Type createMockForIntersectionOfInterfaces() and createStubForIntersectionOfInterfaces() (#207)
  • Support #[DataProviderExternal] (#211)
  • Report undefined methods in ->method('...') on mocks (#212)
  • Report undefined methods in ->method('...') on unions of mocks (#231)
  • Report setUp() and tearDown() overrides that don't call the parent (#215)
  • Report assertPreConditions() and assertPostConditions() overrides that don't call the parent (#229)
  • Match string-keyed datasets to test parameters by name (#213)
  • Report string-keyed datasets combined with a dependency that passes a value (#236)
  • Report positional dataset entries after named ones (#238)
  • Narrow test parameter types from data providers (#225)
  • Check that #[Covers*] and @covers targets exist (#224)
  • Check datasets of #[DataProviderClosure] providers (#242)
  • Check datasets of providers without a @return type (#275)
  • Report prophesize() without ProphecyTrait (#258)
  • Report #[DataProvider('Other::method')] as an undefined provider, like PHPUnit (#235)
  • Report malformed PHPUnit annotations instead of a missing provider (#209)
  • Report malformed PHPUnit annotations in the class docblocks of used traits (#234)
  • Honour @psalm-suppress for data provider and dataset issues (#257)
  • Ignore the docblock of a method that has any PHPUnit attribute (#263)

Fixes

  • Read PHPUnit tags in docblocks that also have an unknown @psalm tag (#232)
  • Report non-static providers implemented by a child of an abstract test case (#241)
  • Report assertion suggestions in either argument order (#253)
  • Don't report methods PHPUnit runs as hooks as unused (#259)
  • Honour setUp() and #[Before] from traits for MissingConstructor (#260)
  • Don't check data providers of non-public test methods (#261)
  • Check providers typed iterable<V> or Generator<V> (#262)
  • Fix TooFewArguments for list<T> datasets (#264)
  • Report provider arguments that need a coercion as ArgumentTypeCoercion (#265)
  • Expand imported type aliases in provider checks (#266)
  • Report mixed dataset values as MixedArgument (#271)
  • Don't report InvalidArgument for test parameters typed with the method's own templates (#270)
  • Don't report MixedArgumentTypeCoercion for closure parameters typed with the method's own templates (#277)

Development

  • Move 1.x development to master (#228)
  • Use assertSame() in external provider fixtures (#230)
  • Bump prophecy-phpunit and php_codesniffer dev constraints (#237)
  • Split TestCase.feature into one feature file per area (#243)
  • Build the Behat config in Context instead of copying it into every scenario (#254)
  • Lint the Behat scenarios for checks that silently assert nothing (#255)
  • Replace PHP_CodeSniffer with PHP-CS-Fixer (#273)
  • Apply PHP-CS-Fixer (#276)

Full Changelog: 0.22.2...1.0.0