fix form-data matcher logic

This commit is contained in:
Pavel 2022-04-14 13:59:59 +03:00
parent 5a92b28b5f
commit f455ba52d5
4 changed files with 17 additions and 4 deletions

View File

@ -73,5 +73,10 @@
"@lint", "@lint",
"@phpunit" "@phpunit"
] ]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
} }
} }

View File

@ -10,7 +10,7 @@
namespace Pock\Matchers; namespace Pock\Matchers;
use Pock\Comparator\ComparatorLocator; use Pock\Comparator\ComparatorLocator;
use Pock\Comparator\RecursiveLtrArrayComparator; use Pock\Comparator\RecursiveArrayComparator;
use Pock\Traits\SeekableStreamDataExtractor; use Pock\Traits\SeekableStreamDataExtractor;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
@ -35,6 +35,6 @@ class FormDataMatcher extends QueryMatcher
return false; return false;
} }
return ComparatorLocator::get(RecursiveLtrArrayComparator::class)->compare($this->query, $query); return ComparatorLocator::get(RecursiveArrayComparator::class)->compare($this->query, $query);
} }
} }

View File

@ -44,11 +44,19 @@ class FormDataMatcherTest extends PockTestCase
self::assertFalse($matcher->matches($request)); self::assertFalse($matcher->matches($request));
} }
public function testMatches(): void public function testNoMatchesExtraValues(): void
{ {
$matcher = new FormDataMatcher(['field2' => 'value2']); $matcher = new FormDataMatcher(['field2' => 'value2']);
$request = self::getRequestWithBody('field1=value1&field2=value2'); $request = self::getRequestWithBody('field1=value1&field2=value2');
self::assertFalse($matcher->matches($request));
}
public function testMatches(): void
{
$matcher = new FormDataMatcher(['field1' => 'value1', 'field2' => 'value2']);
$request = self::getRequestWithBody('field1=value1&field2=value2');
self::assertTrue($matcher->matches($request)); self::assertTrue($matcher->matches($request));
} }
} }

View File

@ -681,7 +681,7 @@ EOF;
$builder = new PockBuilder(); $builder = new PockBuilder();
$builder->matchMethod(RequestMethod::GET) $builder->matchMethod(RequestMethod::GET)
->matchUri(self::TEST_URI) ->matchUri(self::TEST_URI)
->matchFormData(['field2' => 'value2']) ->matchFormData(['field1' => 'value1', 'field2' => 'value2'])
->reply(200); ->reply(200);
$response = $builder->getClient()->sendRequest(self::getRequestWithBody('field1=value1&field2=value2')); $response = $builder->getClient()->sendRequest(self::getRequestWithBody('field1=value1&field2=value2'));