Browse Source

Merge branch '2.2' into 2.11

# Conflicts:
#	.travis.yml
#	composer.json
#	tests/Test/AbstractFixerTestCase.php
#	tests/Test/Constraint/SameStringsConstraint.php
#	tests/Test/Constraint/SameStringsConstraintTest.php
#	tests/Test/Constraint/XmlMatchesXsdConstraint.php
#	tests/Test/Constraint/XmlMatchesXsdConstraintTest.php
Dariusz Ruminski 7 years ago
parent
commit
3577a0024f

+ 0 - 1
.gitattributes

@@ -6,7 +6,6 @@ tests/Fixtures/ export-ignore
 tests/Linter/AbstractLinterTestCase.php export-ignore
 tests/Report/AbstractReporterTestCase.php export-ignore
 tests/Test/AbstractTransformerTestCase.php export-ignore
-tests/Test/Constraint/XmlMatchesXsdConstraint.php export-ignore
 
 .appveyor.yml export-ignore
 .composer-require-checker.json export-ignore

+ 2 - 0
.travis.yml

@@ -75,6 +75,8 @@ jobs:
                 - if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/lts:$(echo $SYMFONY_VERSION | grep -o 'v[0-9]\+') || true; fi
 
                 - travis_retry composer update $DEFAULT_COMPOSER_FLAGS $COMPOSER_FLAGS
+                - composer require --dev php-cs-fixer/phpunit-constraint-isidenticalstring:^1.0 || true # install if possible, move to require-dev section on 2.11
+                - composer require --dev php-cs-fixer/phpunit-constraint-xmlmatchesxsd:^1.0 || true # install if possible, move to require-dev section on 2.11
                 - composer info -D | sort
             script:
                 - vendor/bin/phpunit || travis_terminate 1

+ 2 - 0
composer.json

@@ -46,6 +46,8 @@
     },
     "suggest": {
         "ext-mbstring": "For handling non-UTF8 characters in cache signature.",
+        "php-cs-fixer/phpunit-constraint-isidenticalstring": "For IsIdenticalString constraint.",
+        "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "For XmlMatchesXsd constraint.",
         "symfony/polyfill-mbstring": "When enabling `ext-mbstring` is not possible."
     },
     "config": {

+ 7 - 2
tests/Report/JunitReporterTest.php

@@ -12,8 +12,8 @@
 
 namespace PhpCsFixer\Tests\Report;
 
+use PhpCsFixer\PhpunitConstraintXmlMatchesXsd\Constraint\XmlMatchesXsd;
 use PhpCsFixer\Report\JunitReporter;
-use PhpCsFixer\Tests\Test\Constraint\XmlMatchesXsdConstraint;
 use Symfony\Component\Console\Formatter\OutputFormatter;
 
 /**
@@ -37,6 +37,11 @@ final class JunitReporterTest extends AbstractReporterTestCase
 
     public static function setUpBeforeClass()
     {
+        // @TODO 2.11 remove me
+        if (!class_exists('PhpCsFixer\PhpunitConstraintXmlMatchesXsd\Constraint\XmlMatchesXsd')) {
+            self::markTestSkipped('Cannot execute test, install `php-cs-fixer/phpunit-constraint-xmlmatchesxsd` first.');
+        }
+
         self::$xsd = file_get_contents(__DIR__.'/../../doc/junit-10.xsd');
     }
 
@@ -163,7 +168,7 @@ XML;
         $formatter = new OutputFormatter();
         $input = $formatter->format($input);
 
-        $this->assertThat($input, new XmlMatchesXsdConstraint(self::$xsd));
+        $this->assertThat($input, new XmlMatchesXsd(self::$xsd));
         $this->assertXmlStringEqualsXmlString($expected, $input);
     }
 

+ 7 - 2
tests/Report/XmlReporterTest.php

@@ -12,8 +12,8 @@
 
 namespace PhpCsFixer\Tests\Report;
 
+use PhpCsFixer\PhpunitConstraintXmlMatchesXsd\Constraint\XmlMatchesXsd;
 use PhpCsFixer\Report\XmlReporter;
-use PhpCsFixer\Tests\Test\Constraint\XmlMatchesXsdConstraint;
 use Symfony\Component\Console\Formatter\OutputFormatter;
 
 /**
@@ -33,6 +33,11 @@ final class XmlReporterTest extends AbstractReporterTestCase
 
     public static function setUpBeforeClass()
     {
+        // @TODO 2.11 remove me
+        if (!class_exists('PhpCsFixer\PhpunitConstraintXmlMatchesXsd\Constraint\XmlMatchesXsd')) {
+            self::markTestSkipped('Cannot execute test, install `php-cs-fixer/phpunit-constraint-xmlmatchesxsd` first.');
+        }
+
         self::$xsd = file_get_contents(__DIR__.'/../../doc/xml.xsd');
     }
 
@@ -153,7 +158,7 @@ XML;
         $formatter = new OutputFormatter();
         $input = $formatter->format($input);
 
-        $this->assertThat($input, new XmlMatchesXsdConstraint(self::$xsd));
+        $this->assertThat($input, new XmlMatchesXsd(self::$xsd));
         $this->assertXmlStringEqualsXmlString($expected, $input);
     }
 }

+ 24 - 3
tests/Test/AbstractFixerTestCase.php

@@ -19,7 +19,6 @@ use PhpCsFixer\Linter\Linter;
 use PhpCsFixer\Linter\LinterInterface;
 use PhpCsFixer\RuleSet;
 use PhpCsFixer\Tests\Test\Assert\AssertTokensTrait;
-use PhpCsFixer\Tests\Test\Constraint\SameStringsConstraint;
 use PhpCsFixer\Tests\TestCase;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
@@ -157,7 +156,7 @@ abstract class AbstractFixerTestCase extends TestCase
 
             $this->assertThat(
                 $tokens->generateCode(),
-                new SameStringsConstraint($expected),
+                self::createIsIdenticalStringConstraint($expected),
                 'Code build on input code must match expected code.'
             );
             $this->assertTrue($tokens->isChanged(), 'Tokens collection built on input code must be marked as changed after fixing.');
@@ -189,7 +188,7 @@ abstract class AbstractFixerTestCase extends TestCase
 
         $this->assertThat(
             $tokens->generateCode(),
-            new SameStringsConstraint($expected),
+            self::createIsIdenticalStringConstraint($expected),
             'Code build on expected code must not change.'
         );
         $this->assertFalse($tokens->isChanged(), 'Tokens collection built on expected code must not be marked as changed after fixing.');
@@ -279,4 +278,26 @@ abstract class AbstractFixerTestCase extends TestCase
 
         return $this->fixerClassName;
     }
+
+    /**
+     * @todo Remove me when this class will end up in dedicated package.
+     *
+     * @param string $expected
+     */
+    private static function createIsIdenticalStringConstraint($expected)
+    {
+        $candidates = array_filter([
+            'PhpCsFixer\PhpunitConstraintIsIdenticalString\Constraint\IsIdenticalString',
+            'PHPUnit\Framework\Constraint\IsIdentical',
+            'PHPUnit_Framework_Constraint_IsIdentical',
+        ], function ($className) { return class_exists($className); });
+
+        if (empty($candidates)) {
+            throw new \RuntimeException('PHPUnit not installed?!');
+        }
+
+        $candidate = array_shift($candidates);
+
+        return new $candidate($expected);
+    }
 }

