Steps to replicate the issue (include links if applicable):
- Install packages: composer require squizlabs/php_codesniffer mediawiki/mediawiki-codesniffer dealerdirect/phpcodesniffer-composer-installer
- Create files:
<?xml version="1.0"?> <ruleset> <rule ref="MediaWiki.PHPUnit.AssertionOrder" /> </ruleset>
<?php use PHPUnit\Framework\TestCase; class Test extends TestCase { function test() { $this->assertEquals( $array, [ 'a', 'b', 'c' ] ); $this->assertEquals( $array, array( 'a', 'b', 'c' ) ); $this->assertEquals( $array, array( 'a' => 'b' ) ); $this->assertEquals( $array, [ 'a', 'b', 'c' ], 'message' ); $this->assertEquals( $array, array( 'a', 'b', 'c' ), 'message' ); $this->assertEquals( $array, array( 'a' => 'b' ), 'message' ); } }
- Run phpcbf on the file.
What happens?:
File is now
<?php use PHPUnit\Framework\TestCase; class Test extends TestCase { function test() { $this->assertEquals( [ 'a', 'b', 'c' ], $array ); $this->assertEquals( array( 'a', $array, 'b', 'c' ) ); $this->assertEquals( array( 'a' => 'b' ), $array ); $this->assertEquals( [ 'a', 'b', 'c' ], $array, 'message' ); $this->assertEquals( array( 'a', $array, 'b', 'c' ), 'message' ); $this->assertEquals( array( 'a' => 'b' ), $array, 'message' ); } }
What should have happened instead?:
File is now
<?php use PHPUnit\Framework\TestCase; class Test extends TestCase { function test() { $this->assertEquals( [ 'a', 'b', 'c' ], $array ); $this->assertEquals( array( 'a', 'b', 'c' ), $array ); $this->assertEquals( array( 'a' => 'b' ), $array ); $this->assertEquals( [ 'a', 'b', 'c' ], $array, 'message' ); $this->assertEquals( array( 'a', 'b', 'c' ), $array, 'message' ); $this->assertEquals( array( 'a' => 'b' ), $array, 'message' ); } }
Software version (skip for WMF-hosted wikis like Wikipedia): phpcs 3.7.2, mediawiki/mediawiki-codesniffer 41.0.0
Other information (browser name/version, screenshots, etc.):
Note that we are a third-party user of this package, and our coding standards (which are beyond my control) require that we use array( ... ) rather than [ ... ].
Looks like the sniff needs to also consider T_ARRAY in addition to T_OPEN_SHORT_ARRAY (and use parenthesis_closer instead of bracket_closer for the former, of course), and then T_CLOSE_PARENTHESIS in addition to T_CLOSE_SHORT_ARRAY as well.