Просмотр исходного кода

Add support for PHPUnit 6, drop PHPUnit 4

Dariusz Ruminski 7 лет назад
Родитель
Сommit
6cb4f9a7f6

+ 1 - 1
.appveyor.yml

@@ -5,7 +5,6 @@ clone_folder: C:\projects\php-cs-fixer
 
 environment:
     matrix:
-        - php_ver: 7.1.2
         - php_ver: 5.6.30
           SKIP_LINT_TEST_CASES: 1
 
@@ -28,6 +27,7 @@ install:
     - echo extension_dir=ext >> php.ini
     - echo extension=php_curl.dll >> php.ini
     - echo extension=php_openssl.dll >> php.ini
+    - echo extension=php_mbstring.dll >> php.ini
     - IF NOT EXIST C:\tools\composer.phar (cd C:\tools && appveyor DownloadFile https://getcomposer.org/download/1.4.1/composer.phar)
     - cd C:\projects\php-cs-fixer
     - php C:\tools\composer.phar global show hirak/prestissimo -q || php C:\tools\composer.phar global require hirak/prestissimo

+ 3 - 3
composer.json

@@ -19,7 +19,7 @@
         "ext-tokenizer": "*",
         "composer/semver": "^1.4",
         "doctrine/annotations": "^1.2",
-        "gecko-packages/gecko-php-unit": "^2.0",
+        "gecko-packages/gecko-php-unit": "^2.0 || ^3.0",
         "php-cs-fixer/diff": "^1.0",
         "symfony/console": "^3.2 || ^4.0",
         "symfony/event-dispatcher": "^3.0 || ^4.0",
@@ -32,11 +32,11 @@
         "symfony/stopwatch": "^3.0 || ^4.0"
     },
     "require-dev": {
-        "johnkary/phpunit-speedtrap": "^1.1",
+        "johnkary/phpunit-speedtrap": "^1.1 || ^2.0@dev",
         "justinrainbow/json-schema": "^5.0",
         "php-coveralls/php-coveralls": "^1.0.2",
         "php-cs-fixer/accessible-object": "^1.0",
-        "phpunit/phpunit": "^4.8.35 || ^5.4.3",
+        "phpunit/phpunit": "^5.7.23 || ^6.4.3",
         "symfony/phpunit-bridge": "^3.2.2 || ^4.0"
     },
     "suggest": {

+ 1 - 1
tests/AbstractDoctrineAnnotationFixerTestCase.php

@@ -26,7 +26,7 @@ abstract class AbstractDoctrineAnnotationFixerTestCase extends AbstractFixerTest
      */
     public function testConfigureWithInvalidConfiguration(array $configuration)
     {
-        $this->setExpectedException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class);
+        $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class);
 
         $this->fixer->configure($configuration);
     }

+ 3 - 3
tests/Cache/CacheTest.php

