Browse Source

Merge branch '2.2' into 2.3

# Conflicts:
#	tests/Cache/FileHandlerTest.php
#	tests/Console/Command/ReadmeCommandTest.php
#	tests/Console/ConfigurationResolverTest.php
#	tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php
#	tests/Fixer/Alias/RandomApiMigrationFixerTest.php
#	tests/Fixer/FunctionNotation/ReturnTypeDeclarationFixerTest.php
#	tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php
Dariusz Ruminski 7 years ago
parent
commit
e5aa3fb24e

+ 3 - 3
src/Console/ConfigurationResolver.php

@@ -418,7 +418,7 @@ final class ConfigurationResolver
                 $formats = $reporterFactory->getFormats();
                 sort($formats);
 
-                throw new InvalidConfigurationException(sprintf('The format "%s" is not defined, supported are %s.', $format, implode(', ', $formats)));
+                throw new InvalidConfigurationException(sprintf('The format "%s" is not defined, supported are "%s".', $format, implode('", "', $formats)));
             }
         }
 
@@ -699,9 +699,9 @@ final class ConfigurationResolver
             true
         )) {
             throw new InvalidConfigurationException(sprintf(
-                'The path-mode "%s" is not defined, supported are %s.',
+                'The path-mode "%s" is not defined, supported are "%s".',
                 $this->options['path-mode'],
-                implode(', ', $modes)
+                implode('", "', $modes)
             ));
         }
 

+ 1 - 1
tests/Cache/FileHandlerTest.php

