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:
php-version: ${{ matrix.php-version }}
coverage: pcov
extensions: uopz
- name: Composer cache
uses: actions/cache@v2
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] `replyWithFactory` - reply using specified response factory (provide corresponding interface).
- [ ] `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).

View File

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

View File

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

View File

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

View File

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