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

Tests - Do not use annotations for asserting exceptions

Andreas Möller 8 лет назад
Родитель
Сommit
a41d933456

+ 5 - 4
tests/ConfigTest.php

@@ -107,12 +107,13 @@ final class ConfigTest extends \PHPUnit_Framework_TestCase
         $this->assertSame($config, $config->setCacheFile('some-directory/some.file'));
     }
 
-    /**
-     * @expectedException              \InvalidArgumentException
-     * @expectedExceptionMessageRegExp /^Argument must be an array or a Traversable, got "\w+"\.$/
-     */
     public function testRegisterCustomFixersWithInvalidArgument()
     {
+        $this->setExpectedExceptionRegExp(
+            'InvalidArgumentException',
+            '/^Argument must be an array or a Traversable, got "\w+"\.$/'
+        );
+
         $config = new Config();
         $config->registerCustomFixers('foo');
     }

+ 20 - 16
tests/Console/ConfigurationResolverTest.php

@@ -41,12 +41,13 @@ final class ConfigurationResolverTest extends \PHPUnit_Framework_TestCase
         unset($this->config);
     }
 
-    /**
-     * @expectedException              \PhpCsFixer\ConfigurationException\InvalidConfigurationException
-     * @expectedExceptionMessageRegExp /^Unknown option name: "foo"\.$/
-     */
     public function testSetOptionWithUndefinedOption()
     {
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidConfigurationException',
+            '/^Unknown option name: "foo"\.$/'
+        );
+
         new ConfigurationResolver(
             $this->config,
             array('foo' => 'bar'),
@@ -213,12 +214,13 @@ final class ConfigurationResolverTest extends \PHPUnit_Framework_TestCase
         );
     }
 
-    /**
-     * @expectedException              \PhpCsFixer\ConfigurationException\InvalidConfigurationException
-     * @expectedExceptionMessageRegExp /^The config file: ".+[\/\\]Fixtures[\/\\]ConfigurationResolverConfigFile[\/\\]case_5[\/\\].php_cs.dist" does not return a "PhpCsFixer\\ConfigInterface" instance\. Got: "string"\.$/
-     */
     public function testResolveConfigFileChooseFileWithInvalidFile()
     {
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidConfigurationException',
+            '#^The config file: ".+[\/\\\]Fixtures[\/\\\]ConfigurationResolverConfigFile[\/\\\]case_5[\/\\\]\.php_cs.dist" does not return a "PhpCsFixer\\\ConfigInterface" instance\. Got: "string"\.$#'
+        );
+
         $dirBase = $this->getFixtureDir();
 
         $resolver = new ConfigurationResolver(
@@ -230,12 +232,13 @@ final class ConfigurationResolverTest extends \PHPUnit_Framework_TestCase
         $resolver->getConfig();
     }
 
-    /**
-     * @expectedException              \PhpCsFixer\ConfigurationException\InvalidConfigurationException
-     * @expectedExceptionMessageRegExp /^The format "xls" is not defined, supported are json, junit, txt, xml.$/
-     */
     public function testResolveConfigFileChooseFileWithInvalidFormat()
     {
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidConfigurationException',
+            '/^The format "xls" is not defined, supported are json, junit, txt, xml.$/'
+        );
+
         $dirBase = $this->getFixtureDir();
 
         $resolver = new ConfigurationResolver(
@@ -247,12 +250,13 @@ final class ConfigurationResolverTest extends \PHPUnit_Framework_TestCase
         $resolver->getReporter();
     }
 
-    /**
-     * @expectedException              \PhpCsFixer\ConfigurationException\InvalidConfigurationException
-     * @expectedExceptionMessageRegExp /^For multiple paths config parameter is required.$/
-     */
     public function testResolveConfigFileChooseFileWithPathArrayWithoutConfig()
     {
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidConfigurationException',
+            '/^For multiple paths config parameter is required.$/'
+        );
+
         $dirBase = $this->getFixtureDir();
 
         $resolver = new ConfigurationResolver(

+ 10 - 8
tests/DocBlock/AnnotationTest.php

@@ -241,23 +241,25 @@ final class AnnotationTest extends \PHPUnit_Framework_TestCase
         );
     }
 
-    /**
-     * @expectedException \RuntimeException
-     * @expectedExceptionMessage This tag does not support types
-     */
     public function testGetTypesOnBadTag()
     {
+        $this->setExpectedException(
+            'RuntimeException',
+            'This tag does not support types'
+        );
+
         $tag = new Annotation(array(new Line(' * @deprecated since 1.2')));
 
         $tag->getTypes();
     }
 
