diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b1bde09..6507f22 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v6 - uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.5' coverage: none - run: composer update --no-progress - run: composer update --no-progress --working-dir=dev-tools @@ -28,12 +28,8 @@ jobs: fail-fast: false matrix: include: - - php-version: '7.0' - composer-flags: '--prefer-stable --prefer-lowest' - - php-version: '7.1' - - php-version: '7.2' - - php-version: '7.3' - php-version: '7.4' + composer-flags: '--prefer-stable --prefer-lowest' - php-version: '8.0' - php-version: '8.1' - php-version: '8.2' diff --git a/composer.json b/composer.json index 6bfebb3..caf9b05 100644 --- a/composer.json +++ b/composer.json @@ -13,10 +13,10 @@ } ], "require": { - "php": "^7.0 || ^8.0", + "php": "^7.4 || ^8.0", "ext-dom": "*", "ext-libxml": "*", - "phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.41 || ^9.6.22 || ^10.5.45 || ^11.5.7 || ^12.0.2 || ^13.0.0" + "phpunit/phpunit": "^9.6.34 || ^10.5.53 || ^11.5.55 || ^12.5.14 || ^13.0.5" }, "autoload": { "psr-4": { diff --git a/src/Constraint/XmlMatchesXsd.php b/src/Constraint/XmlMatchesXsd.php index ec406ed..ecb18f2 100644 --- a/src/Constraint/XmlMatchesXsd.php +++ b/src/Constraint/XmlMatchesXsd.php @@ -14,10 +14,4 @@ use PHPUnit\Runner\Version; -if (version_compare(Version::id(), '7.0.0') < 0) { - class_alias(XmlMatchesXsdForV5::class, XmlMatchesXsd::class); -} elseif (version_compare(Version::id(), '8.0.0') < 0) { - class_alias(XmlMatchesXsdForV7::class, XmlMatchesXsd::class); -} else { - class_alias(XmlMatchesXsdForV8::class, XmlMatchesXsd::class); -} +class_alias(XmlMatchesXsdForV9::class, XmlMatchesXsd::class); diff --git a/src/Constraint/XmlMatchesXsdForV5.php b/src/Constraint/XmlMatchesXsdForV5.php deleted file mode 100644 index b25bab5..0000000 --- a/src/Constraint/XmlMatchesXsdForV5.php +++ /dev/null @@ -1,135 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace PhpCsFixer\PhpunitConstraintXmlMatchesXsd\Constraint; - -if (!class_exists('PHPUnit\Framework\Constraint\Constraint')) { - class_alias('PHPUnit_Framework_Constraint', 'PHPUnit\Framework\Constraint\Constraint'); -} - -use PHPUnit\Framework\Constraint\Constraint; - -/** - * @author SpacePossum - * - * @internal - */ -final class XmlMatchesXsdForV5 extends Constraint -{ - /** - * @var string[] - */ - private $xmlConstraintErrors = []; - - /** - * @var string - */ - private $xsd; - - /** - * @param string $xsd - */ - public function __construct($xsd) - { - parent::__construct(); - - // replace first only - $needle = 'http://www.w3.org/2001/xml.xsd'; - if (false !== $pos = strpos($xsd, $needle)) { - $xsd = substr_replace($xsd, 'file:///'.str_replace('\\', '/', __DIR__).'/xml.xsd', $pos, \strlen($needle)); - } - - $this->xsd = $xsd; - } - - public function toString() - { - return 'matches XSD'; - } - - protected function failureDescription($other) - { - if (\is_string($other)) { - return \sprintf("%s %s.\n%s", $other, $this->toString(), implode("\n", $this->xmlConstraintErrors)); - } - - if (\is_object($other)) { - $type = \sprintf('%s#%s', \get_class($other), method_exists($other, '__toString') ? $other->__toString() : ''); - } elseif (null === $other) { - $type = 'null'; - } else { - $type = \gettype($other).'#'.$other; - } - - return $type.' '.$this->toString(); - } - - protected function matches($other) - { - return \is_string($other) - ? $this->stringMatches($other) - : false; - } - - /** - * @param string $other - * - * @return bool - */ - private function stringMatches($other) - { - $internalErrors = libxml_use_internal_errors(true); - libxml_clear_errors(); - - $dom = new \DOMDocument(); - $dom->preserveWhiteSpace = false; - $dom->validateOnParse = true; - - if (!@$dom->loadXML($other, LIBXML_NONET | (\defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) { - $this->setXMLConstraintErrors(); - libxml_clear_errors(); - libxml_use_internal_errors($internalErrors); - - return false; - } - - $dom->normalizeDocument(); - - libxml_clear_errors(); - - if (false === $result = @$dom->schemaValidateSource($this->xsd)) { - $this->setXMLConstraintErrors(); - } - - libxml_clear_errors(); - libxml_use_internal_errors($internalErrors); - - return $result; - } - - private function setXMLConstraintErrors() - { - foreach (libxml_get_errors() as $error) { - if (LIBXML_ERR_WARNING === $error->level) { - $level = 'warning '; - } elseif (LIBXML_ERR_ERROR === $error->level) { - $level = 'error '; - } elseif (LIBXML_ERR_FATAL === $error->level) { - $level = 'fatal '; - } else { - $level = ''; - } - - $this->xmlConstraintErrors[] = \sprintf('[%s%s] %s (line %d, column %d).', $level, $error->code, trim($error->message), $error->line, $error->column); - } - } -} diff --git a/src/Constraint/XmlMatchesXsdForV7.php b/src/Constraint/XmlMatchesXsdForV7.php deleted file mode 100644 index 707e7fb..0000000 --- a/src/Constraint/XmlMatchesXsdForV7.php +++ /dev/null @@ -1,131 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace PhpCsFixer\PhpunitConstraintXmlMatchesXsd\Constraint; - -use PHPUnit\Framework\Constraint\Constraint; - -/** - * @author SpacePossum - * - * @internal - */ -final class XmlMatchesXsdForV7 extends Constraint -{ - /** - * @var string[] - */ - private $xmlConstraintErrors = []; - - /** - * @var string - */ - private $xsd; - - /** - * @param string $xsd - */ - public function __construct($xsd) - { - parent::__construct(); - - // replace first only - $needle = 'http://www.w3.org/2001/xml.xsd'; - if (false !== $pos = strpos($xsd, $needle)) { - $xsd = substr_replace($xsd, 'file:///'.str_replace('\\', '/', __DIR__).'/xml.xsd', $pos, \strlen($needle)); - } - - $this->xsd = $xsd; - } - - public function toString(): string - { - return 'matches XSD'; - } - - protected function failureDescription($other): string - { - if (\is_string($other)) { - return \sprintf("%s %s.\n%s", $other, $this->toString(), implode("\n", $this->xmlConstraintErrors)); - } - - if (\is_object($other)) { - $type = \sprintf('%s#%s', \get_class($other), method_exists($other, '__toString') ? $other->__toString() : ''); - } elseif (null === $other) { - $type = 'null'; - } else { - $type = \gettype($other).'#'.$other; - } - - return $type.' '.$this->toString(); - } - - protected function matches($other): bool - { - return \is_string($other) - ? $this->stringMatches($other) - : false; - } - - /** - * @param string $other - * - * @return bool - */ - private function stringMatches($other) - { - $internalErrors = libxml_use_internal_errors(true); - libxml_clear_errors(); - - $dom = new \DOMDocument(); - $dom->preserveWhiteSpace = false; - $dom->validateOnParse = true; - - if (!@$dom->loadXML($other, LIBXML_NONET | (\defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) { - $this->setXMLConstraintErrors(); - libxml_clear_errors(); - libxml_use_internal_errors($internalErrors); - - return false; - } - - $dom->normalizeDocument(); - - libxml_clear_errors(); - - if (false === $result = @$dom->schemaValidateSource($this->xsd)) { - $this->setXMLConstraintErrors(); - } - - libxml_clear_errors(); - libxml_use_internal_errors($internalErrors); - - return $result; - } - - private function setXMLConstraintErrors() - { - foreach (libxml_get_errors() as $error) { - if (LIBXML_ERR_WARNING === $error->level) { - $level = 'warning '; - } elseif (LIBXML_ERR_ERROR === $error->level) { - $level = 'error '; - } elseif (LIBXML_ERR_FATAL === $error->level) { - $level = 'fatal '; - } else { - $level = ''; - } - - $this->xmlConstraintErrors[] = \sprintf('[%s%s] %s (line %d, column %d).', $level, $error->code, trim($error->message), $error->line, $error->column); - } - } -} diff --git a/src/Constraint/XmlMatchesXsdForV8.php b/src/Constraint/XmlMatchesXsdForV9.php similarity index 98% rename from src/Constraint/XmlMatchesXsdForV8.php rename to src/Constraint/XmlMatchesXsdForV9.php index 9ab6e64..0d2eadf 100644 --- a/src/Constraint/XmlMatchesXsdForV8.php +++ b/src/Constraint/XmlMatchesXsdForV9.php @@ -19,7 +19,7 @@ * * @internal */ -final class XmlMatchesXsdForV8 extends Constraint +final class XmlMatchesXsdForV9 extends Constraint { /** * @var string[]