@@ -64,7 +64,7 @@ final class CacheTest extends TestCase
 
     public function testSetThrowsInvalidArgumentExceptionIfValueIsNotAnInteger()
     {
-        $this->setExpectedException(\InvalidArgumentException::class);
+        $this->expectException(\InvalidArgumentException::class);
 
         $signature = $this->getSignatureDouble();
 
@@ -107,7 +107,7 @@ final class CacheTest extends TestCase
 
     public function testFromJsonThrowsInvalidArgumentExceptionIfJsonIsInvalid()
     {
-        $this->setExpectedException(\InvalidArgumentException::class);
+        $this->expectException(\InvalidArgumentException::class);
 
         $json = '{"foo';
 
@@ -121,7 +121,7 @@ final class CacheTest extends TestCase
      */
     public function testFromJsonThrowsInvalidArgumentExceptionIfJsonIsMissingKey(array $data)
     {
-        $this->setExpectedException(\InvalidArgumentException::class);
+        $this->expectException(\InvalidArgumentException::class);
 
         $json = json_encode($data);
 

+ 12 - 15
tests/Cache/FileHandlerTest.php

@@ -104,7 +104,8 @@ final class FileHandlerTest extends TestCase
     {
         $file = __DIR__.'/non-existent-directory/.php_cs.cache';
 
-        $this->setExpectedExceptionRegExp(\Symfony\Component\Filesystem\Exception\IOException::class, sprintf(
+        $this->expectException(\Symfony\Component\Filesystem\Exception\IOException::class);
+        $this->expectExceptionMessageRegExp(sprintf(
             '#^Failed to write file "%s"(, ".*")?.#',
             preg_quote($file, '#')
         ));
@@ -153,13 +154,11 @@ final class FileHandlerTest extends TestCase
 
         $handler = new FileHandler($dir);
 
-        $this->setExpectedExceptionRegExp(
-            'Symfony\Component\Filesystem\Exception\IOException',
-            sprintf(
-                '#^%s$#',
-                preg_quote('Cannot write cache file "'.realpath($dir).'" as the location exists as directory.', '#')
-        )
-        );
+        $this->expectException(\Symfony\Component\Filesystem\Exception\IOException::class);
+        $this->expectExceptionMessageRegExp(sprintf(
+            '#^%s$#',
+            preg_quote('Cannot write cache file "'.realpath($dir).'" as the location exists as directory.', '#')
+        ));
 
         $handler->write(new Cache(new Signature(
             PHP_VERSION,
@@ -182,13 +181,11 @@ final class FileHandlerTest extends TestCase
 
         $handler = new FileHandler($file);
 
-        $this->setExpectedExceptionRegExp(
-            'Symfony\Component\Filesystem\Exception\IOException',
-            sprintf(
-                '#^%s$#',
-                preg_quote('Cannot write to file "'.realpath($file).'" as it is not writable.', '#')
-        )
-        );
+        $this->expectException(\Symfony\Component\Filesystem\Exception\IOException::class);
+        $this->expectExceptionMessageRegExp(sprintf(
+            '#^%s$#',
+            preg_quote('Cannot write to file "'.realpath($file).'" as it is not writable.', '#')
+        ));
 
         $handler->write(new Cache(new Signature(
             PHP_VERSION,

+ 3 - 5
tests/ConfigTest.php

@@ -74,7 +74,7 @@ final class ConfigTest extends TestCase
 
     public function testConfigRulesUsingInvalidJson()
     {
-        $this->setExpectedException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class);
+        $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class);
 
         $config = new Config();
         $configResolver = new ConfigurationResolver(
@@ -183,10 +183,8 @@ final class ConfigTest extends TestCase
 
     public function testRegisterCustomFixersWithInvalidArgument()
     {
-        $this->setExpectedExceptionRegExp(
-            \InvalidArgumentException::class,
-            '/^Argument must be an array or a Traversable, got "\w+"\.$/'
-        );
+        $this->expectException(\InvalidArgumentException::class);
+        $this->expectExceptionMessageRegExp('/^Argument must be an array or a Traversable, got "\w+"\.$/');
 
         $config = new Config();
         $config->registerCustomFixers('foo');

+ 8 - 4
tests/Console/Command/DescribeCommandTest.php

@@ -135,7 +135,8 @@ EOT;
 
         $commandTester = new CommandTester($command);
 
-        $this->setExpectedExceptionRegExp(\InvalidArgumentException::class, '#^Rule "Foo/bar" not found\.$#');
+        $this->expectException(\InvalidArgumentException::class);
+        $this->expectExceptionMessageRegExp('#^Rule "Foo/bar" not found\.$#');
         $commandTester->execute([
             'command' => $command->getName(),
             'name' => 'Foo/bar',
@@ -150,7 +151,8 @@ EOT;
 
         $commandTester = new CommandTester($command);
 
-        $this->setExpectedExceptionRegExp(\InvalidArgumentException::class, '#^Set "@NoSuchSet" not found\.$#');
+        $this->expectException(\InvalidArgumentException::class);
+        $this->expectExceptionMessageRegExp('#^Set "@NoSuchSet" not found\.$#');
         $commandTester->execute([
             'command' => $command->getName(),
             'name' => '@NoSuchSet',
@@ -165,7 +167,8 @@ EOT;
 
         $commandTester = new CommandTester($command);
 
-        $this->setExpectedExceptionRegExp(\RuntimeException::class, '/^Not enough arguments( \(missing: "name"\))?\.$/');
+        $this->expectException(\RuntimeException::class);
+        $this->expectExceptionMessageRegExp('/^Not enough arguments( \(missing: "name"\))?\.$/');
         $commandTester->execute([
             'command' => $command->getName(),
         ]);
@@ -173,7 +176,8 @@ EOT;
 
     public function testGetAlternativeSuggestion()
     {
-        $this->setExpectedExceptionRegExp(\InvalidArgumentException::class, '#^Rule "Foo2/bar" not found\. Did you mean "Foo/bar"\?$#');
+        $this->expectException(\InvalidArgumentException::class);
+        $this->expectExceptionMessageRegExp('#^Rule "Foo2/bar" not found\. Did you mean "Foo/bar"\?$#');
         $this->execute('Foo2/bar', false);
     }
 

+ 2 - 1
tests/Console/Command/FixCommandTest.php

@@ -78,7 +78,8 @@ final class FixCommandTest extends TestCase
         $commandTester = new CommandTester($command);
 
         if (null !== $expectedException) {
-            $this->setExpectedExceptionRegExp($expectedException['class'], $expectedException['regex']);
+            $this->expectException($expectedException['class']);
+            $this->expectExceptionMessageRegExp($expectedException['regex']);
         }
 
         $commandTester->execute(

+ 1 - 1
tests/Console/Command/ReadmeCommandTest.php

@@ -31,7 +31,7 @@ final class ReadmeCommandTest extends TestCase
     {
         $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->assertIsReadable($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));

+ 18 - 25
tests/Console/ConfigurationResolverTest.php

@@ -13,6 +13,7 @@
 namespace PhpCsFixer\Tests\Console;
 
 use PhpCsFixer\Config;
+use PhpCsFixer\ConfigurationException\InvalidConfigurationException;
 use PhpCsFixer\Console\Command\FixCommand;
 use PhpCsFixer\Console\ConfigurationResolver;
 use PhpCsFixer\Finder;
@@ -50,10 +51,8 @@ final class ConfigurationResolverTest extends TestCase
 
     public function testSetOptionWithUndefinedOption()
     {
-        $this->setExpectedExceptionRegExp(
-            \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class,
-            '/^Unknown option name: "foo"\.$/'
-        );
+        $this->expectException(InvalidConfigurationException::class);
+        $this->expectExceptionMessageRegExp('/^Unknown option name: "foo"\.$/');
 
         new ConfigurationResolver(
             $this->config,
@@ -192,10 +191,8 @@ final class ConfigurationResolverTest extends TestCase
             ''
         );
 
-        $this->setExpectedException(
-            \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class,
-            'The progress type "foo" is not defined, supported are "none", "run-in", "estimating", "estimating-max".'
-        );
+        $this->expectException(InvalidConfigurationException::class);
+        $this->expectExceptionMessage('The progress type "foo" is not defined, supported are "none", "run-in", "estimating", "estimating-max".');
 
         $resolver->getProgress();
     }
@@ -297,8 +294,8 @@ final class ConfigurationResolverTest extends TestCase
 
     public function testResolveConfigFileChooseFileWithInvalidFile()
     {
-        $this->setExpectedExceptionRegExp(
-            \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class,
+        $this->expectException(InvalidConfigurationException::class);
+        $this->expectExceptionMessageRegExp(
             '#^The config file: ".+[\/\\\]Fixtures[\/\\\]ConfigurationResolverConfigFile[\/\\\]case_5[\/\\\]\.php_cs\.dist" does not return a "PhpCsFixer\\\ConfigInterface" instance\. Got: "string"\.$#'
         );
 
@@ -315,10 +312,8 @@ final class ConfigurationResolverTest extends TestCase
 
     public function testResolveConfigFileChooseFileWithInvalidFormat()
     {
-        $this->setExpectedExceptionRegExp(
-            \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class,
-            '/^The format "xls" is not defined, supported are "json", "junit", "txt", "xml"\.$/'
-        );
+        $this->expectException(InvalidConfigurationException::class);
+        $this->expectExceptionMessageRegExp('/^The format "xls" is not defined, supported are "json", "junit", "txt", "xml"\.$/');
 
         $dirBase = $this->getFixtureDir();
 
@@ -333,10 +328,8 @@ final class ConfigurationResolverTest extends TestCase
 
     public function testResolveConfigFileChooseFileWithPathArrayWithoutConfig()
     {
-        $this->setExpectedExceptionRegExp(
-            \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class,
-            '/^For multiple paths config parameter is required\.$/'
-        );
+        $this->expectException(InvalidConfigurationException::class);
+        $this->expectExceptionMessageRegExp('/^For multiple paths config parameter is required\.$/');
 
         $dirBase = $this->getFixtureDir();
 
@@ -482,7 +475,7 @@ final class ConfigurationResolverTest extends TestCase
     public function testResolveIntersectionOfPaths($expected, $configFinder, array $path, $pathMode, $config = null)
     {
         if ($expected instanceof \Exception) {
-            $this->setExpectedException(get_class($expected));
+            $this->expectException(get_class($expected));
         }
 
         if (null !== $configFinder) {
@@ -988,8 +981,10 @@ final class ConfigurationResolverTest extends TestCase
 
     public function testResolveRulesWithUnknownRules()
     {
-        $this->setExpectedException(
-            \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class,
+        $this->expectException(
+            \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class
+        );
+        $this->expectExceptionMessage(
             'The rules contain unknown fixers: "bar", "binary_operator_space" (did you mean "binary_operator_spaces"?).'
         );
 
@@ -1151,10 +1146,8 @@ final class ConfigurationResolverTest extends TestCase
             ''
         );
 
-        $this->setExpectedExceptionRegExp(
-            'PhpCsFixer\ConfigurationException\InvalidConfigurationException',
-            '/^Empty rules value is not allowed\.$/'
-        );
+        $this->expectException(InvalidConfigurationException::class);
+        $this->expectExceptionMessageRegExp('/^Empty rules value is not allowed\.$/');
 
         $resolver->getRules();
     }

Некоторые файлы не были показаны из-за большого количества измененных файлов