-    /**
-     * @expectedException \RuntimeException
-     * @expectedExceptionMessage This tag does not support types
-     */
     public function testSetTypesOnBadTag()
     {
+        $this->setExpectedException(
+            'RuntimeException',
+            'This tag does not support types'
+        );
+
         $tag = new Annotation(array(new Line(' * @author Chuck Norris')));
 
         $tag->setTypes(array('string'));

+ 5 - 4
tests/FinderTest.php

@@ -19,12 +19,13 @@ use PhpCsFixer\Finder;
  */
 final class FinderTest extends \PHPUnit_Framework_TestCase
 {
-    /**
-     * @expectedException              \LogicException
-     * @expectedExceptionMessageRegExp /^You must call (?:the in\(\) method)|(?:one of in\(\) or append\(\)) methods before iterating over a Finder\.$/
-     */
     public function testThatDefaultFinderDoesNotSpecifyAnyDirectory()
     {
+        $this->setExpectedExceptionRegExp(
+            'LogicException',
+            '/^You must call (?:the in\(\) method)|(?:one of in\(\) or append\(\)) methods before iterating over a Finder\.$/'
+        );
+
         $finder = Finder::create();
         $finder->getIterator();
     }

+ 10 - 8
tests/Fixer/Alias/RandomApiMigrationFixerTest.php

@@ -21,21 +21,23 @@ use PhpCsFixer\Test\AbstractFixerTestCase;
  */
 final class RandomApiMigrationFixerTest extends AbstractFixerTestCase
 {
-    /**
-     * @expectedException \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
-     * @expectedExceptionMessageRegExp #^\[random_api_migration\] "is_null" is not handled by the fixer.$#
-     */
     public function testConfigureCheckSearchFunction()
     {
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException',
+            '#^\[random_api_migration\] "is_null" is not handled by the fixer.$#'
+        );
+
         $this->fixer->configure(array('is_null' => 'random_int'));
     }
 
-    /**
-     * @expectedException \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
-     * @expectedExceptionMessageRegExp #^\[random_api_migration\] Expected string got "NULL".$#
-     */
     public function testConfigureCheckReplacementType()
     {
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException',
+            '#^\[random_api_migration\] Expected string got "NULL".$#'
+        );
+
         $this->fixer->configure(array('rand' => null));
     }
 

+ 5 - 4
tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php

@@ -23,12 +23,13 @@ use PhpCsFixer\Test\AbstractFixerTestCase;
  */
 final class ArraySyntaxFixerTest extends AbstractFixerTestCase
 {
-    /**
-     * @expectedException \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
-     * @expectedExceptionMessageRegExp #^\[array_syntax\] Configuration must define "syntax" being "short" or "long".$#
-     */
     public function testInvalidConfiguration()
     {
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException',
+            '#^\[array_syntax\] Configuration must define "syntax" being "short" or "long".$#'
+        );
+
         $this->fixer->configure(array('a' => 1));
     }
 

+ 10 - 8
tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php

@@ -112,22 +112,24 @@ final class ClassDefinitionFixerTest extends AbstractFixerTestCase
         $this->doTest($expected, $input);
     }
 
-    /**
-     * @expectedException \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
-     * @expectedExceptionMessageRegExp /^\[class_definition\] Unknown configuration item "a", expected any of "singleLine, singleItemSingleLine, multiLineExtendsEachSingleLine".$/
-     */
     public function testInvalidConfigurationKey()
     {
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException',
+            '/^\[class_definition\] Unknown configuration item "a", expected any of "singleLine, singleItemSingleLine, multiLineExtendsEachSingleLine".$/'
+        );
+
         $fixer = new ClassDefinitionFixer();
         $fixer->configure(array('a' => false));
     }
 
-    /**
-     * @expectedException \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
-     * @expectedExceptionMessageRegExp /^\[class_definition\] Configuration value for item "singleLine" must be a bool, got "string".$/
-     */
     public function testInvalidConfigurationValueType()
     {
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException',
+            '/^\[class_definition\] Configuration value for item "singleLine" must be a bool, got "string".$/'
+        );
+
         $fixer = new ClassDefinitionFixer();
         $fixer->configure(array('singleLine' => 'z'));
     }

+ 5 - 4
tests/Fixer/ClassNotation/OrderedClassElementsFixerTest.php

@@ -567,12 +567,13 @@ EOT
         );
     }
 
-    /**
-     * @expectedException \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
-     * @expectedExceptionMessage [ordered_class_elements] Unknown class element type "foo".
-     */
     public function testWrongConfig()
     {
+        $this->setExpectedException(
+            'PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException',
+            '[ordered_class_elements] Unknown class element type "foo".'
+        );
+
         $this->fixer->configure(array('foo'));
     }
 }

+ 5 - 4
tests/Fixer/ClassNotation/SingleClassElementPerStatementFixerTest.php

@@ -656,12 +656,13 @@ EOT
         );
     }
 
-    /**
-     * @expectedException \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
-     * @expectedExceptionMessageRegExp /^\[single_class_element_per_statement\] Unknown configuration option "foo"\. Expected any of "property", "const"\.$/
-     */
     public function testWrongConfig()
     {
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException',
+            '/^\[single_class_element_per_statement\] Unknown configuration option "foo"\. Expected any of "property", "const"\.$/'
+        );
+
         $this->fixer->configure(array('foo'));
     }
 

+ 15 - 12
tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php

@@ -429,34 +429,37 @@ EOF;
         $this->doTest($expected, $input);
     }
 
-    /**
-     * @expectedException \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
-     * @expectedExceptionMessageRegExp /^\[visibility_required\] Expected string got "NULL".$/
-     */
     public function testInvalidConfigurationType()
     {
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException',
+            '/^\[visibility_required\] Expected string got "NULL".$/'
+        );
+
         $this->fixer->configure(array(null));
     }
 
-    /**
-     * @expectedException \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
-     * @expectedExceptionMessageRegExp /^\[visibility_required\] Unknown configuration item "_unknown_", expected any of "property", "method", "const".$/
-     */
     public function testInvalidConfigurationValue()
     {
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException',
+            '/^\[visibility_required\] Unknown configuration item "_unknown_", expected any of "property", "method", "const".$/'
+        );
+
         $this->fixer->configure(array('_unknown_'));
     }
 
-    /**
-     * @expectedException \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
-     * @expectedExceptionMessageRegExp /^\[visibility_required\] Invalid configuration item "const" for PHP ".+".$/
-     */
     public function testInvalidConfigurationValueForPHPVersion()
     {
         if (PHP_VERSION_ID >= 70100) {
             $this->markTestSkipped('PHP version to high.');
         }
 
+        $this->setExpectedExceptionRegExp(
+            'PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException',
+            '/^\[visibility_required\] Invalid configuration item "const" for PHP ".+".$/'
+        );
+
         $this->fixer->configure(array('const'));
     }
 

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