ugly hack for tests

This commit is contained in:
Pavel 2021-05-21 20:31:07 +03:00
parent b99fb4f255
commit e7a17599ad
3 changed files with 24 additions and 20 deletions

View File

@ -23,7 +23,6 @@ jobs:
with: with:
php-version: ${{ matrix.php-version }} php-version: ${{ matrix.php-version }}
coverage: pcov coverage: pcov
extensions: uopz
- name: Composer cache - name: Composer cache
uses: actions/cache@v2 uses: actions/cache@v2
with: with:

View File

@ -44,6 +44,9 @@ class XmlBodyMatcher extends BodyMatcher
</xsl:stylesheet> </xsl:stylesheet>
EOT; EOT;
/** @var bool */
public static $forceTextComparison = false;
/** @var XSLTProcessor|null */ /** @var XSLTProcessor|null */
private static $sorter; private static $sorter;
@ -59,14 +62,14 @@ EOT;
*/ */
public function __construct($referenceXml) public function __construct($referenceXml)
{ {
if (!extension_loaded('xsl') || !extension_loaded('dom')) { if (!static::hasExtension('xsl') || !static::hasExtension('dom')) {
$this->useFallback = true; $this->useFallback = true;
} }
if (!extension_loaded('xsl')) { if (!static::hasExtension('xsl')) {
$this->useFallback = true; $this->useFallback = true;
if (extension_loaded('dom') && $referenceXml instanceof DOMDocument) { if (static::hasExtension('dom') && $referenceXml instanceof DOMDocument) {
$referenceXml = static::getDOMString($referenceXml); $referenceXml = static::getDOMString($referenceXml);
} }
@ -190,4 +193,18 @@ EOT;
return $result; 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);
}
} }

View File

@ -10,12 +10,10 @@
namespace Pock\Tests; namespace Pock\Tests;
use DOMDocument; use DOMDocument;
use phpmock\Mock;
use phpmock\MockBuilder;
use phpmock\MockRegistry;
use Pock\Enum\RequestMethod; use Pock\Enum\RequestMethod;
use Pock\Enum\RequestScheme; use Pock\Enum\RequestScheme;
use Pock\Exception\UnsupportedRequestException; use Pock\Exception\UnsupportedRequestException;
use Pock\Matchers\XmlBodyMatcher;
use Pock\PockBuilder; use Pock\PockBuilder;
use Pock\PockResponseBuilder; use Pock\PockResponseBuilder;
use Pock\TestUtils\PockTestCase; use Pock\TestUtils\PockTestCase;
@ -35,9 +33,9 @@ use RuntimeException;
*/ */
class PockBuilderTest extends PockTestCase class PockBuilderTest extends PockTestCase
{ {
protected function tearDown(): void protected function setUp(): void
{ {
uopz_unset_return('extension_loaded'); XmlBodyMatcher::$forceTextComparison = false;
} }
public function testNoHit(): void public function testNoHit(): void
@ -463,17 +461,7 @@ EOF;
$document = new DOMDocument(); $document = new DOMDocument();
$document->loadXML($simpleObject); $document->loadXML($simpleObject);
uopz_set_return( XmlBodyMatcher::$forceTextComparison = true;
'extension_loaded',
function (string $extension) {
if ('xsl' === $extension) {
return false;
}
return true;
},
true
);
$builder = new PockBuilder(); $builder = new PockBuilder();
$builder->matchMethod(RequestMethod::GET) $builder->matchMethod(RequestMethod::GET)