fix for tests & json decoder trait

This commit is contained in:
Pavel 2021-05-21 19:54:17 +03:00
parent e352c310d7
commit b99fb4f255
6 changed files with 29 additions and 25 deletions

View File

@ -23,6 +23,7 @@ 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

@ -123,5 +123,5 @@ In order to use unsupported serializer you should create a decorator which imple
- [x] `replyWithCallback` - reply using specified callback. - [x] `replyWithCallback` - reply using specified callback.
- [x] `replyWithFactory` - reply using specified response factory (provide corresponding interface). - [x] `replyWithFactory` - reply using specified response factory (provide corresponding interface).
- [ ] `symfony/http-client` support. - [ ] `symfony/http-client` support.
- [ ] Compare XML bodies using `DOMDocument`, fallback to text comparison in case of problems. - [x] Compare XML bodies using `DOMDocument`, fallback to text comparison in case of problems.
- [ ] Document everything (with examples if its feasible). - [ ] Document everything (with examples if its feasible).

View File

@ -47,8 +47,7 @@
"jms/serializer": "^2 | ^3.12", "jms/serializer": "^2 | ^3.12",
"symfony/phpunit-bridge": "^5.2", "symfony/phpunit-bridge": "^5.2",
"symfony/serializer": "^5.2", "symfony/serializer": "^5.2",
"symfony/property-access": "^5.2", "symfony/property-access": "^5.2"
"php-mock/php-mock": "^2.3"
}, },
"provide": { "provide": {
"psr/http-client-implementation": "1.0", "psr/http-client-implementation": "1.0",

View File

@ -11,11 +11,10 @@ namespace Pock\Matchers;
use DOMDocument; use DOMDocument;
use Pock\Exception\XmlException; use Pock\Exception\XmlException;
use Throwable;
use XSLTProcessor;
use Pock\Traits\SeekableStreamDataExtractor; use Pock\Traits\SeekableStreamDataExtractor;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use RuntimeException; use RuntimeException;
use XSLTProcessor;
/** /**
* Class XmlBodyMatcher * Class XmlBodyMatcher

View File

@ -22,11 +22,11 @@ trait JsonDecoderTrait
/** /**
* json_decode which throws exception on error. * json_decode which throws exception on error.
* *
* @param string $json * @param string $json
* @param bool|null $associative * @param bool $associative
* @param int $depth * @param int $depth
* *
* @param int $flags * @param int $flags
* *
* @return mixed * @return mixed
* @throws \Pock\Exception\JsonException * @throws \Pock\Exception\JsonException
@ -35,7 +35,7 @@ trait JsonDecoderTrait
*/ */
public static function jsonDecode( public static function jsonDecode(
string $json, string $json,
?bool $associative = false, bool $associative = false,
int $depth = 512, int $depth = 512,
int $flags = 0 int $flags = 0
) { ) {

View File

@ -10,7 +10,9 @@
namespace Pock\Tests; namespace Pock\Tests;
use DOMDocument; use DOMDocument;
use phpmock\Mock;
use phpmock\MockBuilder; 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;
@ -33,6 +35,11 @@ use RuntimeException;
*/ */
class PockBuilderTest extends PockTestCase class PockBuilderTest extends PockTestCase
{ {
protected function tearDown(): void
{
uopz_unset_return('extension_loaded');
}
public function testNoHit(): void public function testNoHit(): void
{ {
$this->expectException(UnsupportedRequestException::class); $this->expectException(UnsupportedRequestException::class);
@ -453,22 +460,21 @@ EOF;
$this->expectException(UnsupportedRequestException::class); $this->expectException(UnsupportedRequestException::class);
} }
$mock = (new MockBuilder())->setNamespace('Pock\Matchers')
->setName('extension_loaded')
->setFunction(
static function (string $extension) {
if ('xsl' === $extension) {
return false;
}
return \extension_loaded($extension);
}
)->build();
$mock->enable();
$document = new DOMDocument(); $document = new DOMDocument();
$document->loadXML($simpleObject); $document->loadXML($simpleObject);
uopz_set_return(
'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)
->matchScheme(RequestScheme::HTTPS) ->matchScheme(RequestScheme::HTTPS)
@ -479,8 +485,6 @@ EOF;
->withHeader('Content-Type', 'text/xml') ->withHeader('Content-Type', 'text/xml')
->withXml(['error' => 'Forbidden']); ->withXml(['error' => 'Forbidden']);
$mock->disable();
$response = $builder->getClient()->sendRequest( $response = $builder->getClient()->sendRequest(
self::getPsr17Factory() self::getPsr17Factory()
->createRequest(RequestMethod::GET, self::TEST_URI) ->createRequest(RequestMethod::GET, self::TEST_URI)
@ -868,6 +872,7 @@ EOF;
<field><![CDATA[test]]></field> <field><![CDATA[test]]></field>
</result> </result>
EOF; EOF;
return [ return [
[$simpleObject, true], [$simpleObject, true],
[$simpleObject . "\n", false] [$simpleObject . "\n", false]