Contrary to the rest of the WC codebase, WC CLI commands require PHP >= 5.5 and use anonymous functions. This commit excludes the PHPCombatibility rule for anonymous functions (PHPCompatibility.PHP.NewClosure.Found) when PHPCS is checking the `includes/cli` directory.
WooCommerce CLI commands use array_column() which was added in PHP 5.5. Since this was not noticed until now it is probably not worth changing and making the code compatible with PHP < 5.5.
The composer.json file in WooCommerce specifies PHPUnit version 6.2.3 as a development dependency; that version of PHPUnit sets PHP 7.0 as the minimum PHP version, effectively making the minimum development version for WooCommerce to be PHP 7.0 (hooray!).
With a more modern version of PHP as the minimum requirement for developers, the code that isn't distributed with the plugin (e.g. the /tests/ directory) doesn't necessarily need to adhere to PHP 5.2-compatible coding standards. This commit removes the /tests/ directory from the scope of the PHP Compatibility checks, enabling the test suite to leverage modern (relative to PHP 5.2, anyway) features like closures, short-array syntax, and namespaces. Embracing more modern PHP in the test suite also opens up the possibilities of using libraries like Faker to populate dummy data, rather than the hard-coded helpers that exist now.
An example test enabled by this change: developers can now use closures for filter callbacks.
add_filter( 'some_filter', function () {
return 'the filtered value';
}
$this->assertEquals( 'the filtered value', my_function() );
Without a closure, this test would need to either write a one-off method in the test class or hack around it with static properties to configure the expected filter response.
This commit renames PHPCS configutarion file to `phpcs.xml`. With the default name, it is not necessary to use the argument `--standard=phpcs.ruleset.xml` anymore when calling `phpcs`.