From e7a17599ad69d1600032a8f0c9e576a703145111 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Fri, 21 May 2021 20:31:07 +0300 Subject: [PATCH] ugly hack for tests --- .github/workflows/tests.yml | 1 - src/Matchers/XmlBodyMatcher.php | 23 ++++++++++++++++++++--- tests/src/PockBuilderTest.php | 20 ++++---------------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9d5147f..96e88b0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,7 +23,6 @@ jobs: with: php-version: ${{ matrix.php-version }} coverage: pcov - extensions: uopz - name: Composer cache uses: actions/cache@v2 with: diff --git a/src/Matchers/XmlBodyMatcher.php b/src/Matchers/XmlBodyMatcher.php index 2fc932b..e0b1268 100644 --- a/src/Matchers/XmlBodyMatcher.php +++ b/src/Matchers/XmlBodyMatcher.php @@ -44,6 +44,9 @@ class XmlBodyMatcher extends BodyMatcher EOT; + /** @var bool */ + public static $forceTextComparison = false; + /** @var XSLTProcessor|null */ private static $sorter; @@ -59,14 +62,14 @@ EOT; */ public function __construct($referenceXml) { - if (!extension_loaded('xsl') || !extension_loaded('dom')) { + if (!static::hasExtension('xsl') || !static::hasExtension('dom')) { $this->useFallback = true; } - if (!extension_loaded('xsl')) { + if (!static::hasExtension('xsl')) { $this->useFallback = true; - if (extension_loaded('dom') && $referenceXml instanceof DOMDocument) { + if (static::hasExtension('dom') && $referenceXml instanceof DOMDocument) { $referenceXml = static::getDOMString($referenceXml); } @@ -190,4 +193,18 @@ EOT; return $result; } + + /** + * @param string $extension + * + * @return bool + */ + private static function hasExtension(string $extension): bool + { + if (static::$forceTextComparison && 'xsl' === $extension) { + return false; + } + + return extension_loaded($extension); + } } diff --git a/tests/src/PockBuilderTest.php b/tests/src/PockBuilderTest.php index cc9a0cc..ac1462c 100644 --- a/tests/src/PockBuilderTest.php +++ b/tests/src/PockBuilderTest.php @@ -10,12 +10,10 @@ namespace Pock\Tests; use DOMDocument; -use phpmock\Mock; -use phpmock\MockBuilder; -use phpmock\MockRegistry; use Pock\Enum\RequestMethod; use Pock\Enum\RequestScheme; use Pock\Exception\UnsupportedRequestException; +use Pock\Matchers\XmlBodyMatcher; use Pock\PockBuilder; use Pock\PockResponseBuilder; use Pock\TestUtils\PockTestCase; @@ -35,9 +33,9 @@ use RuntimeException; */ class PockBuilderTest extends PockTestCase { - protected function tearDown(): void + protected function setUp(): void { - uopz_unset_return('extension_loaded'); + XmlBodyMatcher::$forceTextComparison = false; } public function testNoHit(): void @@ -463,17 +461,7 @@ EOF; $document = new DOMDocument(); $document->loadXML($simpleObject); - uopz_set_return( - 'extension_loaded', - function (string $extension) { - if ('xsl' === $extension) { - return false; - } - - return true; - }, - true - ); + XmlBodyMatcher::$forceTextComparison = true; $builder = new PockBuilder(); $builder->matchMethod(RequestMethod::GET)