From 80244d878affb1d67506f1c0698a87a4d4465c9e Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Mon, 1 Jun 2020 11:23:51 +0200 Subject: [PATCH 1/2] Fix tests with Symfony 5.1 --- .travis.yml | 4 +- composer.json | 2 +- php-cs-fixer | 2 +- src/Console/Application.php | 2 +- .../CastNotation/LowercaseCastFixerTest.php | 10 ++--- .../CastNotation/ShortScalarCastFixerTest.php | 6 ++- .../Fixer/Comment/HeaderCommentFixerTest.php | 12 +++--- .../ControlStructure/YodaStyleFixerTest.php | 10 ++--- .../LanguageConstruct/IsNullFixerTest.php | 2 +- .../BinaryOperatorSpacesFixerTest.php | 2 +- ...pdocAddMissingParamAnnotationFixerTest.php | 41 +++++++++++++------ 11 files changed, 54 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1d112244d5b..66f1cee7284 100644 --- a/.travis.yml +++ b/.travis.yml @@ -83,14 +83,14 @@ jobs: <<: *STANDARD_TEST_JOB stage: Test php: 7.1 - name: 7.1 | Symfony 4.1 + name: 7.1 | Symfony ~4.1.0 env: SYMFONY_DEPRECATIONS_HELPER=disabled PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER=1 SYMFONY_VERSION="~4.1.0" - <<: *STANDARD_TEST_JOB stage: Test php: 7.2 - name: 7.2 | Symfony 5.0 + name: 7.2 | Symfony ^5.0 env: SYMFONY_DEPRECATIONS_HELPER=disabled PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER=1 SYMFONY_VERSION="^5.0" - diff --git a/composer.json b/composer.json index ee88eef79e7..781e376722d 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.1", "phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.1", "phpunitgoodpractices/traits": "^1.8", - "symfony/phpunit-bridge": "^4.3 || ^5.0", + "symfony/phpunit-bridge": "^5.1", "symfony/yaml": "^3.0 || ^4.0 || ^5.0" }, "suggest": { diff --git a/php-cs-fixer b/php-cs-fixer index 0a61d13333c..23c88b33e8b 100755 --- a/php-cs-fixer +++ b/php-cs-fixer @@ -12,7 +12,7 @@ */ if (getenv('PHP_CS_FIXER_FUTURE_MODE')) { - error_reporting(-1); + error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED); } if (defined('HHVM_VERSION_ID')) { diff --git a/src/Console/Application.php b/src/Console/Application.php index 97b4b28b6d4..55acdbe3aca 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -46,7 +46,7 @@ final class Application extends BaseApplication public function __construct() { if (!getenv('PHP_CS_FIXER_FUTURE_MODE')) { - error_reporting(-1); + error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED); } parent::__construct('PHP CS Fixer', self::VERSION); diff --git a/tests/Fixer/CastNotation/LowercaseCastFixerTest.php b/tests/Fixer/CastNotation/LowercaseCastFixerTest.php index a34faeca76c..3aa182e6614 100644 --- a/tests/Fixer/CastNotation/LowercaseCastFixerTest.php +++ b/tests/Fixer/CastNotation/LowercaseCastFixerTest.php @@ -13,6 +13,7 @@ namespace PhpCsFixer\Tests\Fixer\CastNotation; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * @author SpacePossum @@ -23,6 +24,8 @@ */ final class LowercaseCastFixerTest extends AbstractFixerTestCase { + use ExpectDeprecationTrait; + /** * @param string $expected * @param null|string $input @@ -55,14 +58,11 @@ public function testFix74($expected, $input = null) * @dataProvider provideFixDeprecatedCases * @requires PHP 7.4 * @group legacy - * @expectedDeprecation Unsilenced deprecation: The (real) cast is deprecated, use (float) instead - * @expectedDeprecation Unsilenced deprecation: The (real) cast is deprecated, use (float) instead - * @expectedDeprecation Unsilenced deprecation: The (real) cast is deprecated, use (float) instead - * @expectedDeprecation Unsilenced deprecation: The (real) cast is deprecated, use (float) instead - * @expectedDeprecation Unsilenced deprecation: The (real) cast is deprecated, use (float) instead */ public function testFix74Deprecated($expected, $input = null) { + $this->expectDeprecation('The (real) cast is deprecated, use (float) instead'); + $this->doTest($expected, $input); } diff --git a/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php b/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php index 38c5d814468..6660b2dad21 100644 --- a/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php +++ b/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php @@ -13,6 +13,7 @@ namespace PhpCsFixer\Tests\Fixer\CastNotation; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * @author SpacePossum @@ -23,6 +24,8 @@ */ final class ShortScalarCastFixerTest extends AbstractFixerTestCase { + use ExpectDeprecationTrait; + /** * @param string $expected * @param null|string $input @@ -55,10 +58,11 @@ public function testFix74($expected, $input = null) * @dataProvider provideFixDeprecatedCases * @requires PHP 7.4 * @group legacy - * @expectedDeprecation Unsilenced deprecation: The (real) cast is deprecated, use (float) instead */ public function testFix74Deprecated($expected, $input = null) { + $this->expectDeprecation('The (real) cast is deprecated, use (float) instead'); + $this->doTest($expected, $input); } diff --git a/tests/Fixer/Comment/HeaderCommentFixerTest.php b/tests/Fixer/Comment/HeaderCommentFixerTest.php index 795b4200532..841f8dc829d 100644 --- a/tests/Fixer/Comment/HeaderCommentFixerTest.php +++ b/tests/Fixer/Comment/HeaderCommentFixerTest.php @@ -517,7 +517,7 @@ public function testLegacyMisconfiguration() public function testMisconfiguration($configuration, $exceptionMessage) { $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); - $this->expectExceptionMessage('[header_comment] '.$exceptionMessage); + $this->expectExceptionMessageRegExp("#^\\[header_comment\\] {$exceptionMessage}$#"); $this->configureFixerWithAliasedOptions($configuration); } @@ -528,35 +528,35 @@ public function provideMisconfigurationCases() [[], 'Missing required configuration: The required option "header" is missing.'], [ ['header' => 1], - 'Invalid configuration: The option "header" with value 1 is expected to be of type "string", but is of type "integer".', + 'Invalid configuration: The option "header" with value 1 is expected to be of type "string", but is of type "(int|integer)"\.', ], [ [ 'header' => '', 'comment_type' => 'foo', ], - 'Invalid configuration: The option "comment_type" with value "foo" is invalid. Accepted values are: "PHPDoc", "comment".', + 'Invalid configuration: The option "comment_type" with value "foo" is invalid\. Accepted values are: "PHPDoc", "comment"\.', ], [ [ 'header' => '', 'comment_type' => new \stdClass(), ], - 'Invalid configuration: The option "comment_type" with value stdClass is invalid. Accepted values are: "PHPDoc", "comment".', + 'Invalid configuration: The option "comment_type" with value stdClass is invalid\. Accepted values are: "PHPDoc", "comment"\.', ], [ [ 'header' => '', 'location' => new \stdClass(), ], - 'Invalid configuration: The option "location" with value stdClass is invalid. Accepted values are: "after_open", "after_declare_strict".', + 'Invalid configuration: The option "location" with value stdClass is invalid\. Accepted values are: "after_open", "after_declare_strict"\.', ], [ [ 'header' => '', 'separate' => new \stdClass(), ], - 'Invalid configuration: The option "separate" with value stdClass is invalid. Accepted values are: "both", "top", "bottom", "none".', + 'Invalid configuration: The option "separate" with value stdClass is invalid\. Accepted values are: "both", "top", "bottom", "none"\.', ], ]; } diff --git a/tests/Fixer/ControlStructure/YodaStyleFixerTest.php b/tests/Fixer/ControlStructure/YodaStyleFixerTest.php index 69ac075df07..28432be5057 100644 --- a/tests/Fixer/ControlStructure/YodaStyleFixerTest.php +++ b/tests/Fixer/ControlStructure/YodaStyleFixerTest.php @@ -700,11 +700,7 @@ public function testComplexConfiguration() public function testInvalidConfig(array $config, $expectedMessage) { $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); - $this->expectExceptionMessageRegExp(sprintf( - '#^\[%s\] %s$#', - $this->fixer->getName(), - preg_quote($expectedMessage, '#') - )); + $this->expectExceptionMessageRegExp("#^\\[{$this->fixer->getName()}\\] {$expectedMessage}$#"); $this->fixer->configure($config); } @@ -715,8 +711,8 @@ public function testInvalidConfig(array $config, $expectedMessage) public function provideInvalidConfigurationCases() { return [ - [['equal' => 2], 'Invalid configuration: The option "equal" with value 2 is expected to be of type "bool" or "null", but is of type "integer".'], - [['_invalid_' => true], 'Invalid configuration: The option "_invalid_" does not exist. Defined options are: "always_move_variable", "equal", "identical", "less_and_greater".'], + [['equal' => 2], 'Invalid configuration: The option "equal" with value 2 is expected to be of type "bool" or "null", but is of type "(int|integer)"\.'], + [['_invalid_' => true], 'Invalid configuration: The option "_invalid_" does not exist\. Defined options are: "always_move_variable", "equal", "identical", "less_and_greater"\.'], ]; } diff --git a/tests/Fixer/LanguageConstruct/IsNullFixerTest.php b/tests/Fixer/LanguageConstruct/IsNullFixerTest.php index 2941dadb366..88eb1335ffd 100644 --- a/tests/Fixer/LanguageConstruct/IsNullFixerTest.php +++ b/tests/Fixer/LanguageConstruct/IsNullFixerTest.php @@ -40,7 +40,7 @@ public function testConfigurationWrongOption() public function testConfigurationWrongValue() { $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); - $this->expectExceptionMessage('[is_null] Invalid configuration: The option "use_yoda_style" with value -1 is expected to be of type "bool", but is of type "integer".'); + $this->expectExceptionMessageRegExp('#^\[is_null\] Invalid configuration: The option "use_yoda_style" with value -1 is expected to be of type "bool", but is of type "(int|integer)"\.$#'); $this->fixer->configure(['use_yoda_style' => -1]); } diff --git a/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php b/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php index ffacfcb2ce9..7f58ea3ef9e 100644 --- a/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php +++ b/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php @@ -911,7 +911,7 @@ public function testWrongConfigTypeForOperators() { $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); $this->expectExceptionMessageRegExp( - '/^\[binary_operator_spaces\] Invalid configuration: The option "operators" with value true is expected to be of type "array", but is of type "boolean"\.$/' + '/^\[binary_operator_spaces\] Invalid configuration: The option "operators" with value true is expected to be of type "array", but is of type "(bool|boolean)"\.$/' ); $this->fixer->configure(['operators' => true]); diff --git a/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php b/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php index 52ba02da5b3..915472f387c 100644 --- a/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php @@ -42,15 +42,13 @@ public function testConfigureRejectsUnknownConfigurationKey() /** * @dataProvider provideConfigureRejectsInvalidConfigurationValueCases * - * @param mixed $value + * @param mixed $value + * @param string $expectedMessage */ - public function testConfigureRejectsInvalidConfigurationValue($value) + public function testConfigureRejectsInvalidConfigurationValue($value, $expectedMessage) { $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class); - $this->expectExceptionMessage(sprintf( - 'expected to be of type "bool", but is of type "%s".', - \is_object($value) ? \get_class($value) : \gettype($value) - )); + $this->expectExceptionMessageRegExp($expectedMessage); $this->fixer->configure([ 'only_untyped' => $value, @@ -58,16 +56,33 @@ public function testConfigureRejectsInvalidConfigurationValue($value) } /** - * @return array + * @return iterable */ public function provideConfigureRejectsInvalidConfigurationValueCases() { - return [ - 'null' => [null], - 'int' => [1], - 'array' => [[]], - 'float' => [0.1], - 'object' => [new \stdClass()], + yield 'null' => [ + null, + '#expected to be of type "bool", but is of type "(null|NULL)"\.$#', + ]; + + yield 'int' => [ + 1, + '#expected to be of type "bool", but is of type "(int|integer)"\.$#', + ]; + + yield 'array' => [ + [], + '#expected to be of type "bool", but is of type "array"\.$#', + ]; + + yield 'float' => [ + 0.1, + '#expected to be of type "bool", but is of type "(float|double)"\.$#', + ]; + + yield 'object' => [ + new \stdClass(), + '#expected to be of type "bool", but is of type "stdClass"\.$#', ]; } From 10dc54f9ccee8b99d18c46ece417707077676e66 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Wed, 3 Jun 2020 08:43:43 +0200 Subject: [PATCH 2/2] Update ShellCheck download URL --- dev-tools/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-tools/install.sh b/dev-tools/install.sh index 6d82bdf544a..f72e722fcd5 100755 --- a/dev-tools/install.sh +++ b/dev-tools/install.sh @@ -32,7 +32,7 @@ bin/checkbashisms --version echo λλλ shellcheck if [ ! -x bin/shellcheck ]; then - wget -qO- "https://storage.googleapis.com/shellcheck/shellcheck-${VERSION_SC}.linux.x86_64.tar.xz" \ + wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${VERSION_SC}/shellcheck-${VERSION_SC}.linux.x86_64.tar.xz" \ | tar -xJv -O shellcheck-${VERSION_SC}/shellcheck \ > bin/shellcheck chmod u+x bin/shellcheck