+ 23 - 2
tests/Test/AbstractIntegrationTestCase.php

@@ -22,7 +22,6 @@ use PhpCsFixer\FixerFactory;
 use PhpCsFixer\Linter\Linter;
 use PhpCsFixer\Linter\LinterInterface;
 use PhpCsFixer\Runner\Runner;
-use PhpCsFixer\Tests\Test\Constraint\SameStringsConstraint;
 use PhpCsFixer\Tests\TestCase;
 use PhpCsFixer\Tokenizer\Tokens;
 use PhpCsFixer\WhitespacesFixerConfig;
@@ -261,7 +260,7 @@ abstract class AbstractIntegrationTestCase extends TestCase
         $fixedInputCode = file_get_contents($tmpFile);
         $this->assertThat(
             $fixedInputCode,
-            new SameStringsConstraint($expected),
+            self::createIsIdenticalStringConstraint($expected),
             sprintf(
                 "Expected changes do not match result for \"%s\" in \"%s\".\nFixers applied:\n%s.",
                 $case->getTitle(),
@@ -397,4 +396,26 @@ abstract class AbstractIntegrationTestCase extends TestCase
 
         return $linter;
     }
+
+    /**
+     * @todo Remove me when this class will end up in dedicated package.
+     *
+     * @param string $expected
+     */
+    private static function createIsIdenticalStringConstraint($expected)
+    {
+        $candidates = array_filter([
+            'PhpCsFixer\PhpunitConstraintIsIdenticalString\Constraint\IsIdenticalString',
+            'PHPUnit\Framework\Constraint\IsIdentical',
+            'PHPUnit_Framework_Constraint_IsIdentical',
+        ], function ($className) { return class_exists($className); });
+
+        if (empty($candidates)) {
+            throw new \RuntimeException('PHPUnit not installed?!');
+        }
+
+        $candidate = array_shift($candidates);
+
+        return new $candidate($expected);
+    }
 }