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:
|
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:
|
||||||
|
@ -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 it’s feasible).
|
- [ ] Document everything (with examples if it’s feasible).
|
||||||
|
@ -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",
|
||||||
|
@ -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
|
||||||
|
@ -23,7 +23,7 @@ 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
|
||||||
@ -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
|
||||||
) {
|
) {
|
||||||
|
@ -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,21 +460,20 @@ EOF;
|
|||||||
$this->expectException(UnsupportedRequestException::class);
|
$this->expectException(UnsupportedRequestException::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
$mock = (new MockBuilder())->setNamespace('Pock\Matchers')
|
$document = new DOMDocument();
|
||||||
->setName('extension_loaded')
|
$document->loadXML($simpleObject);
|
||||||
->setFunction(
|
|
||||||
static function (string $extension) {
|
uopz_set_return(
|
||||||
|
'extension_loaded',
|
||||||
|
function (string $extension) {
|
||||||
if ('xsl' === $extension) {
|
if ('xsl' === $extension) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return \extension_loaded($extension);
|
return true;
|
||||||
}
|
},
|
||||||
)->build();
|
true
|
||||||
$mock->enable();
|
);
|
||||||
|
|
||||||
$document = new DOMDocument();
|
|
||||||
$document->loadXML($simpleObject);
|
|
||||||
|
|
||||||
$builder = new PockBuilder();
|
$builder = new PockBuilder();
|
||||||
$builder->matchMethod(RequestMethod::GET)
|
$builder->matchMethod(RequestMethod::GET)
|
||||||
@ -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]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user