Skip to content

Commit 1656587

Browse files
Fix codeclimate warnings (#18)
1 parent db6b39b commit 1656587

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/Constraint/UrlEncodedMatches.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function __construct($nameMatcher, $valueMatcher = null)
1818

1919
if ($valueMatcher === null) {
2020
$valueMatcher = new IsAnything();
21-
} else if (!($valueMatcher instanceof Constraint)) {
21+
} elseif (!($valueMatcher instanceof Constraint)) {
2222
$valueMatcher = new IsEqual($valueMatcher);
2323
}
2424

@@ -31,15 +31,12 @@ protected function matches($other): bool
3131
parse_str($other, $parsedQuery);
3232

3333
foreach ($parsedQuery as $key => $value) {
34-
if (!$this->nameMatcher->evaluate($key, "", true)) {
35-
continue;
36-
}
34+
$nameMatches = $this->nameMatcher->evaluate($key, "", true);
35+
$valueMatches = $this->valueMatcher->evaluate($value, "", true);
3736

38-
if (!$this->valueMatcher->evaluate($value, "", true)) {
39-
continue;
37+
if ($nameMatches && $valueMatches) {
38+
return true;
4039
}
41-
42-
return true;
4340
}
4441

4542
return false;
@@ -50,5 +47,4 @@ public function toString(): string
5047
return 'contains a name matching ' . $this->nameMatcher->toString() . ' and value matching ' . $this->valueMatcher->toString();
5148
}
5249

53-
5450
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Helmich\Psr7Assert\Tests\Unit\Constraint;
6+
7+
use GuzzleHttp\Psr7\Request;
8+
use Helmich\Psr7Assert\Constraint\HasUriConstraint;
9+
use Helmich\Psr7Assert\Constraint\UrlEncodedMatches;
10+
use PHPUnit\Framework\AssertionFailedError;
11+
use PHPUnit\Framework\TestCase;
12+
13+
class UrlEncodedMatchesTest extends TestCase
14+
{
15+
public function testMatchesValueWithCorrectKeyAndValue()
16+
{
17+
$constraint = new UrlEncodedMatches("foo", "bar");
18+
self::assertTrue($constraint->evaluate("foo=bar&baz=foo", "", true));
19+
}
20+
21+
public function testDoesNotMatchValueWithIncorrectValue()
22+
{
23+
$constraint = new UrlEncodedMatches("foo", "wrong");
24+
self::assertFalse($constraint->evaluate("foo=bar&baz=foo", "", true));
25+
}
26+
27+
public function testDoesNotMatchValueWithIncorrectKey()
28+
{
29+
$constraint = new UrlEncodedMatches("wrong", "bar");
30+
self::assertFalse($constraint->evaluate("foo=bar&baz=foo", "", true));
31+
}
32+
}

0 commit comments

Comments
 (0)