@@ -104,7 +104,7 @@ final class FileHandlerTest extends TestCase
 
         $this->setExpectedExceptionRegExp(\Symfony\Component\Filesystem\Exception\IOException::class, sprintf(
             '#^Failed to write file "%s"(, ".*")?.#',
-            preg_quote($file)
+            preg_quote($file, '#')
         ));
 
         $cache = new Cache(new Signature(

+ 25 - 10
tests/Console/Command/ReadmeCommandTest.php

@@ -16,6 +16,7 @@ use PhpCsFixer\Console\Application;
 use PHPUnit\Framework\TestCase;
 use Symfony\Component\Console\Input\ArrayInput;
 use Symfony\Component\Console\Output\BufferedOutput;
+use Symfony\Component\Console\Output\OutputInterface;
 
 /**
  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
@@ -28,20 +29,34 @@ final class ReadmeCommandTest extends TestCase
 {
     public function testIfReadmeFileIsCorrect()
     {
-        if (!class_exists(\Symfony\Component\Console\Output\BufferedOutput::class)) {
-            $this->markTestSkipped('Unsupported symfony/console version, Symfony\Component\Console\Output\BufferedOutput was added in 2.4.');
-        }
+        $readmeFile = __DIR__.'/../../../README.rst';
+        $this->assertFileExists($readmeFile, sprintf('README file "%s" not found.', $readmeFile)); // switch to `assertFileIsReadable` on PHPUnit6
+        $this->assertTrue(is_readable($readmeFile), sprintf('Cannot read "%s".', $readmeFile));
+        $this->assertTrue(is_file($readmeFile), sprintf('Expected file "%s" to be a file.', $readmeFile));
+        $fileContent = file_get_contents($readmeFile);
+        $this->assertInternalType('string', $fileContent, sprintf('Failed to get content of "%s"', $readmeFile));
 
-        $input = new ArrayInput(['readme']);
-        $output = new BufferedOutput();
         $app = new Application();
+        $input = new ArrayInput(['readme']);
 
-        $app->get('readme')->run($input, $output);
-
-        $fileContent = file_get_contents(__DIR__.'/../../../README.rst');
+        $output = new BufferedOutput();
+        $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
+        $output->setDecorated(false);
+
+        $exitCode = $app->get('readme')->run($input, $output);
+        $output = $output->fetch();
+        // normalize line breaks, these are not important for the tests
+        $output = str_replace(PHP_EOL, "\n", $output);
+
+        $this->assertSame(
+            0,
+            $exitCode,
+            sprintf("readme command did not exit successfully.\n%s", $output)
+        );
 
-        $this->assertTrue(
-            $output->fetch() === $fileContent,
+        $this->assertSame(
+            $output,
+            $fileContent,
             'README.rst file is not up to date! Do not modify it manually! Regenerate readme with command: `php php-cs-fixer readme > README.rst`.'
         );
     }

+ 3 - 3
tests/Console/ConfigurationResolverTest.php

@@ -294,7 +294,7 @@ final class ConfigurationResolverTest extends TestCase
     {
         $this->setExpectedExceptionRegExp(
             \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class,
-            '#^The config file: ".+[\/\\\]Fixtures[\/\\\]ConfigurationResolverConfigFile[\/\\\]case_5[\/\\\]\.php_cs.dist" does not return a "PhpCsFixer\\\ConfigInterface" instance\. Got: "string"\.$#'
+            '#^The config file: ".+[\/\\\]Fixtures[\/\\\]ConfigurationResolverConfigFile[\/\\\]case_5[\/\\\]\.php_cs\.dist" does not return a "PhpCsFixer\\\ConfigInterface" instance\. Got: "string"\.$#'
         );
 
         $dirBase = $this->getFixtureDir();
@@ -312,7 +312,7 @@ final class ConfigurationResolverTest extends TestCase
     {
         $this->setExpectedExceptionRegExp(
             \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class,
-            '/^The format "xls" is not defined, supported are json, junit, txt, xml.$/'
+            '/^The format "xls" is not defined, supported are "json", "junit", "txt", "xml"\.$/'
         );
 
         $dirBase = $this->getFixtureDir();
@@ -330,7 +330,7 @@ final class ConfigurationResolverTest extends TestCase
     {
         $this->setExpectedExceptionRegExp(
             \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class,
-            '/^For multiple paths config parameter is required.$/'
+            '/^For multiple paths config parameter is required\.$/'
         );
 
         $dirBase = $this->getFixtureDir();

+ 4 - 4
tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php

@@ -312,19 +312,19 @@ final class NoMixedEchoPrintFixerTest extends AbstractFixerTestCase
         return [
             [
                 ['a' => 'b'],
-                '#^\[no_mixed_echo_print\] Invalid configuration: The option "a" does not exist\. Defined options are: "use"\.$#',
+                '#^\[no_mixed_echo_print\] Invalid configuration: The option "a" does not exist\. (Known|Defined) options are: "use"\.$#',
             ],
             [
                 ['a' => 'b', 'b' => 'c'],
-                '#^\[no_mixed_echo_print\] Invalid configuration: The options "a", "b" do not exist\. Defined options are: "use"\.$#',
+                '#^\[no_mixed_echo_print\] Invalid configuration: The options "a", "b" do not exist\. (Known|Defined) options are: "use"\.$#',
             ],
             [
                 [1],
-                '#^\[no_mixed_echo_print\] Invalid configuration: The option "0" does not exist\. Defined options are: "use"\.$#',
+                '#^\[no_mixed_echo_print\] Invalid configuration: The option "0" does not exist\. (Known|Defined) options are: "use"\.$#',
             ],
             [
                 ['use' => '_invalid_'],
-                '#^\[no_mixed_echo_print\] Invalid configuration: The option "use" with value "_invalid_" is invalid\. Accepted values are: "print", "echo".$#',
+                '#^\[no_mixed_echo_print\] Invalid configuration: The option "use" with value "_invalid_" is invalid\. Accepted values are: "print", "echo"\.$#',
             ],
         ];
     }

+ 2 - 2
tests/Fixer/Alias/RandomApiMigrationFixerTest.php

@@ -28,7 +28,7 @@ final class RandomApiMigrationFixerTest extends AbstractFixerTestCase
     {
         $this->setExpectedExceptionRegExp(
             \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class,
-            '#^\[random_api_migration\] Invalid configuration: Function "is_null" is not handled by the fixer.$#'
+            '#^\[random_api_migration\] Invalid configuration: Function "is_null" is not handled by the fixer\.$#'
         );
 
         $this->fixer->configure(['replacements' => ['is_null' => 'random_int']]);
@@ -38,7 +38,7 @@ final class RandomApiMigrationFixerTest extends AbstractFixerTestCase
     {
         $this->setExpectedExceptionRegExp(
             \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class,
-            '#^\[random_api_migration\] Invalid configuration: Replacement for function "rand" must be a string, "NULL" given.$#'
+            '#^\[random_api_migration\] Invalid configuration: Replacement for function "rand" must be a string, "NULL" given\.$#'
         );
 
         $this->fixer->configure(['replacements' => ['rand' => null]]);

+ 1 - 1
tests/Fixer/FunctionNotation/ReturnTypeDeclarationFixerTest.php

@@ -28,7 +28,7 @@ final class ReturnTypeDeclarationFixerTest extends AbstractFixerTestCase
     {
         $this->setExpectedExceptionRegExp(
             \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class,
-            '#^\[return_type_declaration\] Invalid configuration: The option "s" does not exist. Defined options are: "space_before".$#'
+            '#^\[return_type_declaration\] Invalid configuration: The option "s" does not exist\. (Known|Defined) options are: "space_before"\.$#'
         );
 
         $this->fixer->configure(['s' => 9000]);

+ 1 - 1
tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php

@@ -376,7 +376,7 @@ $b;',
     {
         $this->setExpectedExceptionRegExp(
             \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class,
-            '/^\[binary_operator_spaces\] Invalid configuration: The option "align_double_arrow" with value 123 is invalid. Accepted values are: true, false, null\.$/'
+            '/^\[binary_operator_spaces\] Invalid configuration: The option "align_double_arrow" with value 123 is invalid\. Accepted values are: true, false, null\.$/'
         );
 
         $this->fixer->configure(['align_double_arrow' => 123]);