Php-cs-fixer: Fixer for PHPUnit's @expectedException annotation is using deprecated setExpectedException()

Created on 14 Nov 2018  路  1Comment  路  Source: FriendsOfPHP/PHP-CS-Fixer

Hi,

As the title says, the fixer is introducing deprecations from PhpUnit. i did check this issue #2501 which is closed already. There was a comment also about this same problem but i guess it did not received proper attention. Thats why i am creating a new issue here.

Thanks in advance,
Regards,
David

When reporting an issue (bug) please provide the following information:

The PHP version you are using ($ php -v):

=> PHP 7.2.12-1+ubuntu16.04.1+deb.sury.org+1 (cli)

PHP CS Fixer version you are using ($ php-cs-fixer -V):

=> PHP CS Fixer 2.13.1 Yogi's BBQ by Fabien Potencier and Dariusz Ruminski (54814c6)

The command you use to run PHP CS Fixer:

=> php php-cs-fixer.phar fix --quiet --dry-run --config=.php-cs-fixer

The configuration file you are using, if any:

<?php

return PhpCsFixer\Config::create()
    ->setUsingCache(true)->setCacheFile(__DIR__.'/.ci/build/cache/.php_cs.cache')

    ->setRiskyAllowed(true)->setRules([
        '@Symfony'                           => true,
        '@Symfony:risky'                     => true,
        '@PHP71Migration'                    => true,
        '@PHP71Migration:risky'              => true,

        'header_comment'                     => ['header' => ''],
        'declare_strict_types'               => true,
        'array_syntax'                       => array('syntax' => 'short'),
        'yoda_style'                         => false,
        'binary_operator_spaces'             => array('operators' => ['=>' => null]),

        'strict_comparison'                  => true,
        'strict_param'                       => true,
        'dir_constant'                       => true,
        'php_unit_strict'                    => true,
        'php_unit_no_expectation_annotation' => true,
        'php_unit_ordered_covers'            => true,
        'is_null'                            => true,
        'function_to_constant'               => true,
        'ordered_imports'                    => true,
        'not_operator_with_successor_space'  => true,
        'combine_consecutive_issets'         => true,
        'combine_consecutive_unsets'         => true,
        'escape_implicit_backslashes'        => true,
        'no_superfluous_elseif'              => true,
        'no_useless_else'                    => true,
        'static_lambda'                      => true,
        'compact_nullable_typehint'          => true,
        'combine_consecutive_issets'         => true,
        'combine_consecutive_unsets'         => true,
    ])

    ->setFinder(PhpCsFixer\Finder::create()->in([
        __DIR__ . '/packages/*/src',
        __DIR__ . '/packages/*/test',
        __DIR__ . '/packages/*/database/migrations',
    ]));

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
/**
 * @expectedException \Assert\InvalidArgumentException
 */
 public function testFixer(): void
 {
      Assertion::notNull(null);
 }
  • with unexpected changes applied when running PHP CS Fixer:
public function testFixer(): void
{
    $this->setExpectedException(\Assert\InvalidArgumentException::class);

    Assertion::notNull(null);
}
  • with the changes you expected instead:
public function testFixer(): void
{
    $this->expectException(\Assert\InvalidArgumentException::class);

    Assertion::notNull(null);
}
kinquestion

Most helpful comment

it's using setExpectedException as it doesn't know which PHPUnit you are willing to use

add php_unit_expectation to your ruleset:

Usages of ->setExpectedException* methods MUST be replaced by ->expectException* methods.

>All comments

it's using setExpectedException as it doesn't know which PHPUnit you are willing to use

add php_unit_expectation to your ruleset:

Usages of ->setExpectedException* methods MUST be replaced by ->expectException* methods.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

OskarStark picture OskarStark  路  3Comments

EvgenyOrekhov picture EvgenyOrekhov  路  3Comments

aidantwoods picture aidantwoods  路  3Comments

Bilge picture Bilge  路  3Comments

ro0NL picture ro0NL  路  3Comments