mirror of
https://github.com/Neur0toxine/pock.git
synced 2025-02-07 08:19:22 +03:00
fix for tests & json decoder trait
This commit is contained in:
parent
e352c310d7
commit
b99fb4f255
1
.github/workflows/tests.yml
vendored
1
.github/workflows/tests.yml
vendored
@ -23,6 +23,7 @@ jobs:
|
||||
with:
|
||||
php-version: ${{ matrix.php-version }}
|
||||
coverage: pcov
|
||||
extensions: uopz
|
||||
- name: Composer cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
|
@ -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 it’s feasible).
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
@ -23,7 +23,7 @@ trait JsonDecoderTrait
|
||||
* json_decode which throws exception on error.
|
||||
*
|
||||
* @param string $json
|
||||
* @param bool|null $associative
|
||||
* @param bool $associative
|
||||
* @param int $depth
|
||||
*
|
||||
* @param int $flags
|
||||
@ -35,7 +35,7 @@ trait JsonDecoderTrait
|
||||
*/
|
||||
public static function jsonDecode(
|
||||
string $json,
|
||||
?bool $associative = false,
|
||||
bool $associative = false,
|
||||
int $depth = 512,
|
||||
int $flags = 0
|
||||
) {
|
||||
|
@ -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,21 +460,20 @@ EOF;
|
||||
$this->expectException(UnsupportedRequestException::class);
|
||||
}
|
||||
|
||||
$mock = (new MockBuilder())->setNamespace('Pock\Matchers')
|
||||
->setName('extension_loaded')
|
||||
->setFunction(
|
||||
static function (string $extension) {
|
||||
$document = new DOMDocument();
|
||||
$document->loadXML($simpleObject);
|
||||
|
||||
uopz_set_return(
|
||||
'extension_loaded',
|
||||
function (string $extension) {
|
||||
if ('xsl' === $extension) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return \extension_loaded($extension);
|
||||
}
|
||||
)->build();
|
||||
$mock->enable();
|
||||
|
||||
$document = new DOMDocument();
|
||||
$document->loadXML($simpleObject);
|
||||
return true;
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
$builder = new PockBuilder();
|
||||
$builder->matchMethod(RequestMethod::GET)
|
||||
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user